Wordpress Search Query gets executet although using SOLR

  • f.schatz
    Participant
    5 months ago #37511

    When using WP Solr for the main search (?s=test) the search still takes very long. So we debugged via Plugin Query Monitor and found out that, although WP SOLR is searching via SOLR, the following sql is executed

    SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
    FROM wp_posts
    WHERE 1=1
    AND (((wp_posts.post_title LIKE ‘%Berlin%’)
    OR (wp_posts.post_excerpt LIKE ‘%Berlin%’)
    OR (wp_posts.post_content LIKE ‘%Berlin%’)))
    AND ((wp_posts.post_type = ‘post’
    AND (wp_posts.post_status = ‘publish’
    OR wp_posts.post_status = ‘acf-disabled’
    OR wp_posts.post_status = ‘private’))
    OR (wp_posts.post_type = ‘page’
    AND (wp_posts.post_status = ‘publish’
    OR wp_posts.post_status = ‘acf-disabled’
    OR wp_posts.post_status = ‘private’)))
    ORDER BY wp_posts.post_title LIKE ‘%Berlin%’ DESC, wp_posts.post_date DESC
    LIMIT 0, 10

    Which takes about 4 secounds in our Database. This should not happen as this fulltext search over the wp_posts table is very slow, thats why we are using wp solr`

    The stack is

    WP_Query->get_posts()
    wp-includes/class-wp-query.php:3312
    WP_Query->query()
    wp-includes/class-wp-query.php:3800
    WP->query_posts()
    wp-includes/class-wp.php:662
    wpsolr\c\c\s\WPSOLR_Service_Container::get_is_replace_by_wpsolr_query()
    app/plugins/wpsolr-pro/wpsolr/core/classes/services/class-wpsolr-service-container.php:192
    wpsolr\c\c\s\WPSOLR_Service_Container::action_wp_loaded()
    app/plugins/wpsolr-pro/wpsolr/core/classes/services/class-wpsolr-service-container.php:46
    do_action(‘wp_loaded’)
    wp-includes/plugin.php:517

    Can you check or tell me what to do?

    wpsolr
    Keymaster
    5 months ago #37512

    Which WPSOLR version do you use?

    Do you use some other search/facet/filter plugin that could interfere?

    f.schatz
    Participant
    5 months ago #37513

    No. But as you see the stack

    WPSOLR_Service_Container::get_is_replace_by_wpsolr_query()
    if ( ! is_admin() ) {
    $wp->parse_request();
    add_filter( ‘posts_pre_query’, [ self::class, ‘posts_pre_query’ ], 10, 2 );
    $wp->query_posts();
    remove_filter( ‘posts_pre_query’, [ self::class, ‘posts_pre_query’ ], 10 );
    do_action( WPSOLR_Events::WPSOLR_ACTION_IS_REPLACE_BY_WPSOLR_QUERY_AFTER_POST_PRE_QUERY );
    }

    and

    static function posts_pre_query( $retval, $query ) {
    // Prevent executing SQL before deciding replacing the query
    return null;
    }

    posts_pre_query is empty an does not prevent anything?

    wpsolr
    Keymaster
    5 months ago #37515

    This is correct. It should, and used to be, “return [];” instead of “return null;”

    You can patch your file as a workaround. I’ll make more tests in the meantime.

    wpsolr
    Keymaster
    5 months ago #37516

    There are issues with this fix since WordPress 6.1, leading to 404 pages.
    I’ll have to dig deeper into the problem.

    f.schatz
    Participant
    5 months ago #37520

    Could you already check this? Its a pretty huge issue as the search is really slow due to that.

    wpsolr
    Keymaster
    5 months ago #37521

    I’m testing a fix right now.

    wpsolr
    Keymaster
    5 months ago #37569

    Here is a release containing the fix to replace your current release.

    Please check carefully all pages of your site, as it is a fundamental change. It has been tested quite extensively, but we never know.

    The fix will be part of WPSOLR 23.6

    f.schatz
    Participant
    5 months ago #37574

    Thanks a lot. But i think its still executed?

    Stack is

    WP_Query->get_posts
    WP_Query->query
    WP->query_posts
    wpsolr\core\classes\services\WPSOLR_Service_Container::get_is_replace_by_wpsolr_query
    wpsolr\core\classes\services\WPSOLR_Service_Container::action_wp_loaded
    do_action(‘wp_loaded’)
    require_once(‘wp-settings.php’)
    require_once(‘/var/www/clients/client2/web2/web/www/web/wp-config.php’)
    require_once(‘wp-load.php’)
    require(‘wp-blog-header.php’)

    What did you changed? Maybe i can have a look to?

    wpsolr
    Keymaster
    5 months ago #37575
    SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
    FROM wp_posts
    WHERE 1=1
    AND (((wp_posts.post_title LIKE ‘%Berlin%’)
    OR (wp_posts.post_excerpt LIKE ‘%Berlin%’)
    OR (wp_posts.post_content LIKE ‘%Berlin%’)))
    AND ((wp_posts.post_type = ‘post’
    AND (wp_posts.post_status = ‘publish’
    OR wp_posts.post_status = ‘acf-disabled’
    OR wp_posts.post_status = ‘private’))
    OR (wp_posts.post_type = ‘page’
    AND (wp_posts.post_status = ‘publish’
    OR wp_posts.post_status = ‘acf-disabled’
    OR wp_posts.post_status = ‘private’)))
    ORDER BY wp_posts.post_title LIKE ‘%Berlin%’ DESC, wp_posts.post_date DESC
    LIMIT 0, 10

    should have disappeared from your logs now.

    f.schatz
    Participant
    5 months ago #37576

    Sadly its not. Thats why the question what exactly you changed than i could debug on our side too?

    wpsolr
    Keymaster
    5 months ago #37577

    Same place that you mentioned before.

    Can I see here your screen 2.1, and a screenshot of the trace from Query monitor leading to AND (((wp_posts.post_title LIKE ‘%Berlin%’) ?

    f.schatz
    Participant
    5 months ago #37578

    SORRY, i missed copying all files. Now everything is fine. Thanks a lot for your great support.

    wpsolr
    Keymaster
    5 months ago #37579

    Great!

    wpsolr
    Keymaster
    3 months, 2 weeks ago #38491

    WPSOLR 23.6 is ready.

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.