Example #1
0
 /**
  * Tears down the fixture, for example, closes a network connection.
  * This method is called after a test is executed.
  */
 protected function tearDown()
 {
     try {
         $this->object->index('testindexing')->delete();
     } catch (\Exception $e) {
     }
 }
Example #2
0
 public function testIllegalJson()
 {
     $sherlock = $this->object;
     $req = $this->object->search();
     $req->index("testqueries")->type("test");
     $query = Sherlock\Sherlock::queryBuilder()->Raw('Illegal JSON');
     $req->query($query);
     $this->assertThrowsException('\\Sherlock\\common\\exceptions\\SearchPhaseExecutionException', function () use($req) {
         $req->execute();
     });
 }
Example #3
0
 public function testRawQueryBuilding()
 {
     $req = $this->object->search();
     $req->index("test3")->type("benchmark");
     $expectedData = array("query" => array("term" => array("field1" => array("value" => "town"))));
     $req->query(Sherlock::queryBuilder()->Raw($expectedData['query']));
     $data = $req->toJSON();
     $expectedData = json_encode($expectedData);
     $this->assertEquals($expectedData, $data);
 }
 /**
  * @covers sherlock\Sherlock\components\queries\CustomFiltersScore::filter
  * @covers sherlock\Sherlock\requests\SearchRequest::query
  * @covers sherlock\Sherlock\requests\SearchRequest::toJSON
  */
 public function testMultipleFilter()
 {
     $req = $this->object->search();
     $req->index("testqueries")->type("test");
     $filter = Sherlock::filterBuilder()->Term()->field("auxillary")->term("auxillary");
     $query = Sherlock::queryBuilder()->CustomFiltersScore()->query(Sherlock::queryBuilder()->Term()->field("auxillary")->term("auxillary"))->filter($filter, 2)->filter($filter, 3)->filter($filter, 4)->score_mode("first")->max_boost(0.5);
     $req->query($query);
     $data = $req->toJSON();
     $expectedData = '{"query":{"custom_filters_score":{"query":{"term":{"auxillary":{"value":"auxillary"}}},"filters":[{"filter":{"term":{"auxillary":"auxillary","_cache":true}},"boost":2},{"filter":{"term":{"auxillary":"auxillary","_cache":true}},"boost":3},{"filter":{"term":{"auxillary":"auxillary","_cache":true}},"boost":4}],"score_mode":"first","max_boost":0.5}}}';
     $this->assertEquals($expectedData, $data);
     $resp = $req->execute();
 }
Example #5
0
 /**
  * @covers sherlock\Sherlock\components\filters\Type::value
  * @covers sherlock\Sherlock\requests\SearchRequest::query
  * @covers sherlock\Sherlock\requests\SearchRequest::toJSON
  */
 public function testType()
 {
     $req = $this->object->search();
     $req->index("testfilters")->type("test");
     $filter = Sherlock::filterBuilder()->Type()->value("testString");
     $query = Sherlock::queryBuilder()->MatchAll();
     $req->query($query);
     $req->filter($filter);
     $data = $req->toJSON();
     $expectedData = '{"query":{"match_all":[]},"filter":{"type":{"value":"testString"}}}';
     $this->assertEquals($expectedData, $data);
     $resp = $req->execute();
 }
Example #6
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->object = new Sherlock\Sherlock();
     $this->object->addNode('localhost', '9200');
 }