Is your enhancement related to a problem? Please describe.
Hi,
I'm playing around with ElasticPress because bots are spamming our search function with, well, spam and this puts unnecessary pressure on our database.
So if you have it index everything (even protected content), search from within wp-admin is also done using Elastic. Which is nice. What is not so nice is that the default order is by score. I think this is not very intuitive for the editor.
So when playing around, I found that there is a filter, ep_set_default_sort, but that only handles the normal listing of posts. Its default is by post_date desc, which is fine because that is how WP defaults too.
When you actually do a search, you need to hook into ep_set_sort. And it is not very obvious what you have to return. For Google: This would be the answer:
Well and I think this should be an UI option. Because first of all, you find all sorts of confusing answers to this problem (maybe leftovers from older versions) with wrong information - such as you need to return "date" (while for this hook, you need to return "post_date"). And then I feel like you could offer all the other possible values, like score.
Designs
No response
Describe alternatives you've considered
I guess adding this filter see above does the trick... For now. But when you change your internal data structure, it might stop working. And being a filter, it also would not throw an error, so it'd be hard to debug why the behaviour changes.
Also WP's default order (if nothing else is specified) is by post_title (if the queried word is included) and by post_date. So having the default changed to at least post_date desc would come closer to what stock WP does.
Code of Conduct
[X] I agree to follow this project's Code of Conduct
Is your enhancement related to a problem? Please describe.
Hi,
I'm playing around with ElasticPress because bots are spamming our search function with, well, spam and this puts unnecessary pressure on our database.
So if you have it index everything (even protected content), search from within wp-admin is also done using Elastic. Which is nice. What is not so nice is that the default order is by score. I think this is not very intuitive for the editor.
So when playing around, I found that there is a filter,
ep_set_default_sort
, but that only handles the normal listing of posts. Its default is by post_date desc, which is fine because that is how WP defaults too.When you actually do a search, you need to hook into
ep_set_sort
. And it is not very obvious what you have to return. For Google: This would be the answer:Well and I think this should be an UI option. Because first of all, you find all sorts of confusing answers to this problem (maybe leftovers from older versions) with wrong information - such as you need to return "date" (while for this hook, you need to return "post_date"). And then I feel like you could offer all the other possible values, like score.
Designs
No response
Describe alternatives you've considered
I guess adding this filter see above does the trick... For now. But when you change your internal data structure, it might stop working. And being a filter, it also would not throw an error, so it'd be hard to debug why the behaviour changes.
Also WP's default order (if nothing else is specified) is by post_title (if the queried word is included) and by post_date. So having the default changed to at least post_date desc would come closer to what stock WP does.
Code of Conduct