Searching and listing objects with a one-to-many relationship

2 views
Skip to first unread message

David

unread,
Sep 8, 2009, 1:03:56 PM9/8/09
to Thinking Sphinx
I have a models Article and Comments, where Articles have many
Comments. How can I get Thinking Sphinx to return the list of Articles
which have Comments containing my search term, and also return a list
of the matching Comments in that Article, without doing multiple
searches? I currently have...

For Articles:
indexes :name, :as => :article_name
indexes comments.body, :as => :comment_body

Is there a way to determine which comments the 'comments.body'
attribute matches? Any help would be appreciated. Thanks.

Pat Allan

unread,
Sep 9, 2009, 2:44:15 PM9/9/09
to thinkin...@googlegroups.com
Hi David

I'd recommend having an index on the Comment model as well, and then
doing a search across both models:
ThinkingSphinx.search 'query'

This way, you'll know exactly which comment instances match. (There's
no way to find this out from Sphinx in your current setup).

--
Pat
Reply all
Reply to author
Forward
0 new messages