/** * {@inheritdoc} */ public function buildQuery(ShopContextInterface $context, $term) { $boolQuery = new BoolQuery(); $boolQuery->addParameter('minimum_should_match', 1); $boolQuery->add($this->getBestFieldQuery($term), BoolQuery::SHOULD); $boolQuery->add($this->getPhrasePrefixQuery($term), BoolQuery::SHOULD); return $boolQuery; }
/** * @param Struct\ListProduct $product * @return BoolQuery */ protected function getSimilarQuery(Struct\ListProduct $product) { $categories = $this->getProductCategories($product); $queries = [new FuzzyLikeThisFieldQuery('name', $product->getName(), ['boost' => 5]), new TermsQuery('categoryIds', $categories)]; $query = new BoolQuery(); $query->addParameter('minimum_should_match', 1); foreach ($queries as $bool) { $query->add($bool, BoolQuery::SHOULD); } return $query; }