Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added display hits ranking scores #466

Merged
merged 6 commits into from Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .code-samples.meilisearch.yaml
Expand Up @@ -335,6 +335,10 @@ search_parameter_guide_matching_strategy_2: |-
client.index('movies').search('big fat liar', {
matching_strategy: 'all'
})
search_parameter_guide_show_ranking_score_1: |-
client.index('movies').search('winter feast', {
show_ranking_score: true
})
add_movies_json_1: |-
require 'json'

Expand Down
2 changes: 2 additions & 0 deletions lib/meilisearch/index.rb
Expand Up @@ -220,6 +220,8 @@ def delete_all_documents!

### SEARCH

# options: A Hash
# showRankingScore - To see the ranking scores for returned documents
andre-m-dev marked this conversation as resolved.
Show resolved Hide resolved
def search(query, options = {})
parsed_options = Utils.transform_attributes({ q: query.to_s }.merge(options.compact))

Expand Down
20 changes: 20 additions & 0 deletions spec/meilisearch/index/search/show_ranking_score_spec.rb
@@ -0,0 +1,20 @@
# frozen_string_literal: true

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

it 'shows the ranking score when showRankingScore is true' do
response = index.search('hobbit', { showRankingScore: true })
andre-m-dev marked this conversation as resolved.
Show resolved Hide resolved
expect(response['hits'][0]).to have_key('_rankingScore')
end

it 'hides the ranking score when showRankingScore is false' do
response = index.search('hobbit', { showRankingScore: false })
andre-m-dev marked this conversation as resolved.
Show resolved Hide resolved
expect(response['hits'][0]).not_to have_key('_rankingScore')
end

it 'hides the ranking score when showRankingScore is not set' do
response = index.search('hobbit')
expect(response['hits'][0]).not_to have_key('_rankingScore')
end
end