1

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

前任:-

“我可以找到”在模型 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
4

1 回答 1

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
于 2013-01-17T13:44:46.190 回答