Thinking Sphinx:索引组合列并且还使用 LOWER 函数?
我读了这个问题关于使用“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(...)”函数?或者,我的实际问题。我如何对此进行索引,以便我能够按人员字段对项目进行排序并使其不区分大小写?
I read this question about using the "LOWER" function to help with sorting mixed case columns. I would like to do something similar but with a little more complex attribute. First, I have a basic many-to-many relationship:
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
I'm using TS to index projects:
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
This indexes fine, but then I discovered the gotcha when upper and lower case letters are used in people's names. I tried replacing the call with following:
has ["LOWER(people.first_name)", "LOWER(people.middle_name)", "LOWER(people.last_name)"], :as => :person, :type => :string
But I kept getting error when rebuilding the index:
ERROR: index 'project_core': sql_range_query: Unknown column 'people.first_name' in 'field list' (DSN=mysql://...).
How can I implement the "LOWER(...)" function? Or, my actual question. How can I index this so I'll be able to sort projects by the person field and have it be case-insensitive?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在第一个示例(普通列引用,而不是 SQL 片段)中,尝试将
:sortable
设置为:insensitive
而不是true
。In your first example (normal column references, not SQL snippets), try setting
:sortable
to:insensitive
instead oftrue
.