Support » Plugin: Relevanssi - A Better Search » Search results return no results when Relevanssi is turned on

  • Hi I just downloaded the current version of Relevanssi(3.5.8), I have indexed my site, added my custom post type(exhibit) to be indexed then reindexed the site. After I finished, I went to my home page and searched for a page I know I have, “Welcome”. I was returned no results. I then deactivated the plugin and searched again, and was returned 3 results(2 return because they have welcom in their content. I then reactivated the plugin and tired again, and again I was returned 0 results.

    I have 2 search results pages one just for the exhibit custom post type, and the other for the entire site. On my search.php I have this:

    $search_refer = $_GET["site_section"];
    $search_post = $_GET["post_types"];
    if ($search_post == 'exhibit') { load_template(TEMPLATEPATH . '/exhibit-search.php'); }
    if ($search_refer == 'main-search') { load_template(TEMPLATEPATH . '/site-search.php'); };

    Should I be using something like this instead of the default dsearch results query:

    `$query->query_vars[‘s’] = $post->post_title;
    $query->query_vars[‘posts_per_page’] = 5;
    $query->query_vars[‘operator’] = ‘or’;
    relevanssi_do_query($query);`

    Thanks,

    Aaron

    • This topic was modified 6 months, 2 weeks ago by  amadhav1.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Switching to a new template with load_template() shouldn’t be a problem. Can you show me what’s inside site-search.php, for example?

    The search results template should have no query at all; there’s generally no need for one, and it will just disturb Relevanssi. If you need to change the query parameters, do that in a pre_get_posts filter instead of running a second query from the search results template.

    Hi Mikko,

    This is what I have for my site-search.php

    <?php
    /*
    The template for displaying Search Results pages.*/
    ?>
    
    <?php get_header(); ?>
    <div class="row">
       <h1 class="search-title">
    <?php _e( 'Search Results Found For', 'locale' ); ?>: "<?php the_search_query(); ?>"
    </h1>
    <?php global $query_string;
    
    $query_args = explode("&", $query_string);
    $search_query = array();
    
    if( strlen($query_string) > 0 ) {
    	foreach($query_args as $key => $string) {
    		$query_split = explode("=", $string);
    		$search_query[$query_split[0]] = urldecode($query_split[1]);
    	} // foreach
    } //if
    
    $search = new WP_Query($search_query);
      
    	 if ( $search->have_posts() ) : while ( $search->have_posts() ) : $search->the_post(); ?>
    	<div class="media">		
    	<div class="media-left media-middle">	
    
    	<?php
    if ( has_post_thumbnail() ) {
    	echo "<div class='media-object'>";
    	the_post_thumbnail( 'thumbnail' );
    	echo "</div>";
    }?> 
    		</div>
     <div class="media-body">
    			<h2 class="media-heading"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    
    			<?php the_excerpt(); ?>
    			<?php 
    			if(get_post_type( get_the_ID() )=='exhibit'){ e?>
    			<p><a href="<?php the_permalink(); ?>" class="btn btn-info">Continue Reading</a>
    			</p> <?php } ?>
    		</div>
    </div>
    
      <?php endwhile; else: ?>
    		<p><?php _e('Sorry, no results found.'); ?></p>
    	<?php endif; ?>
    
    		  <!-- pagination -->
            		 <?php custom_pagination(); ?>
      
    </div>
    
    <?php get_footer(); ?>

    Any Idea why I can’t get results with relevanssi?

    Thanks,

    Aaron

    Plugin Author Mikko Saari

    (@msaari)

    Yes: that new WP_Query() is dropping Relevanssi off. Relevanssi replaces the original query, which you then discard and create a new query Relevanssi doesn’t see.

    Why you need to create a new query there in the first place? Seems to me you’re not actually doing anything that would require a new query. You’re just creating a second query using the same parameters as the first query.

    Can’t you just remove the whole $search query and use the default query? Relevanssi would work with that, and you’d save server resources, too – now your site is running every search query twice.

    Hello,

    I made the fix that you suggested, however I am still unable to find any search results. I am trying to display basic results with Relevanssi turned on, and I am unable to get any results. This is my basic search results page for looks like, but it does not return results, and if I turn off the plugin I get 11 results.

    <?php   
    	 if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    			<h2 class="media-heading"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    
    <?php endwhile; else: ?>
    		<p><?php _e('Sorry, no results found.'); ?></p>
    	<?php endif; ?>

    Any Idea why I can’t get any results?

    Thanks,

    Aaron

    • This reply was modified 6 months, 1 week ago by  amadhav1.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Search results return no results when Relevanssi is turned on’ is closed to new replies.