Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 9 additions & 22 deletions Sphinx/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,9 @@ protected function buildQuery(): string
$clauses[] = 'ORDER BY ' . $this->buildOrder($this->orderBy);
}

$clauses[] = sprintf('LIMIT %d, %d', $this->offset, $this->limit);
if ($this->limit) {
$clauses[] = sprintf('LIMIT %d, %d', $this->offset, $this->limit);
}

if ($this->option) {
$clauses[] = 'OPTION ' . $this->buildOption($this->option);
Expand Down Expand Up @@ -711,7 +713,7 @@ protected function buildOption(array $options): string
*
* @return array
*/
public function getResults(): array
public function getResults()
{
if($this->_state === self::STATE_CLEAN) {
$this->results;
Expand Down Expand Up @@ -800,12 +802,8 @@ protected function createStatement(string $query): PDOStatement
*
* @return array
*/
protected function applyQueryBuilder(array $results): array
protected function applyQueryBuilder(array $results): \Doctrine\ORM\Query
{
if (count($results) == 0) {
return [];
}

$ids = array_map('intval', array_column($results, 'id'));
$results = [];

Expand All @@ -817,22 +815,11 @@ protected function applyQueryBuilder(array $results): array
->setFirstResult(null)
->setMaxResults(null);

if ($this->orderBy) {
$this->queryBuilder->resetDQLPart('orderBy');
}

$entities = $this->queryBuilder->getQuery()->getResult();

foreach ($entities as $entity) {
$idGetter = 'get' . ucfirst($this->queryBuilderColumn);
$id = $entity->$idGetter();
$position = array_search($id, $ids);
$results[$position] = $entity;
}

ksort($results);
// if ($this->orderBy) {
// $this->queryBuilder->resetDQLPart('orderBy');
// }

return array_values($results);
return $this->queryBuilder->getQuery();
}

private function populateMetadata() {
Expand Down