0
votes

when I search for the second word the result mismatch for example 'web ' the result

["WEB MEDIA ","CREATIV WEB ","WEB SERVICES TECHNOLOGIES","iDURAR WEB AGENCY","WEB CREATION","DEV WEB SOLUTION","BIG WEB DZ","AMANA SITE WEB"]

but for 'web m' the result

["VOISINAGE PC","DELTA SOFT","MMCOMPUTING ETS","MICROPROZ","PORTIDEE","LATICODE","CYBER WEB SERVICES","SIEGE SOCIAL","EL DALIL YALAOUI ET CIE - SIEGE COMMERCIAL""IMA"]

iI try all examples in the internet

ruby
@suggestions = Form.search(params[:term]).map{ |x| x[:name]}

SELECT * FROM form_core WHERE MATCH('web m') AND sphinx_deleted = 0 LIMIT 0, 20 Sphinx Found 23 results

2
How exactly do you want your search to function? If you put in two words do you want both to be matched or just one? - Mark
@Mark yes i want both to be matched . the problem is when I add the second word the result match only the second word - ramzieus
Is name the only field you have? Or does your Form index have other fields involved? Also: which versions of Sphinx and Thinking Sphinx are you using? - pat
Hello @pat I resolve the problem by add ^ and * and remove stars ruby ThinkingSphinx.search('^' + params[:term] + '*', options) - ramzieus

2 Answers

0
votes

Try:

search_terms = params[:term].split(' ')
@suggestions = []
Form.all.each do |instance|
  next unless (search_terms - instance.name.join(' ')).empty?
  @suggestions << instance
end

This will create an array of search terms, and an array of words your form instance has for names. It then checks if every element in the search_terms array is present in the array of words present in the form's name, and adds it to @suggestions if every word is present.

0
votes

I get the best result by adding ^ and * to

ThinkingSphinx.search('^' + params[:term] + '*', options)

and it's ok