TermsQuery example



            $expression = $condition['expression'] ?? '=';

            switch (strtolower($expression)) {
                case 'in':
                    $value = $condition['value'];
                    if (!\is_array($value)) {
                        $value = [$value];
                    }
                    $query->add(
                        new TermsQuery($condition['property']$value),
                        BoolQuery::MUST
                    );
                    break;

                case '=':
                    $query->add(
                        new TermQuery($condition['property']$condition['value']),
                        BoolQuery::MUST
                    );
                    break;

                
private function getSorting(ManualSorting $criteriaPart, CategoryCondition $categoryCondition): FieldSort
    {
        $categoryId = $categoryCondition->getCategoryIds()[0];

        // Elasticsearch DSL does not support the new format         // @see: https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-sort.html#_nested_sorting_examples         return new FieldSort('manualSorting.position', strtolower($criteriaPart->getDirection())[
            'unmapped_type' => 'integer',
            'nested' => [
                'path' => 'manualSorting',
                'filter' => (new TermsQuery('manualSorting.category_id', [$categoryId]))->toArray(),
            ],
        ]);
    }
}
public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart));
    }

    private function getQuery(ProductIdCondition $criteriaPart): TermsQuery
    {
        return new TermsQuery('id', $criteriaPart->getProductIds());
    }
}
public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart));
    }

    private function getQuery(OrdernumberCondition $criteriaPart): TermsQuery
    {
        return new TermsQuery('number.raw', $criteriaPart->getOrdernumbers());
    }
}


    private function addQuery(SimilarProductCondition $criteriaPart, Search $search): void
    {
        $productId = $criteriaPart->getProductId();
        $productName = $criteriaPart->getProductName();
        $categories = $this->getProductCategories($productId);

        $query = new BoolQuery();

        $nameQuery = new MultiMatchQuery(['name', 'keywords']$productName['boost' => 5]);
        $categoriesQuery = new TermsQuery('categoryIds', $categories['boost' => 0.2]);

        $query->add($nameQuery, BoolQuery::SHOULD);
        $query->add($categoriesQuery, BoolQuery::MUST);

        $not = new BoolQuery();
        $not->add(new TermQuery('id', $productId), BoolQuery::MUST_NOT);

        $search->addQuery($not, BoolQuery::FILTER);
        $search->addQuery($query);
    }

    
return new MatchQuery($field$value);

            case ProductAttributeCondition::OPERATOR_NOT_IN:
                if (!\is_array($value)) {
                    throw new RuntimeException('Invalid value for TermsQuery provided');
                }

                if ($type === 'string') {
                    $field .= '.raw';
                }
                $filter = new BoolQuery();
                $filter->add(new TermsQuery($field$value), BoolQuery::MUST_NOT);

                return $filter;

            case ProductAttributeCondition::OPERATOR_IN:
                if (!\is_array($value)) {
                    throw new RuntimeException('Invalid value for TermsQuery provided');
                }

                if ($type === 'string') {
                    $field .= '.raw';
                }

                
Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart));
    }

    private function getQuery(CustomerGroupCondition $criteriaPart): BoolQuery
    {
        $filter = new BoolQuery();
        $filter->add(
            new TermsQuery('blockedCustomerGroupIds', $criteriaPart->getCustomerGroupIds()),
            BoolQuery::MUST_NOT
        );

        return $filter;
    }
}
public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart));
    }

    private function getQuery(PropertyCondition $criteriaPart): TermsQuery
    {
        return new TermsQuery('properties.id', $criteriaPart->getValueIds());
    }
}


    private function parseEqualsAnyFilter(EqualsAnyFilter $filter, EntityDefinition $definition, Context $context): BuilderInterface
    {
        $fieldName = $this->buildAccessor($definition$filter->getField()$context);

        if ($this->keyValueStorage->get(ElasticsearchIndexer::ENABLE_MULTILINGUAL_INDEX_KEY, false)) {
            $field = $this->getField($definition$fieldName);

            $value = $this->parseValue($definition$filter, \array_values($filter->getValue()));

            $query = new TermsQuery($fieldName$value);

            if ($field instanceof TranslatedField) {
                $query = new DisMaxQuery();
                foreach ($context->getLanguageIdChain() as $languageId) {
                    $accessor = $this->getTranslatedFieldName($fieldName$languageId);
                    $query->addQuery(new TermsQuery($accessor$value));
                }
            }

            return $this->createNestedQuery(
                $query,
                
public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart));
    }

    private function getQuery(ManufacturerCondition $criteriaPart): TermsQuery
    {
        return new TermsQuery('manufacturer.id', $criteriaPart->getManufacturerIds());
    }
}
public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addPostFilter($this->getQuery($criteriaPart));
    }

    private function getQuery(CategoryCondition $criteriaPart): TermsQuery
    {
        return new TermsQuery('categoryIds', $criteriaPart->getCategoryIds());
    }
}
$this->handle($criteriaPart$criteria$search);
    }

    private function handle(VariantCondition $criteriaPart, Criteria $criteria, Search $search): void
    {
        $groupBy = $this->buildGroupBy($criteria);

        if ($groupBy) {
            $search->addPostFilter(new TermQuery($groupBy, true));

            $search->addPostFilter(
                new TermsQuery(
                    'filterConfiguration.options.id',
                    $criteriaPart->getOptionIds()
                )
            );

            return;
        }

        $search->addPostFilter(new TermQuery('isMainVariant', true));

        $search->addPostFilter(
            
Home | Imprint | This part of the site doesn't use cookies.