Skip to content

Commit

Permalink
Search update
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanJelicSF committed Jul 7, 2023
1 parent 42119d5 commit 7638233
Showing 1 changed file with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
use Elastica\Query\Nested;
use Elastica\Query\Range;
use Elastica\Query\Term;
use Elastica\QueryBuilder\DSL\Suggest;
use Elastica\Suggest;
use Elastica\Suggest\Phrase;
use FOS\ElasticaBundle\Paginator\PaginatorAdapterInterface;
use FOS\ElasticaBundle\Repository;
use SWP\Bundle\ElasticSearchBundle\Criteria\Criteria;
Expand Down Expand Up @@ -212,7 +213,7 @@ public function findByCriteria(Criteria $criteria, array $extraFields = [], bool

$functionScore->setQuery($boolFilter);

$query = Query::create($boolFilter)
$query = Query::create($functionScore)
->addSort([
//'_score' => 'desc',
'publishedAt' => $criteria->getOrder()->getDirection(),
Expand All @@ -226,31 +227,22 @@ public function findByCriteria(Criteria $criteria, array $extraFields = [], bool

public function getSuggestedTerm(string $term): string
{
$suggestQuery = new Suggest();
$suggestQuery->phrase('our_suggestion', '_all');
$suggest = new Suggest();
$phraseSuggest = new Phrase('our_suggestion', 'title');
$phraseSuggest->setText($term);
$suggest->addSuggestion($phraseSuggest);

$phraseMultiMatchQuery = new MultiMatch();
$phraseMultiMatchQuery->setQuery($term);
$phraseMultiMatchQuery->setFields('_all');
$phraseMultiMatchQuery->setType(MultiMatch::TYPE_PHRASE);
$phraseMultiMatchQuery->setParam('boost', 50);

$query = new \Elastica\Query($phraseMultiMatchQuery);
$suggest = new \Elastica\Suggest();
$suggest->setParam(
'phrase',
[
'text' => $term,
'phrase' => ['field' => '_all'],
]
);

$query->setSuggest($suggest);

$adapter = $this->createPaginatorAdapter($query);
$suggest = $adapter->getSuggests();

return $suggest['phrase'][0]['options'][0]['text'] ?? '';
return $suggest['our_suggestion'][0]['options'][0]['text'] ?? '';
}
}

0 comments on commit 7638233

Please sign in to comment.