0
votes

Question 1

I have a model that has multiple associations, I have created at index configuration that feeds of the associated models, e.g. person is the main model, this has associations that are indexed - such as employment_positions, documents, interviews etc

So I would really want to pin down what the sphinx search has used to get the result so that I can use the excerpt on the main model or the associated model

So if I have 10 documents attached to a person, and I use a search term like "Java" I want to be able to detect what associated model has the highest ranked match / or discover what associated model was the basis for the match

Question 2

Im also puzzled a little further - when Sphinx uses excerpts, if a search is done using a field e.g. @person_job_title "java", the excerpt doesnt highlight the search word.

I suspect that others have faced the same issue, does anyone have a work around?

1

1 Answers

0
votes

With regards to your first question: Sphinx doesn't provide any information on which fields match which keywords for a search - and while Thinking Sphinx understands associations, Sphinx does not, so there's no other manner in which to gather such data. I think a better approach here may be to have separate Sphinx indices for each model, and then you can run a search across all those models and get more obvious answers on which ones match.

As for the second question: I'm not sure if this is a bug somewhere along the way, or a clear issue with Sphinx… if you're able to share your full search call and the use of excerpts in your view, that'd help with debugging.

If it happens that the field name is coming from your code (rather than being user-supplied), you could try using a separate excerpter and see if that gets better results:

# e.g. if params[:query] is just "java", and you've got params[:field]
# or similar providing "@person_job_title"
excerpter = ThinkingSphinx::Excerpter.new 'article_core', params[:query]
excerpter.excerpt! result.person.job_title