Relevanssi Wordpress 搜索结果
Relevanssi Wordpress Search Results
我们有一个客户网站 (http://hayball.com.au) running the Relevanssi Wordpress Plugin (https://www.relevanssi.com)。
客户发现某些结果在搜索时没有出现。例如,搜索词条 'learning' 应显示包含 'learning' 作为搜索词条的所有结果。它不显示名为 "Caulfield Grammar School, Masterplan & Learning Project" 的项目,即使搜索词在标题中也是如此。
如果您随后使用 "caulfield" 作为搜索词,它会显示该项目。这是在主题中显示搜索结果的代码。
<?php if (have_posts()): ?>
<ul>
<?php while (have_posts()) : the_post(); ?>
<?php
$posttype = get_post_type();
$link = '';
$readmore = '';
$excerpt = '';
if( $posttype == 'projects' ) {
$category = get_the_terms(get_the_ID(), 'sector');
$primaryCat = get_post_meta(get_the_ID(),'_yoast_wpseo_primary_sector',true);
if($primaryCat){
$category = null;
$primary = get_term($primaryCat, 'sector');
$category[] = $primary;
}
$link = '<a href="/projects/">' . $project . '</a>';
if($category) {
$link = $link . ' / <a href="/projects/#' . $category[0]->slug . '">' . $category[0]->name . '</a>';
}
$link = $link . ' / <a href="' . get_the_permalink() . '">' . get_the_title() . '</a>';
$readmore = get_the_permalink();
$excerpt = get_the_excerpt();
}
if( $posttype == 'news' ) {
$category = get_the_terms(get_the_ID(), 'category');
$link = '<a href="/news/">' . $exchange . '</a>';
if($category) {
$link = $link . ' / <a href="/news/#' . $category[0]->slug . '">' . $category[0]->name . '</a>';
}
$link = $link . ' / <a href="' . get_the_permalink() . '">' . get_the_title() . '</a>';
$readmore = get_the_permalink();
$excerpt = get_the_excerpt();
}
if( $posttype == 'award' ) {
$link = ''; //'<a href="/practice/awards/">Awards</a>';
$readmore = '/practice/awards/';
$excerpt = get_the_excerpt();
}
if( $posttype == 'person' ) {
$link = ''; //'<a href="/practice/people/">People</a>';
$readmore = '/practice/people/';
$excerpt = get_the_title();
}
if( $posttype == 'location' ) {
$link = ''; //'<a href="/contact/">Contact</a>';
$readmore = '/contact/';
$excerpt = get_field('address');
}
if( $posttype == 'page' ) {
$link = ''; //'<a href="' . get_the_permalink() . '">' . get_the_title() . '</a>';
$readmore = get_the_permalink();
}
?>
<li id="<?php echo get_the_ID(); ?>">
<div class="content">
<h4><?php the_title(); ?></h4>
<p class="link">
<?php echo $link; ?>
</p>
<p><?php echo $excerpt; ?></p>
<a href="<?php echo $readmore; ?>"><?php echo translation('read_more'); ?></a>
</div>
<?php if(wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'thumbnail' )) : ?>
<div class="image" style="background-image: url('<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'thumbnail' ); echo $image[0]; ?>')"></div>
<?php endif; ?>
</li>
<?php endwhile; ?>
</ul>
<?php else: ?>
<p>
0 <?php echo translation('results'); ?>
</p>
<?php endif; ?>
我也被告知尝试将此添加到 functions.php 似乎什么也没做。
function mjt_project_search( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array( 'projects', 'news', 'award', 'person', 'location', 'page') );
$query->set( 'post_status', array( 'publish') );
}
return $query;}
add_filter( 'pre_get_posts', 'mjt_project_search' );`
当插件被禁用时,它会正确显示结果,但客户端要求所有搜索结果具有高相关性,因此使用 Relevanssi 插件。
如有任何帮助或帮助,我们将不胜感激。
谢谢,
戴恩
我已经使用 Relevanssi 几年了,但不是专家。如果它存在于我们的任何 post 中,我还没有遇到找不到搜索词的情况。由于在搜索 caulfield 时发现 post,这意味着 post 已被编入索引。我用您在上面提供的标题向我的网站添加了一个 post。 Relevansii 在搜索 "learning or learn" 时返回了 post。我可以重现未找到的 post 的唯一方法是将 "learning" 添加到 Relevanssi 停用词列表。确保它不在您的停用词列表中。 Settings/indexing/Show Advanced Settings 下有一个 Relevanssi 选项可以用空格替换 & 符号。我测试了您的 post 标题,用空格替换了 & 符号并再次保留了 & 符号。两次都找到了。抱歉,我帮不上什么忙。
事实证明,在我们的代理机构接管网站之前,该网站的前任开发人员忽略了在搜索结果中建立分页。所以它确实出现了但是在第3页。哈哈。
感谢大家的帮助。
我们有一个客户网站 (http://hayball.com.au) running the Relevanssi Wordpress Plugin (https://www.relevanssi.com)。
客户发现某些结果在搜索时没有出现。例如,搜索词条 'learning' 应显示包含 'learning' 作为搜索词条的所有结果。它不显示名为 "Caulfield Grammar School, Masterplan & Learning Project" 的项目,即使搜索词在标题中也是如此。
如果您随后使用 "caulfield" 作为搜索词,它会显示该项目。这是在主题中显示搜索结果的代码。
<?php if (have_posts()): ?>
<ul>
<?php while (have_posts()) : the_post(); ?>
<?php
$posttype = get_post_type();
$link = '';
$readmore = '';
$excerpt = '';
if( $posttype == 'projects' ) {
$category = get_the_terms(get_the_ID(), 'sector');
$primaryCat = get_post_meta(get_the_ID(),'_yoast_wpseo_primary_sector',true);
if($primaryCat){
$category = null;
$primary = get_term($primaryCat, 'sector');
$category[] = $primary;
}
$link = '<a href="/projects/">' . $project . '</a>';
if($category) {
$link = $link . ' / <a href="/projects/#' . $category[0]->slug . '">' . $category[0]->name . '</a>';
}
$link = $link . ' / <a href="' . get_the_permalink() . '">' . get_the_title() . '</a>';
$readmore = get_the_permalink();
$excerpt = get_the_excerpt();
}
if( $posttype == 'news' ) {
$category = get_the_terms(get_the_ID(), 'category');
$link = '<a href="/news/">' . $exchange . '</a>';
if($category) {
$link = $link . ' / <a href="/news/#' . $category[0]->slug . '">' . $category[0]->name . '</a>';
}
$link = $link . ' / <a href="' . get_the_permalink() . '">' . get_the_title() . '</a>';
$readmore = get_the_permalink();
$excerpt = get_the_excerpt();
}
if( $posttype == 'award' ) {
$link = ''; //'<a href="/practice/awards/">Awards</a>';
$readmore = '/practice/awards/';
$excerpt = get_the_excerpt();
}
if( $posttype == 'person' ) {
$link = ''; //'<a href="/practice/people/">People</a>';
$readmore = '/practice/people/';
$excerpt = get_the_title();
}
if( $posttype == 'location' ) {
$link = ''; //'<a href="/contact/">Contact</a>';
$readmore = '/contact/';
$excerpt = get_field('address');
}
if( $posttype == 'page' ) {
$link = ''; //'<a href="' . get_the_permalink() . '">' . get_the_title() . '</a>';
$readmore = get_the_permalink();
}
?>
<li id="<?php echo get_the_ID(); ?>">
<div class="content">
<h4><?php the_title(); ?></h4>
<p class="link">
<?php echo $link; ?>
</p>
<p><?php echo $excerpt; ?></p>
<a href="<?php echo $readmore; ?>"><?php echo translation('read_more'); ?></a>
</div>
<?php if(wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'thumbnail' )) : ?>
<div class="image" style="background-image: url('<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'thumbnail' ); echo $image[0]; ?>')"></div>
<?php endif; ?>
</li>
<?php endwhile; ?>
</ul>
<?php else: ?>
<p>
0 <?php echo translation('results'); ?>
</p>
<?php endif; ?>
我也被告知尝试将此添加到 functions.php 似乎什么也没做。
function mjt_project_search( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array( 'projects', 'news', 'award', 'person', 'location', 'page') );
$query->set( 'post_status', array( 'publish') );
}
return $query;}
add_filter( 'pre_get_posts', 'mjt_project_search' );`
当插件被禁用时,它会正确显示结果,但客户端要求所有搜索结果具有高相关性,因此使用 Relevanssi 插件。
如有任何帮助或帮助,我们将不胜感激。
谢谢, 戴恩
我已经使用 Relevanssi 几年了,但不是专家。如果它存在于我们的任何 post 中,我还没有遇到找不到搜索词的情况。由于在搜索 caulfield 时发现 post,这意味着 post 已被编入索引。我用您在上面提供的标题向我的网站添加了一个 post。 Relevansii 在搜索 "learning or learn" 时返回了 post。我可以重现未找到的 post 的唯一方法是将 "learning" 添加到 Relevanssi 停用词列表。确保它不在您的停用词列表中。 Settings/indexing/Show Advanced Settings 下有一个 Relevanssi 选项可以用空格替换 & 符号。我测试了您的 post 标题,用空格替换了 & 符号并再次保留了 & 符号。两次都找到了。抱歉,我帮不上什么忙。
事实证明,在我们的代理机构接管网站之前,该网站的前任开发人员忽略了在搜索结果中建立分页。所以它确实出现了但是在第3页。哈哈。
感谢大家的帮助。