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. Add the functions one at a time to your site and run a search to see results.

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.

Use Query Monitor

Query Monitor is a superb tool for debugging WordPress behaviour. It’s very useful for debugging Relevanssi searches as well – you can see the queries Relevanssi makes and notice unwanted query parameters appearing in the database queries.

Here are some instructions on how to use Query Monitor.

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

Use Query Monitor, or add this:

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 that’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 empty, then the problem is not in Relevanssi. Relevanssi is providing the correct results, after which your theme discards them and runs into other trouble.

9 comments Debugging Relevanssi searching issues

  1. Hi,

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

    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” }

    string(632) “SELECT DISTINCT(relevanssi.doc), relevanssi.*, relevanssi.title * 5 + relevanssi.content * 1 + relevanssi.comment * 0.75 + relevanssi.tag * 0.75 + * 0 + + 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”

    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.


  2. Hi Mikko,
    I unfortunately, i get no search results after I update my sites Relevanssi search plugin. I have try Admin search and I get no post results. I have indexed the site multiple times, but it still doesn’t work.



    1. Derrick, when you say “Admin search”, do you mean the WP admin search under Posts, or the Relevanssi admin search under Dashboard > Admin search?

      First step would be to check that the indexing is correct. Does the “State of the Index” in Relevanssi indexing settings show the correct number of posts? If you look at individual posts with the Relevanssi debugger, do they seem to be indexed correctly?

      If the indexing is working, then you’re at the right place: you can use the tools on this page to debug why the search doesn’t work. If you need help, please try these methods and report your findings, preferably in a new thread on the Relevanssi support forums.

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

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