diff options
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Query/SimpleQueryStringTest.php')
-rw-r--r-- | vendor/ruflin/elastica/test/lib/Elastica/Test/Query/SimpleQueryStringTest.php | 108 |
1 files changed, 69 insertions, 39 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/SimpleQueryStringTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/SimpleQueryStringTest.php index eff9b8a1..80316547 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/SimpleQueryStringTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/SimpleQueryStringTest.php @@ -1,73 +1,103 @@ <?php - namespace Elastica\Test\Query; - use Elastica\Document; -use Elastica\Index; use Elastica\Query\SimpleQueryString; use Elastica\Test\Base; class SimpleQueryStringTest extends Base { /** - * @var Index + * @group unit */ - protected $_index; + public function testToArray() + { + $string = 'this is a test'; + $fields = array('field1', 'field2'); + $query = new SimpleQueryString($string, $fields); + $query->setDefaultOperator(SimpleQueryString::OPERATOR_OR); + $query->setAnalyzer('whitespace'); + + $expected = array( + 'simple_query_string' => array( + 'query' => $string, + 'fields' => $fields, + 'analyzer' => 'whitespace', + 'default_operator' => SimpleQueryString::OPERATOR_OR, + ), + ); - protected function setUp() + $this->assertEquals($expected, $query->toArray()); + } + + /** + * @group functional + */ + public function testQuery() { - parent::setUp(); - $this->_index = $this->_createIndex("simple_query_string_test"); + $index = $this->_createIndex(); $docs = array( new Document(1, array('make' => 'Gibson', 'model' => 'Les Paul')), new Document(2, array('make' => 'Gibson', 'model' => 'SG Standard')), new Document(3, array('make' => 'Gibson', 'model' => 'SG Supreme')), new Document(4, array('make' => 'Gibson', 'model' => 'SG Faded')), - new Document(5, array('make' => 'Fender', 'model' => 'Stratocaster')) + new Document(5, array('make' => 'Fender', 'model' => 'Stratocaster')), ); - $this->_index->getType("guitars")->addDocuments($docs); - $this->_index->refresh(); - } + $index->getType('guitars')->addDocuments($docs); + $index->refresh(); - protected function tearDown() - { - parent::tearDown(); - $this->_index->delete(); + $query = new SimpleQueryString('gibson +sg +-faded', array('make', 'model')); + $results = $index->search($query); + + $this->assertEquals(2, $results->getTotalHits()); + + $query->setFields(array('model')); + $results = $index->search($query); + + // We should not get any hits, since the "make" field was not included in the query. + $this->assertEquals(0, $results->getTotalHits()); } - public function testToArray() + /** + * @group unit + */ + public function testSetMinimumShouldMatch() { - $string = "this is a test"; - $fields = array('field1', 'field2'); - $query = new SimpleQueryString($string, $fields); - $query->setDefaultOperator(SimpleQueryString::OPERATOR_OR); - $query->setAnalyzer("whitespace"); - $expected = array( - "simple_query_string" => array( - "query" => $string, - "fields" => $fields, - "analyzer" => "whitespace", - "default_operator" => SimpleQueryString::OPERATOR_OR - ) + 'simple_query_string' => array( + 'query' => 'DONT PANIC', + 'minimum_should_match' => '75%', + ), ); + $query = new SimpleQueryString($expected['simple_query_string']['query']); + $query->setMinimumShouldMatch($expected['simple_query_string']['minimum_should_match']); + $this->assertEquals($expected, $query->toArray()); + $this->assertInstanceOf('Elastica\Query\SimpleQueryString', $query->setMinimumShouldMatch('75%')); } - public function testQuery() + /** + * @group functional + */ + public function testSetMinimumShouldMatchWorks() { - $query = new SimpleQueryString("gibson +sg +-faded", array("make", "model")); - $results = $this->_index->search($query); + $index = $this->_createIndex(); + $type = $index->getType('foobars'); + $type->addDocuments(array( + new Document(1, array('body' => 'foo')), + new Document(2, array('body' => 'bar')), + new Document(3, array('body' => 'foo bar')), + new Document(4, array('body' => 'foo baz bar')), + )); + $index->refresh(); - $this->assertEquals(2, $results->getTotalHits()); - - $query->setFields(array("model")); - $results = $this->_index->search($query); + $query = new SimpleQueryString('foo bar'); + $query->setMinimumShouldMatch(2); + $results = $type->search($query); - // We should not get any hits, since the "make" field was not included in the query. - $this->assertEquals(0, $results->getTotalHits()); + $this->assertCount(2, $results); + $this->assertEquals(3, $results[0]->getId()); + $this->assertEquals(4, $results[1]->getId()); } } -
\ No newline at end of file |