rails sunspot solr search by keywords

元气小坏坏 提交于 2019-12-11 19:14:02

问题


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

My expected output is

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.

My fulltext is working good

I have edited 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>

MY model contains

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

My controller is

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

Edit 1

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.

I changed fulltext params[:search] do to keywords params[:search] do

Edit 2

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

回答1:


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

You should add minimum_match to your search block, i.e.:

@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).



来源:https://stackoverflow.com/questions/18820145/rails-sunspot-solr-search-by-keywords

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!