Thinking Sphinx:索引组合列并且还使用 LOWER 函数?

发布于 2024-12-13 00:16:02 字数 1291 浏览 1 评论 0原文

我读了这个问题关于使用“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幽蝶幻影 2024-12-20 00:16:02

在第一个示例(普通列引用,而不是 SQL 片段)中,尝试将 :sortable 设置为 :insensitive 而不是 true

In your first example (normal column references, not SQL snippets), try setting :sortable to :insensitive instead of true.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文