Skip to content

Commit

Permalink
Merge branch 'main' into feat/ranking_score_threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
curquiza authored Jul 6, 2024
2 parents e7ef719 + 5d4e3ed commit add3200
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 12 deletions.
14 changes: 14 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -657,3 +657,17 @@ search_parameter_reference_ranking_score_threshold_1: |-
client.index('INDEX_NAME').search('badman', {
rankingScoreThreshold: 0.2
})
search_parameter_reference_distinct_1: |-
client.index('INDEX_NAME').search('QUERY TERMS', {
distinct: 'ATTRIBUTE_A'
})
distinct_attribute_guide_filterable_1: |-
client.index('products').update_filterable_attributes([
'product_id',
'sku',
'url'
])
distinct_attribute_guide_distinct_parameter_1: |-
client.index('products').search('white shirt', {
distinct: 'sku'
})
4 changes: 2 additions & 2 deletions spec/meilisearch/index/search/attributes_to_highlight_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
response = index.search('the', attributes_to_highlight: ['title'])
expect(response).to be_a(Hash)
expect(response.keys).to contain_exactly(*DEFAULT_SEARCH_RESPONSE_KEYS)
expect(response['hits'].count).to eq(3)
expect(response['hits'].count).to eq(4)
expect(response['hits'].first).to have_key('_formatted')
expect(response['hits'].first['_formatted']['title']).to eq('<em>The</em> Hobbit')
end
Expand All @@ -16,7 +16,7 @@
response = index.search('', attributes_to_highlight: ['*'])
expect(response).to be_a(Hash)
expect(response.keys).to contain_exactly(*DEFAULT_SEARCH_RESPONSE_KEYS)
expect(response['hits'].count).to eq(7)
expect(response['hits'].count).to eq(8)
expect(response['hits'].first).to have_key('_formatted')
end

Expand Down
6 changes: 3 additions & 3 deletions spec/meilisearch/index/search/attributes_to_retrieve_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
response = index.search('the', attributes_to_retrieve: ['title'])
expect(response).to be_a(Hash)
expect(response.keys).to contain_exactly(*DEFAULT_SEARCH_RESPONSE_KEYS)
expect(response['hits'].count).to eq(3)
expect(response['hits'].count).to eq(4)
expect(response['hits'].first).to have_key('title')
expect(response['hits'].first).not_to have_key('objectId')
expect(response['hits'].first).not_to have_key('genre')
Expand All @@ -17,7 +17,7 @@
response = index.search('the', attributes_to_retrieve: ['title', 'genre'])
expect(response).to be_a(Hash)
expect(response.keys).to contain_exactly(*DEFAULT_SEARCH_RESPONSE_KEYS)
expect(response['hits'].count).to eq(3)
expect(response['hits'].count).to eq(4)
expect(response['hits'].first).to have_key('title')
expect(response['hits'].first).not_to have_key('objectId')
expect(response['hits'].first).to have_key('genre')
Expand All @@ -27,7 +27,7 @@
response = index.search('the', attributes_to_retrieve: ['*'])
expect(response).to be_a(Hash)
expect(response.keys).to contain_exactly(*DEFAULT_SEARCH_RESPONSE_KEYS)
expect(response['hits'].count).to eq(3)
expect(response['hits'].count).to eq(4)
expect(response['hits'].first).to have_key('objectId')
expect(response['hits'].first).to have_key('title')
expect(response['hits'].first).to have_key('genre')
Expand Down
19 changes: 19 additions & 0 deletions spec/meilisearch/index/search/distinct_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

RSpec.describe 'MeiliSearch::Index - Distinct search' do
include_context 'search books with genre'

before do
index.update_filterable_attributes(['genre']).await
end

it 'does a search without distinct' do
response = index.search('harry potter')
expect(response['hits'].count).to eq(2)
end

it 'does a custom search with distinct' do
response = index.search('harry potter', { distinct: 'genre' })
expect(response['hits'].count).to eq(1)
end
end
2 changes: 1 addition & 1 deletion spec/meilisearch/index/search/q_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
response = index.search('coco "harry"')
expect(response).to be_a(Hash)
expect(response.keys).to contain_exactly(*DEFAULT_SEARCH_RESPONSE_KEYS)
expect(response['hits'].count).to eq(1)
expect(response['hits'].count).to eq(2)
expect(response['hits'].first['objectId']).to eq(4)
expect(response['hits'].first).not_to have_key('_formatted')
end
Expand Down
13 changes: 7 additions & 6 deletions spec/support/books_contexts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
let(:index) { client.index('books') }
let(:documents) do
[
{ objectId: 123, title: 'Pride and Prejudice', genre: 'romance' },
{ objectId: 456, title: 'Le Petit Prince', genre: 'adventure' },
{ objectId: 1, title: 'Alice In Wonderland', genre: 'adventure' },
{ objectId: 2, title: 'Le Rouge et le Noir', genre: 'romance' },
{ objectId: 1344, title: 'The Hobbit', genre: 'adventure' },
{ objectId: 4, title: 'Harry Potter and the Half-Blood Prince', genre: 'fantasy' },
{ objectId: 123, title: 'Pride and Prejudice', genre: 'romance' },
{ objectId: 456, title: 'Le Petit Prince', genre: 'adventure' },
{ objectId: 1, title: 'Alice In Wonderland', genre: 'adventure' },
{ objectId: 2, title: 'Le Rouge et le Noir', genre: 'romance' },
{ objectId: 1344, title: 'The Hobbit', genre: 'adventure' },
{ objectId: 4, title: 'Harry Potter and the Half-Blood Prince', genre: 'fantasy' },
{ objectId: 7, title: 'Harry Potter and the Chamber of Secrets', genre: 'fantasy' },
{ objectId: 42, title: 'The Hitchhiker\'s Guide to the Galaxy' }
]
end
Expand Down

0 comments on commit add3200

Please sign in to comment.