• I have this:

    $args = array(
    				's' => $search,
    				'posts_per_page' => 30,
    				'show_posts' => -1,
    			);
    
    			$query = new WP_Query( $args );
    
    			// Relevanssi support
    			if ( function_exists( 'relevanssi_do_query' ) ) {
    				relevanssi_do_query( $query );
    			}
    
    			return $query->posts;

    I have unit test content installed and if I remove the call to relevanssi_do_query I get search results, and if I add it in, I always get 0 results.

    I’m doing that piece of code above in an ajax call.

    https://www.ads-software.com/plugins/relevanssi/

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

    (@msaari)

    Does any results get passed to the relevanssi_hits_filter filter? What kind of parameters get passed through relevanssi_search_filters?

    Thread Starter Benjamin Intal

    (@bfintal)

    I did this:

    add_filter( 'relevanssi_hits_filter', function( $hits ) {
    	var_dump( '$hits', $hits );
    	return $hits;
    });
    
    add_filter( 'relevanssi_search_filters', function( $filters ) {
    	var_dump( '$filters', $filters );
    	return $filters;
    });

    And I got this for hits:

    array(2) {
      [0]=>
      array(0) {
      }
      [1]=>
      string(8) "template"
    }

    and for filters:

    array(15) {
      ["q"]=>
      string(8) "template"
      ["tax_query"]=>
      array(0) {
      }
      ["tax_query_relation"]=>
      string(2) "OR"
      ["post_query"]=>
      array(0) {
      }
      ["parent_query"]=>
      array(0) {
      }
      ["meta_query"]=>
      array(0) {
      }
      ["date_query"]=>
      bool(false)
      ["expost"]=>
      NULL
      ["post_type"]=>
      bool(false)
      ["post_status"]=>
      bool(false)
      ["operator"]=>
      string(2) "OR"
      ["search_blogs"]=>
      bool(false)
      ["author"]=>
      bool(false)
      ["orderby"]=>
      NULL
      ["order"]=>
      string(4) "DESC"
    }

    My search term was template and commenting out relevanssi_do_query gives me 11 results.

    Thread Starter Benjamin Intal

    (@bfintal)

    I’m developing a commercial search bar plugin. I’m using VVV and with Theme Unit Test right now. The ultimate goal here is to promote Relevanssi within the plugin so that customers can get better search results when coupled with it.

    Plugin Author Mikko Saari

    (@msaari)

    Hmm… more filters you can check: what goes through relevanssi_query_filter? Does anything go through relevanssi_match?

    Thread Starter Benjamin Intal

    (@bfintal)

    No relevanssi_match results. But relevanssi_query_filter gets hit twice:

    First:

    string(541) "SELECT relevanssi.*, relevanssi.title * 5 + relevanssi.content + 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 wp_relevanssi AS relevanssi  WHERE  relevanssi.term = 'template'   AND ((relevanssi.doc IN (SELECT DISTINCT(posts.ID) FROM wp_posts AS posts
    			WHERE posts.post_type IN ('post', 'page', 'attachment'))) OR (doc = -1)) ORDER BY tf DESC LIMIT 500"

    Second:

    string(560) "SELECT relevanssi.*, relevanssi.title * 5 + relevanssi.content + 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 wp_relevanssi AS relevanssi  WHERE (term LIKE '%template' OR term LIKE 'template%')   AND ((relevanssi.doc IN (SELECT DISTINCT(posts.ID) FROM wp_posts AS posts
    			WHERE posts.post_type IN ('post', 'page', 'attachment'))) OR (doc = -1)) ORDER BY tf DESC LIMIT 500"
    Plugin Author Mikko Saari

    (@msaari)

    That double hit is to be expected, the second is the fuzzy search fallback when the first search finds nothing.

    Try running that MySQL query directly on the MySQL server. What kind of results you get there? While at it, you can also check that the index in wp_relevanssi database looks good.

    Thread Starter Benjamin Intal

    (@bfintal)

    Figured out the problem. I didn’t dive into the database and settings and I just assumed that the content would readily be searchable when Relevanssi was activated. Instead I browsed the docs in the site.

    When I activated Relevanssi I already had existing content that showed up in the search results. After activating Relevanssi, those results disappeared. I would like propose a feature request: automatically build the indexing without user intervention upon plugin activation.

    Additional question: Since I’m doing a:

    $query = new WP_Query( $args );

    then passing that $query object to relevanssi_do_query, I think I’m hitting the database twice: 1 for the normal WP_Query then 1 for the Relevanssi engine. Is there a way to drop the 1st WP_Query database call?

    Plugin Author Mikko Saari

    (@msaari)

    Ah, yes. Automatic indexing is a bit of a problem, because it can take a long time to index the whole site, and if you want to change the settings, it’s a huge pain to wait fifteen minutes for the automatic indexing to finish, then just to change some setting and have to reindex.

    You don’t have to use new WP_Query() to build the query object. Relevanssi never checks if it gets a WP_Query object, as long as the necessary attributes ($query->query_vars) are where it expects them to be.

    $query = new stdClass();
    $query->query_vars['s'] = $s;
    $query->query_vars['posts_per_page'] = 30;

    and so on.

    Thread Starter Benjamin Intal

    (@bfintal)

    Tried stdClass, but I’m getting errors like no property is_admin in stdClass, no have_posts in stdClass. Unfortunately the searched posts are also added to the stdClass so you lose the WP_Query functions. It’s fixable, but I want to use WP_Query functions without any more additional code.

    I found out that calling new WP_Query() without any arguments won’t trigger a database call, so I’ll just use that for now when Relevanssi is available.

    It also seems that the paged parameter is required by Relevanssi aside from s and posts_per_page.

    I have a suggestion with the auto-indexing. I have a similar problem with another plugin currently being tested, we also needed to execute a long running task. That long running task may span for 5 minutes depending on the size of the site. Our solution was to execute just chunks of the task every time the frontend was called. To prevent those small chunks from hindering the page-load, we’re using a non-blocking wp_remote_get to start the execution.

    Plugin Author Mikko Saari

    (@msaari)

    Yes, paged is required to trigger the paging.

    Background indexing is something that has been on the works for quite a while now; hopefully at some point it’ll be possible.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘relevanssi_do_query Not Returning Any Results’ is closed to new replies.