apply_filters( 'relevanssi_search_again', array $params )

This filter hook controls the fallback search.


(array) An array of search parameters.

More information

When Relevanssi runs a search, Relevanssi may run the search immediately again. The typical case is using the partial word matching fallback: Relevanssi will rerun the search with partial matching enabled if the whole word search finds no results.

You can use this filter hook to trigger a new search. This filter hook gets these search parameters:

  • doc_weight: an array of (post ID, weight) pairs for the results found so far.
  • no_matches: if Relevanssi found no results, this is true.
  • operator*: the search operator.
  • phrase_queries*: the queries for phrase matching.
  • query_join*: the JOIN query from the relevanssi_join filter hook.
  • query_restrictions*: the MySQL query restrictions.
  • search_again: if this filter hook returns true for this value, the search will run again.
  • terms: the search terms.

The parameters marked with an * are not available until the next version of Relevanssi is out.

This filter hook is not convenient, and most users will have no reason ever to use this. If you use the forced phrase search, it is easier to do the fallback using this filter hook:

add_filter( 'relevanssi_search_again', function( $params ) {
    if ( $params['no_matches'] ) {
        $params['phrase_queries'] = array();
        $params['search_again']   = true;
    return $params;
}, 10, 1 );

This function blanks out the phrase queries if Relevanssi finds no matches and sets the search_again flag so that Relevanssi does a new search.