addTerm example


        $terms = $this->tokenizer->tokenize($term);

        $pattern = new SearchPattern(new SearchTerm($term));

        if (\count($terms) === 1) {
            return $pattern;
        }

        foreach ($terms as $part) {
            $percent = mb_strlen($part) / mb_strlen($term);
            $pattern->addTerm(new SearchTerm($part$percent));
        }

        return $pattern;
    }
}
$pattern->setTokenTerms($matches);

        $scoring = $this->score($tokens, ArrayNormalizer::flatten($matches));
        // only use the 8 best matches, otherwise the query might explode         $scoring = \array_slice($scoring, 0, self::RELEVANT_KEYWORD_COUNT, true);

        foreach ($scoring as $keyword => $score) {
            $this->logger->info('Search match: ' . $keyword . ' with score ' . (float) $score);
        }

        foreach ($scoring as $keyword => $score) {
            $pattern->addTerm(new SearchTerm((string) $keyword$score));
        }

        return $pattern;
    }

    /** * @param list<string> $tokens * * @return list<string> */
    private function permute(array $tokens): array
    {
$result->addState(self::RESULT_STATE);

        return $result;
    }

    private function createSearch(EntityDefinition $definition, Criteria $criteria, Context $context): Search
    {
        $search = new Search();
        $this->helper->addFilters($definition$criteria$search$context);
        $this->helper->addQueries($definition$criteria$search$context);
        $this->helper->addAggregations($definition$criteria$search$context);
        $this->helper->addTerm($criteria$search$context$definition);
        $this->helper->handleIds($definition$criteria$search$context);
        $search->setSize(0);

        return $search;
    }
}


    private function createSearch(Criteria $criteria, EntityDefinition $definition, Context $context): Search
    {
        $search = new Search();

        $this->helper->handleIds($definition$criteria$search$context);
        $this->helper->addFilters($definition$criteria$search$context);
        $this->helper->addPostFilters($definition$criteria$search$context);
        $this->helper->addQueries($definition$criteria$search$context);
        $this->helper->addSortings($definition$criteria$search$context);
        $this->helper->addTerm($criteria$search$context$definition);

        $search->setSize(self::MAX_LIMIT);
        $limit = $criteria->getLimit();
        if ($limit !== null) {
            $search->setSize($limit);
        }
        $search->setFrom((int) $criteria->getOffset());

        return $search;
    }

    


    /** * @dataProvider searchCustomerEmail */
    public function testSearchTokenizeTerm(bool $tokenize, string $term): void
    {
        $builder = new EntityScoreQueryBuilder();

        $pattern = new SearchPattern(new SearchTerm($term, 1));

        $pattern->addTerm(new SearchTerm('johndoe', 0.5));
        $pattern->addTerm(new SearchTerm('example', 0.3));
        $pattern->addTerm(new SearchTerm('com', 0.2));

        $definition = $tokenize ? $this->shouldTokenizeDefinition : $this->shouldNotTokenizeDefinition;

        $queries = $builder->buildScoreQueries($pattern$definition, 'test', $this->context);

        if (!$tokenize) {
            static::assertCount(2, $queries);
            static::assertEquals([
                new ScoreQuery(new EqualsFilter('test.email', $term), 100),
                
Home | Imprint | This part of the site doesn't use cookies.