Grouping results by model type

16 views
Skip to first unread message

mhodgson

unread,
May 11, 2008, 3:14:14 PM5/11/08
to Thinking Sphinx
First post! Cool!

First off, thanks to Pat for all his work on Thinking Sphinx and
Riddle.

I'm new to Sphinx and I'm in the process of switching my app over from
Ferret (sick of all the corrupt index troubles). I think I've got most
of it figured out, but I'm hoping someone could provide a some quick
tips for multi-model search and grouping results by model type.
Currently I have a full site search that searches through 7 models
with 7 different ferret calls. This is slow and I'm hoping thinking
sphinx has a better solution for this.

Also, when the results are returned, I need to group them by model
type for display (a user result is displayed differently than a blog
entry reslut, etc.)

Any help (or even a point to the right documentation or source code)
would be awesome.

Thanks!

-Matt

Pat Allan

unread,
May 12, 2008, 12:00:38 AM5/12/08
to thinkin...@googlegroups.com
Hi Matt

On 12/05/2008, at 5:14 AM, mhodgson wrote:

> I'm new to Sphinx and I'm in the process of switching my app over from
> Ferret (sick of all the corrupt index troubles). I think I've got most
> of it figured out, but I'm hoping someone could provide a some quick
> tips for multi-model search and grouping results by model type.
> Currently I have a full site search that searches through 7 models
> with 7 different ferret calls. This is slow and I'm hoping thinking
> sphinx has a better solution for this.

To search across all indexed models:
ThinkingSphinx::Search.search("something")

> Also, when the results are returned, I need to group them by model
> type for display (a user result is displayed differently than a blog
> entry reslut, etc.)

To group by each model, try something like the following:
ThinkingSphinx::Search.search(
"something",
:sort_mode => :extended,
:sort_by => "class_crc ASC, @relevance DESC"
)

class_crc is the inbuilt attribute which is used to figure out which
model a search result is for.

However - with Sphinx's pagination, this means the first page may be
all one model, so it might be that you still need to make 7 calls to
Sphinx. Not sure how expensive, time-wise, that'll be though - I've
never found searches to be that slow, but the corresponding Model#find
calls may be, depending on whether you're adding :include calls.

Cheers

--
Pat

Reply all
Reply to author
Forward
0 new messages