Posted on

Debugging Relevanssi searching issues

Relevanssi has plenty of useful filter hooks you can use to debug problems. Here are some examples of how you can use the Relevanssi filter hooks to debug issues. Place the functions one at the time in the theme functions.php file and run a search to see results.

Look at the parameters Relevanssi is getting

add_filter( 'relevanssi_modify_wp_query', 'rlv_check_parameters' );
function rlv_check_parameters( $query ) {
    var_dump( $query->query_vars );

If you add this and run a search, you’ll see the query parameters Relevanssi uses. Is there something there that doesn’t look right? For example is there a taxonomy parameter that shouldn’t be there?

Look at the MySQL query

add_filter( 'relevanssi_query_filter', 'rlv_check_mysql' );
function rlv_check_mysql( $query ) {
    var_dump( $query );

This shows the final MySQL query that is used. There’s one for each search term, so this’ll show the query for the first search term (which is not necessarily the word you entered first). Are there any unexpected restrictions involved?

Look at the results

add_filter( 'relevanssi_results', 'rlv_check_results' );
function rlv_check_results( $results ) {
    var_dump( $results );

This should print out an array of ( post ID, post weight ) pairs. Does that match the number of results you expect to find?

Look at the posts returned

If everything else checks out fine, find this line in lib/search.php file in Relevanssi:

$posts = relevanssi_do_query( $query );

After that line, add:

var_dump( $posts );

Then run a search. If you see a list of posts as expected, but your search results are still showing up empty, then the problem is not in Relevanssi. Relevanssi is providing the correct results, after which your theme discards them and runs into some other trouble.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.