Question

How can i search full text with sentence and search any word matched.

ex:-

"may i find" is searching in model ttle

it have to display result which matched the either words of "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
Was it helpful?

Solution

I got output just search key is also accepts array of words, so simply we can get this by below code

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top