/** * {@inheritdoc} */ public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null) { if ($state && $state->isActive()) { if (strpos($this->getField(), ',') !== false) { $subQuery = new BoolQuery(); foreach (explode(',', $this->getField()) as $field) { $subQuery->add(new FuzzyQuery($field, $state->getValue(), $this->getParameters()), 'should'); } $search->addQuery($subQuery, 'must'); } else { $search->addQuery(new FuzzyQuery($this->getField(), $state->getValue(), $this->getParameters()), 'must'); } } }
/** * Data provider for testIteration. * * @return array */ public function getIterationData() { $out = []; // Case #0: no search type set, with a sort, results should be sorted. $search = new Search(); $search->setSize(2); $search->setScroll('1m'); $search->addSort(new Sort('header')); $search->addQuery(new MatchAllQuery()); $out[] = ['search' => $search, true]; // Case #1: search type set to scan, with a sort, results should not be sorted. $search = new Search(); $search->setSize(2); $search->setScroll('1m'); $search->setSearchType('scan'); $search->addSort(new Sort('header')); $search->addQuery(new MatchAllQuery()); $out[] = ['search' => $search, false]; // Case #3: minimum size, should give the same results. $search = new Search(); $search->setSize(1); $search->setScroll('1m'); $search->addSort(new Sort('header')); $search->addQuery(new MatchAllQuery()); $out[] = ['search' => $search, true]; return $out; }
/** * {@inheritdoc} */ public function warmUp(Search $search) { $search->addQuery(new MatchAllQuery()); }
/** * Check if `token_count` field works as expected. */ public function testPersistTokenCountField() { $manager = $this->getManager(); $colorDocument = new ColorDocument(); $colorDocument->piecesCount = 't e s t'; $manager->persist($colorDocument); $manager->commit(); $repository = $manager->getRepository('AcmeTestBundle:ColorDocument'); // Analyzer is whitespace, so there are four tokens. $search = new Search(); $search->addQuery(new TermQuery('pieces_count.count', '4')); $this->assertEquals(1, $repository->execute($search)->getTotalCount()); // Test with invalid count. $search = new Search(); $search->addQuery(new TermQuery('pieces_count.count', '6')); $this->assertEquals(0, $repository->execute($search)->getTotalCount()); }