I may be misunderstanding. And also, I suck at breaking at 80
chars. Anyway what I was thinking (and this is probably miles
away from reality) is that AR just calls #to_s on symbol args,
like:

has :friendships[:friend_id] , :as => :friend_ids

Which probably doesn't work at all, demonstrating how AR
is just a black box to me. Anyway I was just admiring how
some combo of #to_s and #join were being used to parse
the arguments to #has, #has_many, etc, so you could just
replace a complex bit of SQL with a nested hash. I dunno.

In  all fairness, I am half asleep.

On Feb 14, 2009, at 7:34 PM, Pat Allan wrote:

>
> Um, not sure what you mean about the symbol and AR...?
> but I just remembered - the manual 'has' call doesn't set up the
> relationships in the query Sphinx runs, so you'll need another field
> or attribute that uses the friendship relationship, ie:
>
> has friendships.friend_id, :as => :friend_ids
>
> Cheers
>
> --  
> Pat
>
> On 15/02/2009, at 12:30 PM, Alex Caudill wrote:
>
>>
>> Nice trick Pat. I had no idea that ActiveRecord just takes the symbol
>> and converts it into a string when you specify a relationship, I
>> thought
>> there was all kinds of kung-fu involved. That's awesome, I'll
>> definitely
>> find a few places to put that technique to use.
>>
>> On Feb 14, 2009, at 7:23 PM, Pat Allan wrote:
>>
>>>
>>> But, if you want pagination to work straight out of the box, let's
>>> put
>>> named_scope aside for a moment...
>>>
>>> what you need is a custom attribute for your filter... (I'm guessing
>>> table and column names, and using mysql functions)
>>>
>>> has "IF(private = 1, '0', GROUP_CONCAT(friendships.friend_id
>>> SEPARATOR
>>> ','))", :as => :user_limit, :type => :multi
>>>
>>> And then:
>>>
>>> # This will match 0 for public users, and the user id for private
>>> users
>>> User.search "whatever", :with => {:user_limit => [0, user.id]}
>>>
>>> Give that a shot.
>>>
>>> Cheers
>>>
>>> --  
>>> Pat
>>>
>>> On 15/02/2009, at 11:51 AM, Alex Caudill wrote:
>>>
>>>>
>>>> Hey Pascal,
>>>>
>>>> You could use a named_scope, e.g.,
>>>> User.publicly_visible.search(conditions), but then you'd have to
>>>> manually do pagination on the results, like
>>>> User.publicly_visible.search(conditions).paginate(:per_page =>
>>>> 10, :page => 1) - there may be performance problems with this, I
>>>> don't
>>>> know if
>>>> ActiveRecord lazily loads the rest of the User table columns or
>>>> what,
>>>> but I'm using a similar approach with chained named scopes and it
>>>> seems to perform admirably so far.
>>>>
>>>> Hope this helps!
>>>>
>>>> On Feb 14, 2009, at 2:37 PM, pascal wrote:
>>>>
>>>>>
>>>>> Hi
>>>>>
>>>>>
>>>>> I want to convert a search system (just SQL queries) to sphinx/TS
>>>>> and
>>>>> have some troubles, and i hope someone can help me.
>>>>>
>>>>> The aim is to search users by first/lastname and a description  
>>>>> text
>>>>> field. A user has many friends. Depending on the users privacy
>>>>> settings his visibility in the search by first/lastname is
>>>>> restricted
>>>>> to his friends or to everyone. Search by description is never
>>>>> restricted.
>>>>>
>>>>> Maybe an example can clear things up:
>>>>> User "Santa Claus" has "search privacy" turned on. If you are a
>>>>> friend
>>>>> you can still find him by the search "Santa". If you aren't a
>>>>> friend,
>>>>> then you can't find him with "Santa" but with "Christmas" because
>>>>> "Christmas" appears on a his description text.
>>>>>
>>>>> So it something like "find users where search terms matches AND
>>>>> (privacy off OR privacy on AND his ID is in in the list of my
>>>>> friends
>>>>> ids)".
>>>>>
>>>>> I got simple search up and running real quick but is Sphinx/TS the
>>>>> right tool for this? How would i go about this?
>>>>>
>>>>>
>>>>> Thanks for your help!
>>>>>
>>>>> Pascal
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>
>>>>
>>>>
>>>>>
>>>
>>>
>>>>
>>
>>
>>>
>
>
> >


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