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