10up / ElasticPress

A fast and flexible search and query engine for WordPress.
https://elasticpress.io
GNU General Public License v2.0
1.25k stars 311 forks source link

Limit Number of Results being returned #3941

Closed alifazeli closed 3 months ago

alifazeli commented 3 months ago

Describe your question

I use ElasticPress on a WordPress with a huge number of posts. Due to performance issues, I want a maximum of 1000 results to be returned per search, and the filters in the ElasticPress filter widget will also select and display the list of items within these 1000 results. In this way, users can see and filter only the first 1000 results separated from all results related to the query without affecting the score of results.

I changed the value of 'ep_max_results_window' to 1000 but there was no change in the number of results and always if the number of results is high it returns the maximum number of 10000 posts.

Is there a way to reduce the maximum of returned result ?

Code of Conduct

burhandodhy commented 3 months ago

Hi @alifazeli,

ep_max_results_window only works if the posts_per_page parameter is set to -1 https://github.com/10up/ElasticPress/blob/develop/includes/classes/Indexable/Post/Post.php#L1591. If it has any other value, that value will be used as the maximum limit.

Additionally, ensure that you are using the filter correctly. Your code should be look like this:

    add_filter( 'ep_max_results_window', function() {
        return 1000;
    } );

Regards, Burhan

alifazeli commented 3 months ago

Hi @burhandodhy

Thanks a lot. I'm not sure, maybe I'm wrong and ep_max_results_window has nothing to do with my problem. I don't want to limit the number of results per page and I can do that with WordPress widgets. I want to limit the total number of results returned in each search. If ep_max_results_window is related to the same issue though, where can I change the posts_per_page value?

Respectfully

github-actions[bot] commented 3 months ago

It has been 3 days since more information was requested from you in this issue and we have not heard back. This issue is now marked as stale and will be closed in 3 days, but if you have more information to add then please comment and the issue will stay open.

github-actions[bot] commented 3 months ago

This issue has been automatically closed because there has been no response to our request for more information in the past 3 days. With only the information that is currently available, we are unable to take further action on this ticket. Please reach out if you have found or find the answer we need so that we can investigate further. When the information is ready, you can re-open this ticket to share it with us.