Hi Jan

I'm not sure how Ferret works, but ActiveRecord's named scopes are SQL  
only, and Sphinx has its own query structure, so you can't mix the two  
reliably.

People have requested a sphinx_scope addition, but I've not had time  
to implement it - what AR does is pretty tricky, I think. It will stay  
on my feature list though... so one day, you might be able to do what  
you want in a very similar fashion.

The other issue is the query you want to do is a bit too complex for  
Sphinx - ANDs and ORs. You could do it all using fields, but using an  
attribute for the user_id would be faster if just filtering by user  
ids...

Or, what you could do... I'm guessing IF function syntax.

define_index do
   # ...
   has "IF(visibility = 'public', 0, user_id)", :as  
=> :visible_user_id, :type => :integer
   # ...
end

Event.search "query", :with => {:visible_user_id => [0, user.id]}

Yes, it's not quite as neat as a scope, but it should work.

Cheers

-- 
Pat

On 03/02/2009, at 5:16 AM, jeanmartin wrote:

>
> Hi,
>
> coming from AAF I would like to use (complex) boolean filters/
> conditions.
> To be more specific I want to get items visible only to the current
> user, in AR this is done with a named_scope (simplyfied):
>
> class Event
>  named_scope :visible_to, lambda {|user|  :conditions => ['visibility
> = 'public' OR (visibility = 'private' AND user_id = ?)', user.id]  }
> end
> Event.visible_to(current_user).all ...
> With AAF the following works:
> Event.visible_to(current_user).find_with_ferret('query' ...)
>
> It doesn't work with TS. I can't add :conditions => ... with this kind
> of boolean filter. And if I try this:
>
> Event.visible_to(current_user).search 'query'
>
> I get errors because the returned array has the length of the result
> list returned by TS (without AR filtering) although I can see in my
> logs that the AR conditions have been used. There are simply NIL
> objects in the returned list. This is really useless especially if I
> want to use will_paginate.
>
> - Jan
>
> >


--~--~---------~--~----~------------~-------~--~----~
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