thinking sphinx ordering by mixing capitals and lower case

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 02:06:47

问题


I have a rails application that is using thinking_sphinx for the searching. My problem is that the result returned is sorted with capitals first and lower case after it at the bottom. I'd like to mix them so that both 'A' and 'a' comes before 'B'. This is the method I'm using:

Company.search(query, :star => true, :page => params[:page], :per_page => 20, :order => :name, :sort_mode => :asc)

回答1:


Maurício's answer is almost on the right track - but that's for transforming the text that Sphinx indexes for fields. When you're sorting, you're doing that by attributes (which don't use the charset table transformations).

What you'll need to do is separate the sorting attribute of name out from the field, and force the attribute version to use lowercase:

indexes :name
has "LOWER(companies.name)", :as => :name_sort

And then searching becomes:

Company.search query,
  :star      => true,
  :page      => params[:page],
  :per_page  => 20,
  :order     => :name_sort,
  :sort_mode => :asc



回答2:


You have to configure sphinx to transform the input, making uppercase letters become lowercase letters. You can do this with the "charset_table" config.

And here's a complementary tutorial on how to configure it with thinking_sphinx.




回答3:


After researching many hours I got simple and elegant solution for case insensitive search. Just define your index in following way.

indexes name, as: :name_sort, sortable: :insensitive


来源:https://stackoverflow.com/questions/4713152/thinking-sphinx-ordering-by-mixing-capitals-and-lower-case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!