我阅读this question关于使用“LOWER”函数来帮助排序混合大小写列。我想做类似的事情,但有一个更复杂的属性。首先,我有一个基本的多对多关系:
class Project < ActiveRecord::Base
has_many :project_people
has_many :people, :through => :project_people
end
class ProjectPerson < ActiveRecord::Base
belongs_to :project
belongs_to :person
end
class Person < ActiveRecord::Base
has_many :project_people
has_many :projects, :through => :project_people
end
我正在使用TS来索引项目:
class Project
define_index
indexes name, :sortable => true
indexes [people.first_name, people.last_name], :as => :person, :sortable => true
has created_at, category_id
set_property :delta => true
end
end
这个索引很好,但后来当人们的名字中使用了大写和小写字母时,我发现了这个问题。我尝试用以下内容替换呼叫:
has ["LOWER(people.first_name)", "LOWER(people.middle_name)", "LOWER(people.last_name)"], :as => :person, :type => :string
但是在重建索引时我一直遇到错误:
ERROR: index 'project_core': sql_range_query: Unknown column 'people.first_name' in 'field list' (DSN=mysql://...).
如何实现“LOWER(...)”功能?或者,我的实际问题。我如何对此进行索引,以便我能够按人员字段对项目进行排序并使其不区分大小写?
答案 0 :(得分:2)
在您的第一个示例(普通列引用,而不是SQL代码段)中,尝试将:sortable
设置为:insensitive
而不是true
。