SimpleQueryStringQuery example

public function globalCriteria(string $term, Search $criteria): Search
    {
        $splitTerms = explode(' ', $term);
        $lastPart = end($splitTerms);

        // If the end of the search term is not a symbol, apply the prefix search query         if (preg_match('/^[a-zA-Z0-9]+$/', $lastPart)) {
            $term = $term . '*';
        }

        $query = new SimpleQueryStringQuery($term[
            'fields' => ['textBoosted'],
            'boost' => 10,
        ]);

        $criteria->addQuery($query, BoolQuery::SHOULD);

        return $criteria;
    }

    /** * @param array<string>|array<int, array<string>> $ids * * @throws Exception * * @return array<int|string, array<string, mixed>> */
private function buildSearch(string $term, int $limit): Search
    {
        $search = new Search();
        $splitTerms = explode(' ', $term);
        $lastPart = end($splitTerms);

        // If the end of the search term is not a symbol, apply the prefix search query         if (preg_match('/^[a-zA-Z0-9]+$/', $lastPart)) {
            $term = $term . '*';
        }

        $query = new SimpleQueryStringQuery($term[
            'fields' => ['text'],
        ]);

        $search->addQuery($query, BoolQuery::SHOULD);
        $search->setSize($limit);

        return $search;
    }
}
Home | Imprint | This part of the site doesn't use cookies.