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

BUG: ElasticPress running two queries when using Twenty Twenty-Two theme #2745

Closed
nickchomey opened this issue May 8, 2022 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@nickchomey
Copy link
Contributor

nickchomey commented May 8, 2022

I just switched from my theme to Twenty Twenty Two to debug something and I noticed that the search results really didn't seem to be in the correct order, so I used the Debug Bar ElasticPress to inspect the query and results.

It turns out that it is running two queries, and the only difference between the two is that the first shows:

{
    "from": 0,
    "size": 100,
    "sort": [
        {
            "_score": {
                "order": "desc"
            }
        }
    ],

and the second shows

{
    "from": 0,
    "size": 100,
    "sort": [
        {
            "post_date": {
                "order": "desc"
            }
        }
    ],

Inspecting the results, I can see that the first query is ordered appropriately. Evidently it is being replaced by the 2nd.

From some basic step debugging with xdebug, I can see that the first query triggers the ep_set_sort filter, though it defaults to _score anyway.

The 2nd query doesn't get there, because $args['orderby'] is not empty.

Here are the callstacks

Query 1
image

Query 2
image

It looks like the first query is called in the initial \wp-blog-header.php -> wp() process and then when that completes, it goes through the motions again with require_once ABSPATH . WPINC . '/template-loader.php'; at the end of that file.

Disabling all plugins except for Debug Bar and ElasticPress doesn't fix it. If I switch back to my theme or Twenty Twenty-One, only one score-sorted query happens. If I remove search blocks from the pages in 2022, that doesn't help.

I'm not smart enough to know/figure out if this is a problem inherent to ElasticPress, Gutenberg, 2022 theme, Block Themes in general, etc... But I hope this is useful information!

Steps to Reproduce

  1. Activate Twenty Twenty-Two theme
  2. Activate Debug Bar and Debug Bar ElasticPress
  3. Do a search.
  4. Check the queries and results.

Expected behavior
One query, sorted by Score.

Environment information

  • Device: Linux VPS
  • OS: Ubuntu 20.04
  • Browser and version: Microsoft Edge
  • WordPress version: 5.9.3
  • ElasticPress version: 4.10
  • Elasticsearch version: 7.17.3
  • Where do you host your Elasticsearch server? Self Hosted (localhost)
  • What ElasticPress features do you have currently active? Still happens even with only Posts active.
  • Plugins and version: As explained, it happens with them all disabled.
  • Theme and version: Twenty Twenty-Two 1.1
@nickchomey nickchomey added the bug Something isn't working label May 8, 2022
@felipeelia
Copy link
Member

Thanks, @nickchomey. We are keeping track of this problem in #2694 already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants