【发布时间】:2012-01-11 18:38:08
【问题描述】:
我有一个包含多个值的附件表(通过多态关联)。我希望能够通过thinking-sphinx 搜索多个值(如SQL 中的AND)。
例如:
class FieldValue < ActiveRecord::Base
belongs_to :customized, :polymorphic => true
end
class Attachment < ActiveRecord::Base
has_many :field_values, :as => :customized, :dependent => :destroy
define_index do
has field_values.field_id, :as => :field_ids, :type => :multi
indexes field_values.value, :as => :field_values, :type => :multi
set_property :enable_star => 1
set_property :min_infix_len => 3
end
end
我的 FieldValue 模型有一个字段(值),因此使用上面的索引定义,我可以执行以下操作:
Attachment.search :conditions => { :field_values => ["*5100*", "1"] }, :with => { :field_ids => [23, 24] }
但这在技术上并没有达到我的期望。 field_values 应该与 field_ids 匹配(类似于 select * from attachments where (field_value.id = 23 and field_value.value like '*5100*) and (field_value.id = 23 and field_value.value = '1')
(我知道上面缺少连接:P)
是否可以进行类似的搜索?
【问题讨论】:
标签: ruby-on-rails-3 thinking-sphinx polymorphic-associations