Hi guys

I'll fix TS to handle symbols for grouping args - it is more intuitive  
that way. Good to know you've got things figured out though (and yes,  
grouping docs - and much of the other documentation - needs plenty of  
work).

Cheers

-- 
Pat

On 20/02/2009, at 2:35 AM, Xavi Arnaus wrote:

>
> Yeah! right!
>
> The parameter :group_by expects an string which is the symbol defined
> as the alias of the field.
>
> So, finally, the good one related to the define_index above is the
> following:
>
> Post.search params[:q], :group_by =>
> 'related_topic_id', :group_function => :attr
>
> Now I have to order the results, but it is out of this topic ;)
>
> Thank you very much Josh.
>
> On Feb 19, 3:53 pm, Josh <[email protected]> wrote:
>> You might be right, I'm noticing a few differences.  I'm calling
>> search with a string rather than a symbol, so you might try that, but
>> you'll need the alias you assigned instead of the actual column name:
>>
>> Post.search params[:q], :group_by
>> => 'related_topic_id', :group_function => :attr
>>
>> Also, in my index definition I define the ID in the local table  
>> rather
>> than the related table, but I can't imagine that would make a
>> difference.  But, if you're still stuck, you could try changing it:
>>
>>   has topic_id, :as => :related_topic_id
>>
>> Let us know if that helps,
>>
>> - Josh
>>
>> On Feb 19, 9:21 am, Xavi Arnaus <[email protected]> wrote:
>>
>>> I've tried your solution and throws me the same error than without
>>> the :group_function :
>>
>>> Post.search params[:q], :group_by
>>> => :related_topic_id, :group_function => :attr
>>
>>> => NoMethodError: undefined method `bytesize'
>>> for :related_topic_id:Symbol
>>
>>> I think that somehow the :group_by parameter expects something
>>> different than the symbol... If I put the field 'topic_id' as string
>>> it runs without crashing but nothing is returned... I'm really
>>> confused about the diference between each :group_* parameter and  
>>> what
>>> they expect as a value.
>>
>>> Have you get any results doing the grouping like you said? Can you
>>> post your define_index?
>>
>>> Thank you.
>>
>>> On Feb 19, 2:37 pm, Josh <[email protected]> wrote:
>>
>>>> Xavi,
>>
>>>> I'm doing something very similar, and it took me some trial and  
>>>> error
>>>> to figure it out as well.  I think you need the group_function
>>>> parameter, but it needs to describe the type of grouping you  
>>>> want, not
>>>> the field.  Try this:
>>
>>>> @posts = Post.search params[:q], :group_by
>>>> => :related_topic_id, :group_function => :attr
>>
>>>> Hopefully that will give you what you're looking for.  If so,  
>>>> you'll
>>>> have to decide which match you want in the case where there are
>>>> multiple posts with the same topic ID.  For that you'll need a
>>>> combination of the :order and :group_clause params.  I found it a
>>>> little confusing - it seems that :order will control which of your
>>>> grouped items is used, and :group_clause becomes the overall sort  
>>>> for
>>>> all your results.
>>
>>>> Good luck,
>>
>>>> - Josh
>>
>>>> On Feb 19, 4:37 am, Xavi Arnaus <[email protected]> wrote:
>>
>>>>> Hi all
>>
>>>>> I'm trying to implement a searching with grouped results as  
>>>>> follows:
>>
>>>>> It is a one-to-many relation between Topics and Posts, where each
>>>>> Topic has the title and many Posts, which each one has its own  
>>>>> text.
>>
>>>>> I'm trying to make the search by Posts so in the results page I  
>>>>> can
>>>>> point to the Topic but placing the navigator to the Post where the
>>>>> match appears. Everything works fine until here:
>>
>>>>> in the Post model:
>>
>>>>> belongs_to :topic
>>>>> define_index do
>>>>>     # fields
>>>>>     indexes topic.title, :as => :related_topic_title
>>>>>     indexes text
>>>>>     indexes created_at, :sorteable => true
>>
>>>>>     # attributes
>>>>>     has created_at
>>>>>     has topic(:id), :as => :related_topic_id       # field is  
>>>>> topic_id
>>>>> in Posts
>>>>>   end
>>
>>>>> in the controller, within the search action:
>>
>>>>> @posts = Post.search params[:q]
>>
>>>>> Ok, now the problem:
>>>>> If in a Topic there's more than one Post where there is a match, I
>>>>> recieve (obviously) all the posts. But as I want to show the  
>>>>> results
>>>>> by Topic, I need to group all posts by Topic. I tried a lot of
>>>>> combinations:
>>
>>>>> @posts = Post.search params[:q], :group_by => :related_topic_id
>>>>> [ERROR: undefined method 'bytesize' for symbol]
>>>>> @posts = Post.search params[:q], :group_funcion  
>>>>> => :related_topic_id
>>>>> [ERROR: can't convert nil to Integer]
>>>>> @posts = Post.search params[:q], :group_by => 'topic_id' [FAILS:  
>>>>> no
>>>>> matches!!]
>>>>> @posts = Post.search params[:q], :group_funcion
>>>>> => :related_topic_id, :group_clause => "created_at DESC" [FAILS:  
>>>>> no
>>>>> grouping is done]
>>
>>>>> So, as documentation is a little poor in grouping, can anyone  
>>>>> help me
>>>>> on this? How can I group all Posts in a Topic? Ideally, pointing  
>>>>> to
>>>>> the first Post of that matches in a Topic is enough...
>>
>>>>> Keep in mind I'm a newbe on Sphinx
>>>>> Thank you for your time.
> >


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