composeFullTextSearchData($filter); $fullTextWhere = $fullTextSearchData ? $this->processFullTextSearch($queryBuilder, $fullTextSearchData) : null; $fullTextSearchFieldList = $fullTextSearchData ? $fullTextSearchData->getFieldList() : []; $fieldList = $forceFullTextSearch ? [] : array_filter( $this->metadataProvider->getTextFilterAttributeList($this->entityType) ?? self::DEFAULT_ATTRIBUTE_LIST, function ($field) use ($fullTextSearchFieldList) { return !in_array($field, $fullTextSearchFieldList); } ); $skipWildcards = false; if (mb_strpos($filter, '*') !== false) { $skipWildcards = true; $filter = str_replace('*', '%', $filter); } $filterData = FilterData::create($filter, $fieldList) ->withSkipWildcards($skipWildcards) ->withForceFullTextSearch($forceFullTextSearch) ->withFullTextSearchWhereItem($fullTextWhere); $this->filterFactory ->create($this->entityType, $this->user) ->apply($queryBuilder, $filterData); } private function composeFullTextSearchData(string $filter): ?FullTextSearchData { $composer = $this->fullTextSearchDataComposerFactory->create($this->entityType); $params = FullTextSearchDataComposerParams::create(); return $composer->compose($filter, $params); } private function processFullTextSearch(QueryBuilder $queryBuilder, FullTextSearchData $data): WhereItem { $expression = $data->getExpression(); $fullTextOrderType = self::DEFAULT_FT_ORDER; $orderTypeMap = [ 'combined' => self::FT_ORDER_COMBINED, 'relevance' => self::FT_ORDER_RELEVANCE, 'original' => self::FT_ORDER_ORIGINAL, ]; $mOrderType = $this->metadataProvider->getFullTextSearchOrderType($this->entityType); if ($mOrderType) { $fullTextOrderType = $orderTypeMap[$mOrderType]; } $previousOrderBy = $queryBuilder->build()->getOrder(); $hasOrderBy = !empty($previousOrderBy); if (!$hasOrderBy || $fullTextOrderType === self::FT_ORDER_RELEVANCE) { $queryBuilder->order([ OrderExpr::create($expression)->withDesc() ]); } else if ($fullTextOrderType === self::FT_ORDER_COMBINED) { $orderExpression = Expr::round( Expr::divide($expression, $this->fullTextOrderRelevanceDivider) ); $newOrderBy = array_merge( [OrderExpr::create($orderExpression)->withDesc()], $previousOrderBy ); $queryBuilder->order($newOrderBy); } if ($this->fullTextRelevanceThreshold) { return Expr::greaterOrEqual( $expression, $this->fullTextRelevanceThreshold ); } return Expr::notEqual($expression, 0); } }