2013-01-04 21 views

回答

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 
+0

@Subbarao [你能解決這個問題](http://stackoverflow.com/questions/18820145/rails-sunspot-solr-search-by-keywords)我工作了兩天,但我找不到解決方案 – overflow

+0

是的,我用.split('')將句子分割成多個單詞完成 –