Skip to content

Commit

Permalink
Merge #476
Browse files Browse the repository at this point in the history
476:  [v1.3] [EXPERIMENTAL] Display ranking details at search #460  r=brunoocasali a=andre-m-dev

# Pull Request

## Related issue
Fixes #460 

## What does this PR do?
- Add handling of display ranking details at search

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!


Co-authored-by: Andre <>
  • Loading branch information
meili-bors[bot] committed Aug 18, 2023
2 parents 0e0ae32 + 0fd1f1e commit 11f0edb
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.md
Expand Up @@ -207,6 +207,54 @@ JSON output:
}
```

#### Display ranking details at search

JSON output:

```json
{
"hits": [
{
"id": 15359,
"title": "Wonder Woman",
"_rankingScoreDetails": {
"words": {
"order": 0,
"matchingWords": 2,
"maxMatchingWords": 2,
"score": 1.0
},
"typo": {
"order": 1,
"typoCount": 0,
"maxTypoCount": 2,
"score": 1.0
},
"proximity": {
"order": 2,
"score": 1.0
},
"attribute": {
"order": 3,
"attributeRankingOrderScore": 0.8181818181818182,
"queryWordDistanceScore": 1.0,
"score": 0.8181818181818182
},
"exactness": {
"order": 4,
"matchType": "exactMatch",
"score": 1.0
}
}
}
]
}
```

You can enable it by querying PATCH /experimental-features with { "scoreDetails": true }

This feature is only available with Meilisearch v1.3 and newer (optional).

## 🤖 Compatibility with Meilisearch

This package guarantees compatibility with [version v1.x of Meilisearch](https://github.com/meilisearch/meilisearch/releases/latest), but some features may not be present. Please check the [issues](https://github.com/meilisearch/meilisearch-ruby/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22+label%3Aenhancement) for more info.
Expand Down
34 changes: 34 additions & 0 deletions spec/meilisearch/index/search/show_ranking_score_details.rb
@@ -0,0 +1,34 @@
# frozen_string_literal: true

RSpec.describe 'MeiliSearch::Index - Search with ranking score details' do
include_context 'search books with genre'

it 'experimental feature scoreDetails is not enabled so an error is raised' do
enable_score_details(false)

expect do
index.search('hobbit', { show_ranking_score_details: true })
end.to raise_error(MeiliSearch::ApiError)
end

it 'shows the ranking score details when showRankingScoreDetails is true' do
enable_score_details(true)

response = index.search('hobbit', { show_ranking_score_details: true })
expect(response['hits'][0]).to have_key('_rankingScoreDetails')
end

it 'hides the ranking score details when showRankingScoreDetails is false' do
enable_score_details(false)

response = index.search('hobbit', { show_ranking_score_details: false })
expect(response['hits'][0]).not_to have_key('_rankingScoreDetails')
end

it 'hides the ranking score details when showRankingScoreDetails is not set' do
enable_score_details(false)

response = index.search('hobbit')
expect(response['hits'][0]).not_to have_key('_rankingScoreDetails')
end
end
19 changes: 19 additions & 0 deletions spec/support/experimental_feature_helpers.rb
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require 'net/http'
require 'json'

module ExperimentalFeatureHelpers
def enable_score_details(toggle)
uri = URI("http://#{ENV.fetch('MEILISEARCH_URL', 'localhost')}")
uri.path = '/experimental-features'
uri.port = ENV.fetch('MEILISEARCH_PORT', '7700')

req = Net::HTTP::Patch.new(uri)
req.body = { scoreDetails: toggle }.to_json
req.content_type = 'application/json'
req['Authorization'] = "Bearer #{MASTER_KEY}"

Net::HTTP.start(uri.hostname, uri.port) { |http| http.request(req) }
end
end

0 comments on commit 11f0edb

Please sign in to comment.