thinking-sphinx icon indicating copy to clipboard operation
thinking-sphinx copied to clipboard

Identify matched 'fields' for the search results..

Open rkgarg opened this issue 13 years ago • 4 comments

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

rkgarg avatar May 20 '13 13:05 rkgarg

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).

pat avatar May 20 '13 13:05 pat

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

rkgarg avatar May 22 '13 13:05 rkgarg

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?

pat avatar May 23 '13 00:05 pat

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

rkgarg avatar May 26 '13 14:05 rkgarg