Hi Jamal

When grouping search results, Sphinx adds the special attributes @count and 
@group. In your case, @count is the number of user_ids in a group, and @group 
is the user_id for each group.
http://www.sphinxsearch.com/docs/manual-0.9.9.html#clustering

So, you might be able to filter by @count:

  Page.search 'sphinx',
    :group_by       => 'user_id',
    :group_function => :attr,
    :group_clause   => '@count DESC',
    :with           => {'@count' => 2..1024}

Sphinx doesn't have the concept of greater/less-than - so you'll need to use a 
really big number at the top end of the range.

Give this a spin, let us know how it goes.

Cheers

-- 
Pat

On 13/12/2010, at 10:15 AM, Jamal wrote:

> Pat Allan
> 
> Can user_score be a name of group_by
> 
> Let's say I have this table.
> 
> id | user_id | title
> --------------------
> 1 1 sphinx
> 6 1 sphinx
> 2 5 sphinx
> 3 5 sphinx
> 4 4 server
> 5 1 great
> --------------------
> 
> I want to group_by(user_id) and say at least 2 times occurred in the
> user_id for that
> specific title.
> 
> Maybe something like this in Rails:
> pages = Page.search('sphinx', :group_by => 'user_id', :group_function
> => :attr,
> :group_clause => "@users desc")
> 
> But I want something like this:
> group_by(user_id) if @at_least_found_to_times
> 
> 
> 
> In the end I need this result.
> 
> user_ids | users | title
> ----------------------------
> 1,5 2 sphinx
> ----------------------------
> 
> Can I use your method?
> 
> 
> On Dec 10, 12:09 am, Pat Allan <[email protected]> wrote:
>> Hi Stefan
>> 
>> I think you should just be able to put that complex logic into an attribute, 
>> and use that for sorting:
>> 
>>   has "if( user_score ... )", :as => :custom_score, :type => :integer
>> 
>> And then in searching, assuming you've got qualified as an attribute, and 
>> :sortable on user_name (or an explicit attribute based on that column):
>> 
>>   Model.search 'foo',
>>     :order => 'qualified DESC, custom_score ASC, user_name ASC'
>> 
>> Let us know if that doesn't work.
>> 
>> Cheers
>> 
>> --
>> Pat
>> 
>> On 10/12/2010, at 1:58 AM, Stefan wrote:
>> 
>>> Hello everyone!
>> 
>>> I am trying to "translate" a mysql query to sphinx. The complicated
>>> part is the ORDER BY clause. It is as follows:
>> 
>>> ORDER BY qualified DESC,
>>>              if( user_score, if(( user_score=0 AND (user_title_en!=''
>>> OR user_title!='')),-1,0),0),
>>>              if( user_pref, if( user_privilegies=0 , -1, 0), 0),
>>>              if( qualified, to_days(exam_date), -
>>> (to_days(signup_date))),
>>>              user_name
>> 
>>> Please, could anyone tell me if it is possible to sort results like
>>> this in sphinx. I am searching for answers almost a week now and the
>>> only think I found is information about "SPH_SORT_EXPR mode". But I
>>> can't understand exactly how it works so I can chain all the "IF"
>>> statements.
>> 
>>> 10x in advance!!
>> 
>>> --
>>> 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 
>>> athttp://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.
> 

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