具有思想狮身人面像的功能自动完成

时间:2019-07-02 09:54:47

标签: ruby-on-rails ruby sphinx 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]}

选择*从form_core中匹配('web m')和sphinx_deleted = 0 LIMIT 0,20   Sphinx找到23个结果

2 个答案:

答案 0 :(得分:0)

尝试:

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中。

答案 1 :(得分:0)

通过在

中添加^和*可获得最佳结果
ThinkingSphinx.search('^' + params[:term] + '*', options)

没关系