【问题标题】:Thinking Sphinx: Index combined columns and also use the LOWER function?Thinking Sphinx:索引组合列并且还使用 LOWER 函数?
【发布时间】:2011-10-28 17:44:28
【问题描述】:

我阅读了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(...)”功能?或者,我的实际问题。我怎样才能索引它,以便我能够按人员字段对项目进行排序并使其不区分大小写?

【问题讨论】:

    标签: ruby-on-rails sorting sphinx thinking-sphinx


    【解决方案1】:

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

    【讨论】:

    • 谢谢,很好的答案。我想知道为什么我没有在文档中找到这个答案:(
    • 两个原因:文档并不完美(但当然欢迎使用补丁!),而且:此功能目前不在 TS v3 中(仅在 v1/v2 中)。我不太确定为什么它没有成功(如果 Sphinx 本身规范化字符串属性,则可能不需要),但同样欢迎测试和/或补丁。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多