[Plugin: Relevanssi - A Better Search] Maybe an optimization ? (4 posts)

  1. b.l.k
    Posted 4 years ago #


    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

  2. Mikko Saari
    Posted 4 years ago #

    Might be a very good idea, indeed. Thanks!

  3. Mikko Saari
    Posted 4 years ago #

    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.

  4. b.l.k
    Posted 4 years ago #

    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 ! ;-)

Topic Closed

This topic has been closed to new replies.

About this Topic