handleFilter example



    private function addConditions(
        Criteria $criteria,
        ShopContextInterface $context,
        EsSearch $search
    ): void {
        foreach ($criteria->getBaseConditions() as $condition) {
            $handler = $this->handlerRegistry->getHandler($condition);

            if ($handler instanceof PartialConditionHandlerInterface) {
                $handler->handleFilter($condition$criteria$search$context);
            } else {
                trigger_error(sprintf("Condition handler %s doesn't support new filter mode. Class has to implement \\Shopware\\Bundle\\SearchBundleES\\PartialConditionHandlerInterface.", \get_class($handler)), E_USER_DEPRECATED);
                $handler->handle($condition$criteria$search$context);
            }
        }

        foreach ($criteria->getUserConditions() as $criteriaPart) {
            $handler = $this->handlerRegistry->getHandler($criteriaPart);

            // Trigger error when new interface isn't implemented             if (!$handler instanceof PartialConditionHandlerInterface) {
                


    /** * {@inheritdoc} */
    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $this->handleFilter($criteriaPart$criteria$search$context);
    }

    private function getQuery(SearchTermCondition $criteriaPart, ShopContextInterface $context): BoolQuery
    {
        return $this->queryBuilder->buildQuery($context$criteriaPart->getTerm());
    }
}


    /** * {@inheritdoc} */
    public function handlePostFilter(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $this->handleFilter($criteriaPart$criteria$search$context);
    }

    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]);
        
$search = new EsSearch();
        $handlerRegistry = $this->container->get(HandlerRegistry::class);

        if (!$handlerRegistry instanceof HandlerRegistry) {
            throw new RuntimeException(sprintf('%s is missing', HandlerRegistry::class));
        }

        foreach ($conditions as $condition) {
            $handler = $handlerRegistry->getHandler($condition);

            if ($handler instanceof PartialConditionHandlerInterface) {
                $handler->handleFilter($condition$criteria$search$context);
            } else {
                $handler->handle($condition$criteria$search$context);
            }
        }

        $query = new BoolQuery();

        if ($search->getPostFilters()) {
            $query->add($search->getPostFilters());
        }

        
Home | Imprint | This part of the site doesn't use cookies.