自动完成思考狮身人面像
autocomplete with thinking sphinx
当我搜索第二个词时,结果不匹配
例如 'web '
结果
["WEB MEDIA ","CREATIV WEB ","WEB SERVICES TECHNOLOGIES","iDURAR WEB AGENCY","WEB CREATION","DEV WEB SOLUTION","BIG WEB DZ","AMANA SITE WEB"]
但是 'web m'
结果
["VOISINAGE PC","DELTA SOFT","MMCOMPUTING ETS","MICROPROZ","PORTIDEE","LATICODE","CYBER WEB SERVICES","SIEGE SOCIAL","EL DALIL YALAOUI ET CIE - SIEGE COMMERCIAL""IMA"]
我尝试了网上所有的例子
ruby
@suggestions = Form.search(params[:term]).map{ |x| x[:name]}
SELECT * 从 form_core
WHERE MATCH('web m') AND sphinx_deleted
= 0 LIMIT 0, 20
斯芬克斯找到 23 个结果
尝试:
search_terms = params[:term].split(' ')
@suggestions = []
Form.all.each do |instance|
next unless (search_terms - instance.name.join(' ')).empty?
@suggestions << instance
end
这将创建一组搜索词,以及一组您的表单实例中包含的名称单词。然后它检查 search_terms 数组中的每个元素是否存在于表单名称中存在的单词数组中,如果每个单词都存在,则将其添加到 @suggestions
。
我通过将 ^ 和 * 添加到
得到了最好的结果
ThinkingSphinx.search('^' + params[:term] + '*', options)
没关系
当我搜索第二个词时,结果不匹配 例如 'web ' 结果
["WEB MEDIA ","CREATIV WEB ","WEB SERVICES TECHNOLOGIES","iDURAR WEB AGENCY","WEB CREATION","DEV WEB SOLUTION","BIG WEB DZ","AMANA SITE WEB"]
但是 'web m' 结果
["VOISINAGE PC","DELTA SOFT","MMCOMPUTING ETS","MICROPROZ","PORTIDEE","LATICODE","CYBER WEB SERVICES","SIEGE SOCIAL","EL DALIL YALAOUI ET CIE - SIEGE COMMERCIAL""IMA"]
我尝试了网上所有的例子
ruby
@suggestions = Form.search(params[:term]).map{ |x| x[:name]}
SELECT * 从 form_core
WHERE MATCH('web m') AND sphinx_deleted
= 0 LIMIT 0, 20
斯芬克斯找到 23 个结果
尝试:
search_terms = params[:term].split(' ')
@suggestions = []
Form.all.each do |instance|
next unless (search_terms - instance.name.join(' ')).empty?
@suggestions << instance
end
这将创建一组搜索词,以及一组您的表单实例中包含的名称单词。然后它检查 search_terms 数组中的每个元素是否存在于表单名称中存在的单词数组中,如果每个单词都存在,则将其添加到 @suggestions
。
我通过将 ^ 和 * 添加到
得到了最好的结果ThinkingSphinx.search('^' + params[:term] + '*', options)
没关系