pat / thinking-sphinx

Sphinx/Manticore plugin for ActiveRecord/Rails
http://freelancing-gods.com/thinking-sphinx
MIT License
1.63k stars 468 forks source link

Identify matched 'fields' for the search results.. #527

Closed rkgarg closed 11 years ago

rkgarg commented 11 years ago

Is there any way to Identify which fields were matched to get a specific search result.

I want to perform a search for records in a model, which is indexed for 10+ columns(fields). To show relevancy with the search results, it is required to show relevant fields with the record.

Any other suggestions to perform this.? The closest I have currently had is to perform 10(no. of fields) extra TS queries with each fields one by one to get which ones matched the results..

pat commented 11 years ago

With Thinking Sphinx v1/v2, this is possible, but in a limited fashion. There's the fieldmask ranker - but using this removes the usefulness of any other ranking algorithm:

search = ThinkingSphinx.search 'pancakes', :rank_mode => :fieldmask
search.each do |result|
  puts result.matching_fields
end

While you can use the fieldmask ranker in Thinking Sphinx v3, the matching_fields side of things has not been brought across in the rewrite (as this feature is so rarely mentioned, and the implementation from the Sphinx side of things isn't at all elegant).

rkgarg commented 11 years ago

Thnx. a lot !

I have arrived now at max. 2 queries (One for search with proper rank mode, Another search with :fieldmask and objectids from first search result)(http://sphinxsearch.com/forum/view.html?id=4077) to get matching fields for objects instead of 'n' queries; keeping the original sort intact. Would look for some better solution/alternative ..

pat commented 11 years ago

Two queries is a definite improvement. Not sure if it could be condensed down into one - it depends on how good the sorting order of the fieldmask query is, I guess?

rkgarg commented 11 years ago

Yup. Tried few tests, sort order for fieldmask doesn't looks promising.. Field weights aren't getting picked up much.. So might go ahead with above 2 query design only..