API search order has no effect
See original GitHub issueSteps to reproduce:
- use wagtail 1.9 & elasticsearch 2 or any version of wagtail-pg-search-backend
- install Wagtail’s API
- go to
http://localhost:8000/api/v2/pages/?search=a+non-empty+search&order=first_published_at
where you replacea+non-empty+search
with any search query that returns results - go to
http://localhost:8000/api/v2/pages/?search=a+non-empty+search&order=-first_published_at
(with the same replacement as before) - compare the results
As you should see, ordering has no effect on the actual order of results. I discovered this issue while trying to implement search ordering (not to be confused with ranking) in wagtail-pg-search-backend. And I couldn’t find how to do it with the current way search is implemented.
So I guess searching doesn’t handle custom ordering. Unfortunately, the opposite is written in the docs, even with details on how to use it.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Deezer API Search does not honor the "order" and sometimes ...
The order param is not currently implementing for advanced search ; that's why it is not considered on your request.
Read more >Views + Search API not properly sorting by Commerce Price ...
I've tried indexing the price field as an integer, decimal, and string but it always has the same effect. There are no additional...
Read more >Stock not decrementing when order created using API
Hello! I am currently encountering an issue with the create order endpoint in the API not decrementing stock.
Read more >findItemsByKeywords - API Reference - Finding API
This call searches for items on eBay by a keyword query (keywords). ... Sorting has no affect upon the quantity of returned results....
Read more >Search REST API Reference - Algolia
Results will be received in the same order as the requests. Errors: 400 : Bad request argument; 404 : Index does not exist....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
#5318 should hopefully fix the issue with API. To make code snippets work from my previous comment - we will also need to make changes in the elastcisearch backends. I think it’s a separate issue so I created #5319
I recently hand a similar issue with:
This happens because Wagtail API sets reverse order using the
reverse()
on aQuerySet
:https://github.com/wagtail/wagtail/blob/58135ccf6ea06095379c32e07578095545b37762/wagtail/api/v2/filters.py#L79-L95
And Elasticsearch backends do not detect reverse order set using this method:
https://github.com/wagtail/wagtail/blob/58135ccf6ea06095379c32e07578095545b37762/wagtail/search/backends/base.py#L120-L140
Note that
wagtail.contrib.postgres_search.backend
doesn’t use_get_order_by
method, so it works with fine.Examples using code. This one works as expected with Elasticsearch search backend:
This one will return results in different (ascending?) order: