1

我们有一个运行 Relevanssi Wordpress 插件 ( https://www.relevanssi.com ) 的客户网站 ( http://hayball.com.au )。

客户注意到某些结果在搜索时不会出现。例如,搜索“学习”一词应显示包含“学习”作为搜索词的所有结果。即使搜索词在标题中,它也不会显示名为“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 插件。

任何帮助或帮助将不胜感激。

谢谢,戴恩

4

2 回答 2

1

我已经使用 Relevanssi 几年了,但我不是专家。如果它存在于我们的任何帖子中,我没有遇到过找不到搜索词的情况。由于在搜索 caulfield 时找到了该帖子,这意味着该帖子已被索引。我在我的网站上添加了一个帖子,标题是您在上面提供的。Relevansii 在搜索“学习或学习”时返回了该帖子。我可以重现未找到的帖子的唯一方法是将“学习”添加到 Relevanssi 停用词列表中。确保它不在您的停用词列表中。Settings/indexing/Show Advanced Settings 下有一个 Relevanssi 选项,可以用空格替换 & 符号。我测试了你的帖子标题用空格替换&符号并再次保留&符号。两次都找到了。抱歉,我无法提供更多帮助。

于 2018-03-04T21:38:14.070 回答
0

事实证明,在我们的代理机构接管之前,该网站的前任开发人员忽略了在搜索结果中建立分页。所以它确实出现了,但在第 3 页。哈哈。

感谢大家的帮助。

于 2018-03-05T22:37:49.113 回答