Hi Robin
I think the best approach here is to create an 'active' attribute which
represents that state. Here's an example that works with MySQL - some adapting
is probably required for PostgreSQL:
has "IF((COUNT(DISTINCT domains.id) + COUNT(DISTINCT contracts.id)) > 0, 1,
0)",
:as => :active,
:type => :boolean
If in the future you're not referring to the domains or contracts associations
elsewhere in your index definition, then you'll need to tell TS to include
those joins manually:
join contacts
join domains
And then in your scope:
sphinx_scope(:active) do
{:with => {:active => true}}
end
Let me know how this goes.
Cheers
--
Pat
On 29/03/2011, at 9:36 PM, robin wrote:
> Hi folks,
>
> i want to search for customers with are "active".
> a customer is active if he owns about one or more domains OR one or
> more contracts.
>
> A customer has many domains.
> A customer has many contracts.
>
> I want to set a scope for ignoring the nominal members.
> But i am not sure how to build my index for setting the scope without
> sql statements.
>
> define_index do
> ...
> indexes domains(:name), :as => :domains
> indexes contracts(:contract_no), :as => contracts
> has domains(:customer_id), :as => :customer_domain_ids
> has contracts(:customer_id), :as => :customer_contract_ids
> end
>
>
> sphinx_scope(:active) do
> {...}
> end
>
> Customer.active.search(...)
>
> Is it possible to build this?
> Can someone help me with this?
>
> --
> 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.