diff --git a/core/kernel/persistence/starsql/search/GateWay.php b/core/kernel/persistence/starsql/search/GateWay.php index 903b2a8df..48968ffc5 100644 --- a/core/kernel/persistence/starsql/search/GateWay.php +++ b/core/kernel/persistence/starsql/search/GateWay.php @@ -137,7 +137,7 @@ private function fetchObjectList(Statement $query): array if (!$object) { continue; } - $returnValue[] = \common_Utils::toResource($object); + $returnValue[] = \common_Utils::toResource($object->getProperty('uri')); } return $returnValue; } diff --git a/core/kernel/persistence/starsql/search/QuerySerializer.php b/core/kernel/persistence/starsql/search/QuerySerializer.php index f14ab983e..e9a616604 100644 --- a/core/kernel/persistence/starsql/search/QuerySerializer.php +++ b/core/kernel/persistence/starsql/search/QuerySerializer.php @@ -315,30 +315,25 @@ protected function buildLanguagePattern(QueryConvertible $predicate): RawExpress protected function buildReturn(Node $subject): void { - $this->returnStatements[] = $subject->property('uri'); + $this->returnStatements[] = Query::rawExpression( + sprintf('DISTINCT %s', $subject->getVariable()->toQuery()) + ); } protected function buildOrderCondition(Node $subject): void { $sortCriteria = $this->criteriaList->getSort(); - $queryOptions = $this->criteriaList->getOptions(); - $isDistinct = $queryOptions['distinct'] ?? false; $sort = []; - if ($this->criteriaList->getRandom() && !$isDistinct) { - $this->returnStatements[] = Procedure::raw('rand')->alias('rnd'); - $sort[] = '`rnd`'; - } else { - foreach ($sortCriteria as $field => $order) { - $predicate = $subject->property($field); - - $orderProperty = ModelManager::getModel()->getProperty($field); - if ($orderProperty->isLgDependent()) { - $predicate = $this->buildLanguagePattern($predicate); - } + foreach ($sortCriteria as $field => $order) { + $predicate = $subject->property($field); - $sort[] = $predicate->toQuery() . ((strtolower($order) === 'desc') ? ' DESCENDING' : ''); + $orderProperty = ModelManager::getModel()->getProperty($field); + if ($orderProperty->isLgDependent()) { + $predicate = $this->buildLanguagePattern($predicate); } + + $sort[] = $predicate->toQuery() . ((strtolower($order) === 'desc') ? ' DESCENDING' : ''); } if (!empty($sort)) {