【问题标题】:How we can search any word is searchable on sunspot solr on rails project我们如何搜索任何单词都可以在 sunspot solr on rails 项目上搜索
【发布时间】:2013-01-04 12:36:32
【问题描述】:

如何用句子搜索全文并搜索任何匹配的单词。

例如:-

"may i find" 正在模型 ttle 中搜索

它必须显示与“may”、“i”、“find”中的任何一个词匹配的结果

test = Model.search do 
  fulltext key do
    fields(:title)
    query_phrase_slop 1
  end
  without(:field_disabled, true)
  facet(:obj_type)
end

【问题讨论】:

    标签: ruby-on-rails solr ruby-on-rails-3.2 sunspot-solr


    【解决方案1】:

    我得到的输出只是搜索键也接受单词数组,所以我们可以通过下面的代码得到这个

    def custom_search
    test = Model.search do 
     fulltext key do
      fields(:title)
      query_phrase_slop 1
     end
     without(:field_disabled, true)
     facet(:obj_type)
    end
    if test.hits.size==0 #check the condition for no result matched for full text and passing every word
    test = Model.search do 
     fulltext key.split(' ') do # key.split(' ') code make total sentence into array of words
      fields(:title)
      query_phrase_slop 1
     end
     without(:field_disabled, true)
     facet(:obj_type)
    end
    end
    return test
    end
    

    【讨论】:

    • @Subbarao can you solve this question我工作了两天,但我找不到解决方案
    • 是的,我通过 .split(' ') 将句子分成多个单词
    猜你喜欢
    • 2012-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多