Sphinx's filters aren't that complex, unfortunately...

I think the best approach (though keep in mind I don't know the context of all 
this) is to create a second attribute, using a SQL snippet that returns 1 if 
you have kosher products, and 0 otherwise... not quite sure what that SQL would 
look like, but generally the syntax would be:

  has "SQL GOES HERE", :as => :has_kosher_products, :type => :boolean

-- 
Pat

On 12/05/2010, at 3:29 PM, Nick Kezhaya wrote:

> Oh! I didn't know about sphinx_attributes().
> 
> It appears that product_kosher_ids is properly returning a large array
> of integers of the ids; however, because some of the products in each
> store aren't kosher, and some are, the first int at the beginning of
> this array is 0, along with the rest of them.
> 
> How do I go about determining if product_kosher_ids returns more than
> 0?
> 
> On May 11, 10:04 pm, Pat Allan <[email protected]> wrote:
>> Hi Nick
>> 
>> I'm not sure what the issue is, so can you run the following in 
>> script/console:
>> 
>>   Store.search(:conditions => {:product_names => 'chicken'}).collect { 
>> |store|
>>     store.sphinx_attributes['product_kosher_ids']
>>   }
>> 
>> This will get us the details on what Sphinx is storing for that attribute.
>> 
>> --
>> Pat
>> 
>> On 12/05/2010, at 11:57 AM, Nick Kezhaya wrote:
>> 
>> 
>> 
>> 
>> 
>>> class Store < ActiveRecord::Base
>>>  has_many :product_stores
>>>  has_many :products, :through => :product_stores
>> 
>>>  define_index do
>>>    indexes :name
>>>    indexes [products(:name), products(:brand)], :as => :product_names
>> 
>>>    has products(:kosher_id), :as => :product_kosher_ids
>>>  end
>>> end
>> 
>>> Oddly:
>> 
>>> Store.search :conditions => { :product_names => 'chicken' }
>> 
>>> ^ This returns stores properly, but:
>> 
>>> Store.search :conditions => { :product_names => 'chicken' }, :without
>>> => { :product_kosher_ids => 0 }
>> 
>>> ^ Returns an empty array. I've no idea why.
>> 
>>> I know the data is present in the database.
>> 
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "Thinking Sphinx" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to 
>>> [email protected].
>>> For more options, visit this group 
>>> athttp://groups.google.com/group/thinking-sphinx?hl=en.
>> 
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Thinking Sphinx" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to 
>> [email protected].
>> For more options, visit this group 
>> athttp://groups.google.com/group/thinking-sphinx?hl=en.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/thinking-sphinx?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to