Wordpress Search Query gets executet although using SOLR
- f.schatzParticipant5 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, 10Which 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:517Can you check or tell me what to do?
f.schatzParticipant5 months ago #37513No. 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?
wpsolrKeymaster5 months ago #37569Here 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.schatzParticipant5 months ago #37574Thanks 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?
wpsolrKeymaster5 months ago #37575SELECT 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.
wpsolrKeymaster3 months, 2 weeks ago #38491WPSOLR 23.6 is ready.
You must be logged in to reply to this topic.