通过混合大写和小写来思考狮身人面像排序 [英] thinking sphinx ordering by mixing capitals and lower case

查看:39
本文介绍了通过混合大写和小写来思考狮身人面像排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 thinking_sphinx 进行搜索的 rails 应用程序.我的问题是返回的结果首先用大写字母和小写字母在底部排序.我想将它们混合在一起,以便 'A' 和 'a' 出现在 'B' 之前.这是我正在使用的方法:

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)

推荐答案

Maurício 的回答几乎是正确的 - 但这是用于转换 Sphinx 为字段索引的文本.排序时,您是按属性(不使用字符集表转换)进行排序的.

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).

您需要做的是将 name 的排序属性从字段中分离出来,并强制属性版本使用小写:

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

然后搜索变成:

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

这篇关于通过混合大写和小写来思考狮身人面像排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆