/** * @covers sherlock\Sherlock\components\queries\FilteredQuery::query * @covers sherlock\Sherlock\components\queries\FilteredQuery::filter * @covers sherlock\Sherlock\requests\SearchRequest::query * @covers sherlock\Sherlock\requests\SearchRequest::toJSON */ public function testFilteredQuery() { $req = $this->object->search(); $req->index("testqueries")->type("test"); $query = Sherlock::queryBuilder()->FilteredQuery()->query(Sherlock::queryBuilder()->Term()->field("auxillary")->term("auxillary"))->filter(Sherlock::filterBuilder()->Term()->field("auxillary")->term("auxillary")); $req->query($query); $data = $req->toJSON(); $expectedData = '{"query":{"filtered":{"query":{"term":{"auxillary":{"value":"auxillary"}}},"filter":{"term":{"auxillary":"auxillary","_cache":true}}}}}'; $this->assertEquals($expectedData, $data); $resp = $req->execute(); }
/** * @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(); }
/** * @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(); }