Skip to content
This repository was archived by the owner on Feb 21, 2025. It is now read-only.
This repository was archived by the owner on Feb 21, 2025. It is now read-only.

Unable to sort queries #210

@lozcalver

Description

@lozcalver

Currently there doesn’t appear to be anything in QueryComponentFactory that copies the sort order over from the BaseQuery object to Solarium’s query object.

The suggested format in the docs (sorry for using blame view, apparently you can’t link to specific lines of markdown on Github without using it...) also appears to be incorrect, as solarium expects an array in the format of <field> => <dir> rather than an indexed array of strings which contain both the field name and direction.

As usual, my workaround is in the onBeforeSearch() hook:

<?php

namespace App\Extensions\Indexes;

use Firesphere\SolrSearch\Queries\BaseQuery;
use SilverStripe\Core\Extension;
use Solarium\QueryType\Select\Query\Query;

class MyIndexExtension extends Extension
{
    public function onBeforeSearch(BaseQuery $query, Query $clientQuery)
    {
        $clientQuery->setSorts($query->getSort());
    }
}

The docs also need to be updated so they show sort examples in the following format:

$baseQuery->setSort(['ObjectName_Date' => 'asc']);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions