-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
496: Implement facet_search r=brunoocasali a=ellnix # Pull Request ## Related issue Fixes #462 ## 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? Co-authored-by: ellnix <103502144+ellnix@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
127 additions
and
3 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
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
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
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,111 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe 'MeiliSearch::Index - Facet search' do | ||
include_context 'search books with author, genre, year' | ||
|
||
before do | ||
response = index.update_filterable_attributes(['genre', 'year', 'author']) | ||
index.wait_for_task(response['taskUid']) | ||
end | ||
|
||
it 'requires facet name parameter' do | ||
expect { index.facet_search }.to raise_error ArgumentError | ||
end | ||
|
||
context 'without query parameter' do | ||
let(:results) { index.facet_search 'genre' } | ||
|
||
it 'returns all genres' do | ||
expect(results).to include( | ||
'facetHits' => a_collection_including( | ||
a_hash_including('value' => 'fantasy'), | ||
a_hash_including('value' => 'adventure'), | ||
a_hash_including('value' => 'romance') | ||
) | ||
) | ||
end | ||
|
||
it 'returns all genre counts' do | ||
expect(results).to include( | ||
'facetHits' => a_collection_including( | ||
a_hash_including('count' => 3), | ||
a_hash_including('count' => 3), | ||
a_hash_including('count' => 2) | ||
) | ||
) | ||
end | ||
|
||
it 'filters correctly' do | ||
results = index.facet_search 'genre', filter: 'year < 1940' | ||
|
||
expect(results['facetHits']).to contain_exactly( | ||
{ | ||
'value' => 'adventure', | ||
'count' => 2 | ||
}, | ||
{ | ||
'value' => 'romance', | ||
'count' => 2 | ||
} | ||
) | ||
end | ||
end | ||
|
||
context 'with facet_query argument' do | ||
let(:results) { index.facet_search 'genre', 'fan' } | ||
|
||
it 'returns only matching genres' do | ||
expect(results).to include( | ||
'facetHits' => a_collection_containing_exactly( | ||
'value' => 'fantasy', | ||
'count' => 3 | ||
) | ||
) | ||
end | ||
|
||
it 'filters correctly' do | ||
results = index.facet_search 'genre', 'fantasy', filter: 'year < 2006' | ||
|
||
expect(results['facetHits']).to contain_exactly( | ||
'value' => 'fantasy', | ||
'count' => 2 | ||
) | ||
end | ||
end | ||
|
||
context 'with q parameter' do | ||
it 'applies matching_strategy "all"' do | ||
results = index.facet_search 'author', 'J. K. Rowling', q: 'Potter Stories', matching_strategy: 'all' | ||
|
||
expect(results['facetHits']).to be_empty | ||
end | ||
|
||
it 'applies matching_strategy "last"' do | ||
results = index.facet_search 'author', 'J. K. Rowling', q: 'Potter Stories', matching_strategy: 'last' | ||
|
||
expect(results).to include( | ||
'facetHits' => a_collection_containing_exactly( | ||
'value' => 'J. K. Rowling', | ||
'count' => 2 | ||
) | ||
) | ||
end | ||
|
||
it 'applies filter parameter' do | ||
results = index.facet_search 'author', 'J. K. Rowling', q: 'Potter', filter: 'year < 2007' | ||
|
||
expect(results).to include( | ||
'facetHits' => a_collection_containing_exactly( | ||
'value' => 'J. K. Rowling', | ||
'count' => 1 | ||
) | ||
) | ||
end | ||
|
||
it 'applies attributes_to_search_on parameter' do | ||
results = index.facet_search 'author', 'J. K. Rowling', q: 'Potter', attributes_to_search_on: ['year'] | ||
|
||
expect(results['facetHits']).to be_empty | ||
end | ||
end | ||
end |