summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/SimpleQueryStringTest.php
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-05-01 15:30:47 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-05-01 15:30:47 -0400
commit7e85254903c7c0cb49e381f16b18441ea7b058cc (patch)
treeb22328fcf4c8408fc25a7acb73d1cb1089cd82ac /vendor/ruflin/elastica/test/lib/Elastica/Test/Query/SimpleQueryStringTest.php
parent1de335ad3f395ca6861085393ba366a9e3fb4a0d (diff)
parent1a365e77dfb8825136626202b1df462731b42060 (diff)
Merge commit '1a365e'
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.php73
1 files changed, 73 insertions, 0 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
new file mode 100644
index 00000000..eff9b8a1
--- /dev/null
+++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Query/SimpleQueryStringTest.php
@@ -0,0 +1,73 @@
+<?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
+ */
+ protected $_index;
+
+ protected function setUp()
+ {
+ parent::setUp();
+ $this->_index = $this->_createIndex("simple_query_string_test");
+ $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'))
+ );
+ $this->_index->getType("guitars")->addDocuments($docs);
+ $this->_index->refresh();
+ }
+
+ protected function tearDown()
+ {
+ parent::tearDown();
+ $this->_index->delete();
+ }
+
+ 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
+ )
+ );
+
+ $this->assertEquals($expected, $query->toArray());
+ }
+
+ public function testQuery()
+ {
+ $query = new SimpleQueryString("gibson +sg +-faded", array("make", "model"));
+ $results = $this->_index->search($query);
+
+ $this->assertEquals(2, $results->getTotalHits());
+
+ $query->setFields(array("model"));
+ $results = $this->_index->search($query);
+
+ // We should not get any hits, since the "make" field was not included in the query.
+ $this->assertEquals(0, $results->getTotalHits());
+ }
+}
+ \ No newline at end of file