Smile\ElasticsuiteCatalogRule\Model\Rule\Condition\Product\QueryBuilder::getSearchQuery PHP Method

getSearchQuery() public method

Build the query for a condition.
public getSearchQuery ( Product $productCondition ) : Smile\ElasticsuiteCore\Search\Request\QueryInterface
$productCondition Smile\ElasticsuiteCatalogRule\Model\Rule\Condition\Product Product condition.
return Smile\ElasticsuiteCore\Search\Request\QueryInterface
    public function getSearchQuery(ProductCondition $productCondition)
    {
        $query = null;
        $query = $this->getSpecialAttributesSearchQuery($productCondition);
        $this->prepareFieldValue($productCondition);
        if ($query === null && !empty($productCondition->getValue())) {
            $queryType = QueryInterface::TYPE_TERMS;
            $queryParams = $this->getTermsQueryParams($productCondition);
            if ($productCondition->getInputType() === 'string') {
                $queryType = QueryInterface::TYPE_MATCH;
                $queryParams = $this->getMatchQueryParams($productCondition);
            } elseif (in_array($productCondition->getOperator(), ['>=', '>', '<=', '<'])) {
                $queryType = QueryInterface::TYPE_RANGE;
                $queryParams = $this->getRangeQueryParams($productCondition);
            }
            $query = $this->prepareQuery($queryType, $queryParams);
            if (substr($productCondition->getOperator(), 0, 1) === '!') {
                $query = $this->applyNegation($query);
            }
            $field = $this->getSearchField($productCondition);
            if ($field->isNested()) {
                $nestedPath = $field->getNestedPath();
                $nestedQueryParams = ['query' => $query, 'path' => $nestedPath];
                if (isset($this->nestedFilters[$nestedPath])) {
                    $nestedFilterClauses = [];
                    $nestedFilterClauses['must'][] = $this->nestedFilters[$nestedPath]->getFilter();
                    $nestedFilterClauses['must'][] = $nestedQueryParams['query'];
                    $nestedFilter = $this->queryFactory->create(QueryInterface::TYPE_BOOL, $nestedFilterClauses);
                    $nestedQueryParams['query'] = $nestedFilter;
                }
                $query = $this->queryFactory->create(QueryInterface::TYPE_NESTED, $nestedQueryParams);
            }
        }
        return $query;
    }

Usage Example

示例#1
0
 /**
  * Transform a category in query rule.
  *
  * @param CategoryInterface $category Category.
  *
  * @return QueryInterface
  */
 private function getStandardCategoryQuery(CategoryInterface $category)
 {
     $conditionsParams = ['data' => ['attribute' => 'category_ids', 'operator' => '()', 'value' => $category->getId()]];
     $categoryCondition = $this->productConditionsFactory->create($conditionsParams);
     return $this->queryBuilder->getSearchQuery($categoryCondition);
 }
All Usage Examples Of Smile\ElasticsuiteCatalogRule\Model\Rule\Condition\Product\QueryBuilder::getSearchQuery