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.

First try Relevanssi admin search

Before checking the filters, try the Relevanssi admin search (Dashboard > Admin search). Does that find the correct results? If it does, then the problem is likely with your theme.

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 );
    exit();
}

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 );
    exit();
}

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 );
    exit();
}

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 );
exit();

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.

7 comments Debugging Relevanssi searching issues

  1. Hi,

    unfortunatly i get no searchresults anymore after moving to a new host (dont know if thats relevant?!)

    Parameters:
    array(67) { [“s”]=> string(4) “test” [“error”]=> string(0) “” [“m”]=> string(0) “” [“p”]=> int(0) [“post_parent”]=> string(0) “” [“subpost”]=> string(0) “” [“subpost_id”]=> string(0) “” [“attachment”]=> string(0) “” [“attachment_id”]=> int(0) [“name”]=> string(0) “” [“static”]=> string(0) “” [“pagename”]=> string(0) “” [“page_id”]=> int(0) [“second”]=> string(0) “” [“minute”]=> string(0) “” [“hour”]=> string(0) “” [“day”]=> int(0) [“monthnum”]=> int(0) [“year”]=> int(0) [“w”]=> int(0) [“category_name”]=> string(0) “” [“tag”]=> string(0) “” [“cat”]=> string(0) “” [“tag_id”]=> string(0) “” [“author”]=> string(0) “” [“author_name”]=> string(0) “” [“feed”]=> string(0) “” [“tb”]=> string(0) “” [“paged”]=> int(0) [“meta_key”]=> string(0) “” [“meta_value”]=> string(0) “” [“preview”]=> string(0) “” [“sentence”]=> string(0) “” [“title”]=> string(0) “” [“fields”]=> string(0) “” [“menu_order”]=> string(0) “” [“embed”]=> string(0) “” [“category__in”]=> array(0) { } [“category__not_in”]=> array(0) { } [“category__and”]=> array(0) { } [“post__in”]=> array(0) { } [“post__not_in”]=> array(0) { } [“post_name__in”]=> array(0) { } [“tag__in”]=> array(0) { } [“tag__not_in”]=> array(0) { } [“tag__and”]=> array(0) { } [“tag_slug__in”]=> array(0) { } [“tag_slug__and”]=> array(0) { } [“post_parent__in”]=> array(0) { } [“post_parent__not_in”]=> array(0) { } [“author__in”]=> array(0) { } [“author__not_in”]=> array(0) { } [“posts_per_page”]=> int(50) [“post_type”]=> array(6) { [0]=> string(4) “post” [1]=> string(4) “page” [2]=> string(15) “avada_portfolio” [3]=> string(9) “avada_faq” [4]=> string(7) “product” [5]=> string(12) “tribe_events” } [“ignore_sticky_posts”]=> bool(false) [“suppress_filters”]=> bool(false) [“cache_results”]=> bool(false) [“update_post_term_cache”]=> bool(true) [“lazy_load_term_meta”]=> bool(true) [“update_post_meta_cache”]=> bool(true) [“nopaging”]=> bool(false) [“comments_per_page”]=> string(2) “50” [“no_found_rows”]=> bool(false) [“search_terms_count”]=> int(1) [“search_terms”]=> array(1) { [0]=> string(4) “test” } [“search_orderby_title”]=> array(1) { [0]=> string(166) “uxmao_posts.post_title LIKE ‘{23bc5bb05bd47c926c81635c7cc70f66dc403aa07af5e97baba9ba9281e3e9b2}test{23bc5bb05bd47c926c81635c7cc70f66dc403aa07af5e97baba9ba9281e3e9b2}'” } [“order”]=> string(4) “DESC” }

    Query
    string(632) “SELECT DISTINCT(relevanssi.doc), relevanssi.*, relevanssi.title * 5 + relevanssi.content * 1 + relevanssi.comment * 0.75 + relevanssi.tag * 0.75 + relevanssi.link * 0 + relevanssi.author + relevanssi.category * 0.75 + relevanssi.excerpt + relevanssi.taxonomy + relevanssi.customfield + relevanssi.mysqlcolumn AS tf FROM uxmao_relevanssi AS relevanssi WHERE relevanssi.term = ‘test’ AND ( relevanssi.doc IN ( SELECT DISTINCT(posts.ID) FROM uxmao_posts AS posts WHERE posts.post_type IN (‘post’, ‘page’, ‘avada_portfolio’, ‘avada_faq’, ‘product’, ‘tribe_events’) ) ) ORDER BY tf DESC LIMIT 500”

    results
    array(0) { }

    When I disabled relevanssi the search works just fine. (currently disabled)

    I hope you can help! I already miss the plugin functions! 🙂

      1. Thanks for the VERY FAST reply 🙂
        Yes I rebuilt the index (900+ Posts indexed) and also reinstalled the plugin completely.

        Anything else I can try?

    1. Sounds like a problem with your theme then. Not the first time there’s a problem with Avada, but as I don’t have access to Avada and haven’t seen your site, it’s hard to say what’s wrong.

      1. I figured it out yesterday night – not the cause but a workarround. Must be something with Avada 6+ because on the staging site it still works fine without the workarround.

        What I did was: I replaced “” with your shortcode to display the searchform. That made the magic.

        Thank you for pointing me in the right direction.
        For me the problem is solved but if you are interested in finding the real cause I could provide you with a testlogin to the staging-site.

        Best.
        Niko

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.