This is a follow-up to #3111984: Support for sorting.
With the logic we currently have in applySortingToQuery(), there's no way to filter by the "special" fields that Search API support.
\Drupal\search_api\QueryInterface::sort() which also support the following fields:
* - search_api_relevance: Sort by relevance.
* - search_api_datasource: Sort by datasource.
* - search_api_language: Sort by language.
* - search_api_id: Sort by item ID.
My proposal is not to add custom logic before adding the sort to the query and let Search API fail in case the passed sort is not supported (Patch to follow).
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | interdiff_2-3.txt | 566 bytes | jsacksick |
| #3 | 3122594-3.patch | 1.89 KB | jsacksick |
Comments
Comment #2
jsacksick commentedComment #3
jsacksick commentedExpanding the tests with a sort on the "search_api_id" field.
Comment #4
mglamanSo we removed validation for invalid field values though. That prevents the API from letting the client know they chose an incorrect sort option
Comment #5
jsacksick commented"So we removed validation for invalid field values though. That prevents the API from letting the client know they chose an incorrect sort option"
No, because Search API will throw an exception that's then caught by us when the query is executed. We can add a specific method to test this if you'd like.
Comment #6
jsacksick commentedWhen I try to sort by an invalid field, I get the following response:
Comment #8
mglamanWoo!