• AJ

    (@ajisimplifymecom)


    Hello,
    I am trying to use the relevanssi_didyoumean feature for your plugin, but I am getting an empty result. I’m including a code snippet found in a content file that is called in the actual page template. Please let me know if you need more information:

    /**
     * The template used for displaying page content in page-all-products.php
     */
    if(get_query_var('search') <> ''){
    	$args = array(
    		'posts_per_page'	=> 12,
    		'post_type'		=>	'product',
    		'orderby'		=>	'menu_order',
    		'order'			=>	'ASC',
    		'post_status'	=>	'publish',
    		's'				=>  get_query_var('search')
    	);
    	$query = new WP_Query( $args );
    	if(function_exists('relevanssi_do_query')) relevanssi_do_query( $query );
    }
    elseif(get_query_var('application') <> '' || get_query_var('family') <> '' || get_query_var('mounting') <> '') {
    	$taxQuery = array();
    	if(get_query_var('application') <> '') $taxQuery[] = array(
    		'taxonomy'	=> 'product_application',
    		'field'		=> 'slug',
    		'terms'		=> get_query_var('application'),
    	);
    	if(get_query_var('family') <> '') $taxQuery[] = array(
    		'taxonomy'	=> 'product_family',
    		'field'		=> 'slug',
    		'terms'		=> get_query_var('family'),
    	);
    	if(get_query_var('mounting') <> '') $taxQuery[] = array(
    		'taxonomy'	=> 'product_mounting',
    		'field'		=> 'slug',
    		'terms'		=> get_query_var('mounting'),
    	);
    	if(sizeof($taxQuery) > 1) $taxQuery['relation'] = 'AND';
    	$args = array(
    		'posts_per_page'	=> 12,
    		'post_type'		=>	'product',
    		'orderby'		=>	'menu_order',
    		'order'			=>	'ASC',
    		'post_status'	=>	'publish',
    		'tax_query'		=>  $taxQuery
    	);
    	$query = new WP_Query( $args );
    }
    else {
    	$args = array(
    		'posts_per_page'	=> 12,
    		'post_type'		=>	'product',
    		'orderby'		=>	'menu_order',
    		'order'			=>	'ASC',
    		'post_status'	=>	'publish'
    	);
    	$query = new WP_Query( $args );
    } ?>
    
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    	<header class="all-products-header">
    		<h1 class="all-products-title">Commercial LED Lighting</h1>
    		<h2 class="all-products-subtitle">Kirlin Product Search</h2>
    	</header><!-- .entry-header -->
    
    	<div id="product-list-outer">
    		<div id="product-list-inner">
    			<div class="product-list-controls product-list-controls-top">
    				<div id="all-products-matches"><?php
    					if($query->found_posts < 1){
    						if ( function_exists( 'relevanssi_didyoumean' ) ) {
    							relevanssi_didyoumean(
    								get_search_query( false ),
    								'We could\'t find any results for <strong>'.get_query_var('search').'</strong>, did you mean: ',
    								'',
    								5
    							);
    						}
    						else echo 'There aren\'t any products matching your search term, <strong>'.get_query_var('search').'</strong>';
    					}
    					else {
    						echo '<em>'.$query->found_posts.'</em>'; if($query->found_posts == 1) echo ' Product'; else echo ' Products'; if(get_query_var('search') <> '') echo ' for <strong>'.get_query_var('search').'</strong>';
    					}
    					?></div>
Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Mikko Saari

    (@msaari)

    First of all, instead of

    if(get_query_var('search') <> ''){
    	$args = array(
    		'posts_per_page'	=> 12,
    		'post_type'		=>	'product',
    		'orderby'		=>	'menu_order',
    		'order'			=>	'ASC',
    		'post_status'	=>	'publish',
    		's'				=>  get_query_var('search')
    	);
    	$query = new WP_Query( $args );
    	if(function_exists('relevanssi_do_query')) relevanssi_do_query( $query );
    }

    do this:

    if(get_query_var('search') <> ''){
    	$args = array(
    		'posts_per_page'	=> 12,
    		'post_type'		=>	'product',
    		'orderby'		=>	'menu_order',
    		'order'			=>	'ASC',
    		'post_status'	=>	'publish',
    		's'				=>  get_query_var('search')
                    'relevanssi' => true,
    	);
    	$query = new WP_Query( $args );
    }

    You’ll avoid doing one useless WP_Query that way.

    Have you checked that get_search_query( false ) returns the correct search terms? The free version of Did you mean suggestions is based on logged search queries. Do you have enough queries logged? You can also try deleting the relevanssi_didyoumean_query transient to clear the Relevanssi Did you mean cache.

    Thread Starter AJ

    (@ajisimplifymecom)

    get_search_query( false ) returns an empty string as well. I’ve never logged search queries before, is there something I’m missing regarding this? (IE is this done automatically or is there something I need to do myself to make WP do that?)

    Plugin Author Mikko Saari

    (@msaari)

    Ok, so figure out where you can get the actual search string; without it, this won’t work.

    You then need to enable the search logging in Relevanssi settings in order to get suggestions in the free version. Once you do that, the suggestions will start to slowly improve. Give it six months and they’re probably fine.

    (Relevanssi Premium has a much better “Did you mean” feature that is based on the actual indexed content of your site, it’ll work better and faster.)

    Thread Starter AJ

    (@ajisimplifymecom)

    can you give me an example of what a search string looks like? is it something i can build with the search variable?

    Plugin Author Mikko Saari

    (@msaari)

    Earlier in the code, you’re getting the search string from get_query_var('search'):

    's' => get_query_var('search')

    It’s the value of s, nothing fancier than that.

    Thread Starter AJ

    (@ajisimplifymecom)

    got it, so i should just be able to do this?

    relevanssi_didyoumean(
    	get_query_var('search'),
    	'We could\'t find any results for <strong>'.get_query_var('search').'</strong>, did you mean: ',
    	'',
    	5
    );
    Plugin Author Mikko Saari

    (@msaari)

    Yes, that should work.

    Thread Starter AJ

    (@ajisimplifymecom)

    ok, so if i pair that solution with relevanssi premium, it should work without having to log searches, right?

    Plugin Author Mikko Saari

    (@msaari)

    Yes, Relevanssi Premium does not use search logging to power the “Did you mean” suggestions.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘relevanssi_didyoumean not working’ is closed to new replies.