Hi Matthew
You'd actually want to do this as attributes, not fields, and you'll
need to generate some sort of custom attribute.
has 'SQL STRING', :as => :friend_ids, :type => :multi
And then you can filter using the :with option (not :conditions, that
should only be used for fields).
:with => {:friend_ids => [1, 3, 5]}
The tricky part is the SQL string, of course, because you want to
return ids separated by commas, and somehow also work the private/
public logic in there as well. I'd suggest returning 0 if the post is
*not* private, otherwise the friend ids concatenated together (look at
GROUP_CONCAT if you're using MySQL). Then, in searching, always search
for 0, plus friend ids, and it should match all public posts, as well
as any private ones by friends...
:with => {:friend_ids => [0, 1, 3, 5]}
At least, I'm thinking that's right. You know your logic better than I
do :)
Hope this helps
--
Pat
On 02/10/2009, at 3:20 PM, AccUser wrote:
>
> I am in the process of migrating the search function of our RoR web-
> application from using Ferret to Sphinx, but I am having problems with
> search conditions. Specifically, we have a condition expressed in SQL
> thus:
>
> private = 0 OR user_id IN (1,3,5)
>
> private is a boolean indicating whether a post is private or not, and
> user_id is the id of the user owning the post. (1,3,5) is taken from
> the current user's friend ids (i.e. current_user.friend_ids). So, the
> above condition states 'where a post is not private, or it belongs to
> one of my friends'. I hope that makes sense. ;-)
>
> When performing a search with Thinking Sphinx, I assumed that I could
> do the following:
>
> Post.search(params[:q], :conditions => [ %Q(private = :false OR
> user_id IN (:friend_ids)), { :false => false, :friend_ids =>
> current_user.friend_ids }])
>
> But TS only supports passing a hash of conditions, which get ANDed.
> How can I express this OR condition when searching?
>
> Cheers
> Matthew
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---