• Resolved Tema

    (@madeinua)


    Hi,

    I have a huge performance issue when entering an empty search query.

    Here is the difference between the non-empty search term and empty one:

    SELECT COUNT(DISTINCT(relevanssi.doc)) 
    FROM poutrweevr_relevanssi AS relevanssi
    ...
    WHERE  relevanssi.term = 'text to find'   
    ...
    SELECT COUNT(DISTINCT(relevanssi.doc)) 
    FROM poutrweevr_relevanssi AS relevanssi
    ...
    WHERE  relevanssi.term = relevanssi.term   
    ...

    Can you verify this?

    Thanks
    Artem

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Yes, that is Relevanssi working as it should. There’s no search term, so Relevanssi will look for everything, which of course can be really slow. Relevanssi does restrict the termless search to 500 posts even if the search isn’t otherwise throttled, but the query can still be slow.

    There are a couple of approaches here. You can, for example, prevent the termless search completely or tighten the throttle.

    Thread Starter Tema

    (@madeinua)

    Okay, but can this be somehow disabled? I.e. just don’t start the query and return nothing if the search string is empty.

    Plugin Author Mikko Saari

    (@msaari)

    Yes, you can disable it. There are many ways, one is this:

    add_filter( 'relevanssi_search_ok', function( $ok, $query ) {
      return empty( $query->query_vars['s'] ) ? false : $ok;
    }, 10, 2 );

    This will make the termless search fall back to the default WP search.

    Thread Starter Tema

    (@madeinua)

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Empty term performance’ is closed to new replies.