Hi Pat! I am using 3.2 version of Rails.
The first solution you wrote, worked! Thanks for your help! Best regards, Miha On Thu, Oct 29, 2015 at 10:25 AM, Pat Allan <[email protected]> wrote: > Hi Miha > > The best approach is to add an association to your Company model for just > default sites: > > has_many :default_sites, :class_name => ‘Site’, :conditions => > {:is_default => true} > > And then the attribute just changes to reference that: > > has default_sites.country_id, :facet => true > > Granted, the conditions in the association is deprecated (given you’re > using TS v2, I’m guessing you’re still on Rails 3). An alternative that is > friendlier across Rails/TS versions could be to add a WHERE clause within > the index definition: > > # use original attribute definition: > has sites.country_id, :facet => true > > # For PostgreSQL: > where “sites.is_default IS NULL OR sites.is_default = TRUE” > # Or, for MySQL: > where “sites.is_default IS NULL OR sites.is_default = 1” > > This is not tested though, and it’s worth double-checking to confirm the > right results are being returned. My thinking is to have the NULL check > because some companies may not have any default sites, and you still want > those companies being part of the Sphinx data. There may be a better way of > doing this… > > Hope this is helpful. > > — > Pat > > On 29 Oct 2015, at 7:59 am, Treeninja <[email protected]> wrote: > > Hi! > > I am using TS 2 and would like to set some conditions on certain fields in > the index. > > A *company* has many *sites*, which contain *country_id*. So the index > inside Company model is: > > define_index do > indexes :name, :sortable => true > indexes :description > > has sites.country_id, :facet => true > end > > The sites table has *is_default* boolean value and I would like to only > index sites that has *is_default = true*. > > How can I do that in the index? > > Kind regards, Miha > > > > -- > You received this message because you are subscribed to the Google Groups > "Thinking Sphinx" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/thinking-sphinx. > For more options, visit https://groups.google.com/d/optout. > > > -- > You received this message because you are subscribed to the Google Groups > "Thinking Sphinx" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/thinking-sphinx. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/thinking-sphinx. For more options, visit https://groups.google.com/d/optout.
