I have an attachments table that has multiple values (via polymorphic assoc). I'd like to be able to search for multiple values (like an AND in SQL) via thinking-sphinx.
For example:
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
My FieldValue model has one field (value), so using the above index definition, I could do something like:
Attachment.search :conditions => { :field_values => ["*5100*", "1"] }, :with => { :field_ids => [23, 24] }
But this doesn't technically do what I'm hoping for. The field_values should match the field_ids (similar to a select * from attachments where (field_value.id = 23 and field_value.value like '*5100*) and (field_value.id = 23 and field_value.value = '1')
(i know there are joins missing above :P)
Is it possible to do a search similar to this?