用关键字搜索rails sunspot solr [英] rails sunspot solr search by keywords

查看:98
本文介绍了用关键字搜索rails sunspot solr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力搜索2天,以便使用sunspot solr查询关键字搜索.我听不懂

I am working around search for 2 days to query keyword search using sunspot solr. I am unable to understand

我的预期输出是

如果我搜索laptops in US,则应该搜索笔记本电脑和我们

if i search for laptops in US it should search for laptop and us

但是下面的代码仅搜索笔记本电脑,而不搜索其他单词.我该怎么做到.

But the below code search only laptops and not the other words. How can i achieve it.

我的全文很好

我已经编辑了schema.xml

<fieldType name="text" class="solr.TextField" omitNorms="false">
      <analyzer>
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StandardFilterFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.NGramFilterFactory" minGramSize="2" maxGramSize="15"/>
      </analyzer>

      <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StandardFilterFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
    </fieldType>

我的模型包含

searchable do
        text :title,:description,stored: true
        time :updated_at
        text :product do
            product.name if product
        end
        text :product_model do
            product_model.name if product_model
        end
    end

我的控制器是

@search = Post.search do
      fulltext params[:search] do
        query_phrase_slop 1
      end
    end

编辑1

我有两行,其中一列是pizza,另一列是post.如果我搜索pizza,则返回5个结果;如果我搜索post,则返回1个结果.最后,如果我搜索pizza post,则不会产生任何结果.但是预期的输出将得到6个结果.

I have two row with pizza in one column and post in other column. If i search for pizza it returns 5 result if i search for post it returns 1 result. And finally if i search for pizza post it results none. But expected output is to get 6 result.

我将fulltext params[:search] do更改为keywords params[:search] do

编辑2

def index
    @search = Post.search do
      fulltext params[:search].split(' ') do
        phrase_slop 1
      end
    end
    @posts = @search.results
end

推荐答案

最后,我们找到了问题所在(注释),但我将其作为答案,这样问题就可以按照回答的方式结束.

Finally, we've found what's wrong (comments), but I'll put this as an answer so question may be closed as answered.

您应在search块中添加minimum_match,即:

@search = Post.search do
      fulltext params[:search] do
        query_phrase_slop 1
        minimum_match 1
      end
    end

如果未提供该选项,则默认为所有字词都匹配"(来源).

If that option is not provided, it defaults to 'all terms match' (source).

这篇关于用关键字搜索rails sunspot solr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆