Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paging is broken when using algolia backend search #98

Closed
ericmulder opened this issue Sep 18, 2020 · 2 comments
Closed

Paging is broken when using algolia backend search #98

ericmulder opened this issue Sep 18, 2020 · 2 comments
Labels
can't reproduce We cannot reproduce the issue with a standard installation and default theme

Comments

@ericmulder
Copy link

Describe the bug
Hi, I think I found a little bug in the backend search engine. The function found_posts in includes/class-algolia-search.php:212 uses the function should_filter_query. But that function checks if it is a search query. But found posts is not a search query.

I think you could just remove the check there since the found_posts function is only triggered from the pre_get_posts function on line 155 which itself already checked if it should filter the query (on line 105)

To Reproduce
Steps to reproduce the behavior:

  1. Use algoliaas backend search engine
  2. Search for a term
  3. Check which result count is being used by the function found_posts in includes/class-algolia-search.php:212
  4. This is always the wordpress function, and not the found posts count from algolia

Expected behavior
When using the algolia backend search engine, we want the found posts from there.

Desktop (please complete the following information):

  • Plugin version 1.4.0
  • WordPress 5.5.1
@ericmulder ericmulder changed the title Paging is broken when using Paging is broken when using algolia backend search Sep 18, 2020
@richaber
Copy link
Contributor

Howdy @ericmulder,

I'm sorry to hear that you are experiencing issues with pagination.
Obviously it is difficult to diagnose the issue you are experiencing, since I do not have the same code, data, and environment that you have, but in my local testing, WP Search with Algolia 1.4.0 appears to be behaving as expected with WordPress 5.5.1 and a default Twenty* theme.

To verify that paging is indeed working as expected in WP Search with Algolia, I spun up a new local testing environment with WordPress 5.5.1.
The default Twenty Twenty theme is active.
The default "Hello World" post and "Sample Page" are present.
Under WP-Admin -> Settings -> Reading, "Blog pages show at most" is set to 10 posts.

I installed and activated the Query Monitor and Any Ipsum plugins to assist with testing.

I generated 20 posts with Any Ipsum, using the default "Bacon Ipsum" for text content...

bash-3.2$ wp any-ipsum generate-posts 20 --excerpt --titles
Generating Posts:  100% [====================] 0:09 / 0:08
Success: Done! 20 posts generated in 10 seconds

I tested the standard WordPress search.
Searching for "bacon" yielded 15 results, and 2 pages.
On page 1 of the search results, Query Monitor's "Conditionals" tab indicates that is_search() is true.
On page 2 of the search results, Query Monitor's "Conditionals" tab indicates that is_paged() and is_search() are true.

I installed and activated WP Search with Algolia 1.4.0.
I configured my Algolia credentials and index name prefix.
I configured the plugin to "Use Algolia in the backend".
I enabled indexes for posts, pages, media, categories, and tags.

I reindexed my testing content with WP-CLI...

bash-3.2$ wp algolia reindex --all
Processing 1 pages of results.  100% [====================] 0:00 / 0:00
Success: Indexed "1" pages of results inside index "wp_searchable_posts"
Processing 1 pages of results.  100% [====================] 0:00 / 0:00
Success: Indexed "1" pages of results inside index "wp_posts_post"
Processing 1 pages of results.  100% [====================] 0:00 / 0:00
Success: Indexed "1" pages of results inside index "wp_posts_page"
Success: Index wp_posts_attachment was created but no entries were sent.
Processing 1 pages of results.  100% [====================] 0:00 / 0:00
Success: Indexed "1" pages of results inside index "wp_terms_category"
Success: Index wp_terms_post_tag was created but no entries were sent.

I tested the WP Search with Algolia backend search.
Searching for "bacon" yielded 15 results, and 2 pages.
On page 1 of the search results, Query Monitor's "Conditionals" tab indicates that is_search() is true.
On page 2 of the search results, Query Monitor's "Conditionals" tab indicates that is_paged() and is_search() are true.

There were no differences in the results between WordPress standard search and WP Search with Algolia backend search. Paging through each result set worked as expected.

Based on my testing, pagination appears to be behaving as expected with WP Search with Algolia v 1.4.0, WordPress 5.5.1, and a default Twenty* theme (in this test case Twenty Twenty).

This leads me to believe there may be something specific to your environment that I cannot reproduce.

Do you have any plugins or custom code that could be interfering with WP Search with Algolia's functionality?
Does your theme use "standard" WordPress search and pagination functionality, or does it do something "custom"?
Are your indexes up to date?
Have you tried deactivating other plugins, and switching to a default Twenty* theme?
That might help you identify where the issue is coming from.

@richaber richaber added the can't reproduce We cannot reproduce the issue with a standard installation and default theme label Sep 26, 2020
@ericmulder
Copy link
Author

Hi @richaber, you're right. It was a conflicting plugin (facetwp) which was messing with the main_query. Sorry to bother you and thanks for the time spent researching!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can't reproduce We cannot reproduce the issue with a standard installation and default theme
Projects
None yet
Development

No branches or pull requests

2 participants