• Hello,

    the function relevanssi_query() is launched when the filter the_posts is fired. This function retrieves the posts we are looking for, but, the WP_Query has already been launched and results analysed in &get_posts() by WordPress.

    Is it possible to add the following filter on pre_get_posts :

    add_filter('pre_get_posts', 'cancel_wp_query', 10, 1);
    
    function cancel_wp_query($q) {
    	if( $q->is_search ) {
    		$q->query_vars['p'] = -1;
    	}
    }

    We specify to the query to find no post to optimize the loading time. Is it a bad idea ?

    Thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Might be a very good idea, indeed. Thanks!

    I tried this. Searching for a common word that gets 500 hits from ~1000 posts took 0.0071 seconds. Adding your code reduced that to 0.0011 or so (hard to test exactly, because of caching I can’t try the same search term again).

    So, not a huge difference, but I don’t think there’s any harm in it, so I’ll add it in the next version.

    Thread Starter b.l.k

    (@blk-1)

    Thank you for your try and your comment 🙂
    Indeed, this is not the best improvement that could be added but thanks the time you spent ! 😉

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Relevanssi – A Better Search] Maybe an optimization ?’ is closed to new replies.