Hi Alex

I think the best approach is to index both your Question model and  
your Answer model, with only their own fields, and then search across  
both:
   ThinkingSphinx::Search.search params[:query]

And then maybe have different logic depending on each result.

Cheers

-- 
Pat

On 29/04/2009, at 11:37 AM, Alejandro Riera wrote:

>
> Hello,
>
> I have a doubt about the results of the searchs with TS.
> I've tried to search it but I have found nothing (mainly because I
> dont know what to search).
>
> My case is really easy. In my application I have two models: Questions
> and Answers.
> Questions has_many answers and, of course, Answer belongs_to question.
> Both models have a body attribute, which hold the relevant text.
>
> So I told TS to index the body of questions and, as answers are
> related to questions, I told TS to also index them. I made it like
> this:
>
> class Question < ActiveRecord::Base
> [....]
>  define_index do
>    indexes body
>    indexes answers.body, :as => :answers
>  end
> end
>
>
> The thing is that when I make something like: Question.search params
> [:query], there might be some matches that corresponds to the answers
> but not to questions, and, in this case, I would like to show the user
> the answer that matched rather than the question related to it.
>
> So the question is, do you know if there is a way to obtain directly
> the answer that matched the search query?
>
> I know I can always look inside the set of answers belonging to the
> question, but I find it to be kinda messy.
>
> Well, thanks a lot in adavance : )
>
> Alex.
>
> >


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