Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
spec/meilisearch/index/search/show_ranking_score_details.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |