太阳黑子,Solr,order_by,编码

时间:2012-04-10 20:24:17

标签: ruby-on-rails solr sunspot

排序时我遇到了太阳黑子和插入问题的一系列问题。 主要问题是使用带有重音符号的巴西单词。例如,对于一组名称:

  • Alberto
  • Ana
  • Maria
  • 阿尔瓦罗

名称Álvaro,在调用order_by方法后始终显示在列表的末尾。

这是我的列名设置:

class Student < ActiveRecord::Base
 searchable do
   text(:name)
   text(:code)
   string :name_sort do 
     name
   end
 end

 def search(options)
    students = Student.search do 
      fulltext(options[:data])
      order_by :name_sort
    end
    students.results
 end
end

任何人都可以帮忙吗? 谢谢 路易斯

1 个答案:

答案 0 :(得分:6)

您可以在编制索引时尝试使用transliterate

class Student < ActiveRecord::Base
  searchable do
    text(:name)
    text(:code)
    string :name_sort do 
      I18n.transliterate name
    end
  end

  def search(options)
    students = Student.search do 
      fulltext(options[:data])
      order_by :name_sort
    end
    students.results
  end
end