Search->sort() in PHP client - how does it work?

I would like to sort my returned search results by date (descending), attribute2 (ascending), attribute3 (descending), attribute4 (ascending). Based on the PHP client documentation, I would expect that I should be able to do this by specifying

$search->sort(['date' => 'DESC', 'attribute2' => 'ASC', 'attribute3' => 'DESC', 'attribute4' => 'ASC']);

after setting the index using

$search->setIndex('indx');

and before running get(), like so:

$results = $search->search($search_string)->get();

The first problem that I notice is that the PHP client doesn’t accept capitalized sort order parameters, as would be customary in MySQL. (I would ask, as a feature request, that the sort order parameters be made case insensitive.)

Okay, fine, so

$search->sort(['date' => 'desc', 'attribute2' => 'asc', 'attribute3' => 'desc', 'attribute4' => 'asc']);

should work, right? No:

PHP Fatal error: Uncaught Manticoresearch\\Exceptions\\ResponseException: "Error parsing json query: \\"sort\\" property \\"\\" should be an object"

All right, maybe we can still at least sort by date? Let’s try:

$search->sort(['date' => 'desc']);

Now our returned listing goes from

1999-06-04
2023-01-19
2005-02-21
2005-12-14
1998-10-29
2008-10-16
1985-04-19
2020-05-25
2015-10-07

to

2005-02-21
2005-12-14
1998-10-29
1999-06-04
2008-10-16
2015-10-07
1985-04-19
2020-05-25
2023-01-19

Something has changed, but the results are not properly ordered by date.

So, I’m not really sure if sort() just plain doesn’t work, or if I’m using it wrong.

In any case, I would like to propose, as a feature request, that

$search->sort(['date' => 'DESC', 'attribute2' => 'ASC', 'attribute3' => 'DESC', 'attribute4' => 'ASC']);

be an acceptable input to the sort() function, both with multiple attributes sorted using different directions and with sort directions of any capitalization being acceptable.

I found my first problem: date wasn’t listed as an attribute in the configuration file. I added sql_attr_string = date to the source portion of the configuration file, rebuilt the index (using sudo indexer --all --rotate), chown’d the permissions of the index files (in /var/lib/manticore) to manticore user using sudo chown --from=root:root manticore:manticore *, then reloaded the indexes in the MySQL interface using mysql -h0 -P9306 and RELOAD INDEXES;.

Now my sorting by date works correctly.

However, sorting by two attributes using the array syntax still does not work.