Skip to content

Commit 0b52793

Browse files
authored
Merge branch 'main' into fix-matching-strategy-spec
2 parents bb41c1c + 1532c27 commit 0b52793

File tree

5 files changed

+133
-3
lines changed

5 files changed

+133
-3
lines changed

.code-samples.meilisearch.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,12 +603,16 @@ multi_search_1: |-
603603
{ index_uid: 'movies', q: 'nemo', limit: 5 }
604604
{ index_uid: 'movie_ratings', q: 'us' }
605605
])
606+
facet_search_1: |-
607+
client.index('books').facet_search('genres', 'fiction', filter: 'rating > 3')
606608
facet_search_2: |-
607609
client.index('books').update_faceting(
608610
sort_facet_values_by: {
609611
genres: 'count'
610612
}
611613
)
614+
facet_search_3: |-
615+
client.index('books').facet_search('genres', 'c')
612616
get_dictionary_1: |-
613617
client.index('books').dictionary
614618
update_dictionary_1: |-

.rubocop_todo.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-10-10 14:01:22 UTC using RuboCop version 1.50.2.
3+
# on 2023-10-11 10:43:57 UTC using RuboCop version 1.50.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 52
9+
# Offense count: 55
1010
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
1111
# AllowedMethods: refine
1212
Metrics/BlockLength:
@@ -15,7 +15,7 @@ Metrics/BlockLength:
1515
# Offense count: 2
1616
# Configuration parameters: CountComments, CountAsOne.
1717
Metrics/ClassLength:
18-
Max: 358
18+
Max: 363
1919

2020
# Offense count: 1
2121
# Configuration parameters: Max, CountKeywordArgs.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030

3131
**Meilisearch** is an open-source search engine. [Learn more about Meilisearch.](https://github.com/meilisearch/meilisearch)
3232

33+
---
34+
35+
### 🔥 On November 2nd, we are hosting our first-ever live demo and product updates for [Meilisearch Cloud](https://www.meilisearch.com/cloud?utm_campaign=oss&utm_source=github&utm_medium=meilisearch). Make sure to [register here](https://us06web.zoom.us/meeting/register/tZMlc-mqrjIsH912-HTRe-AaT-pp41bDe81a#/registration) and bring your questions for live Q&A!
36+
37+
---
38+
3339
## Table of Contents <!-- omit in toc -->
3440

3541
- [📖 Documentation](#-documentation)

lib/meilisearch/index.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,15 @@ def search(query, options = {})
234234
response
235235
end
236236

237+
### FACET SEARCH
238+
239+
def facet_search(name, query = '', **options)
240+
options.merge!(facet_name: name, facet_query: query)
241+
options = Utils.transform_attributes(options)
242+
243+
http_post("/indexes/#{@uid}/facet-search", options)
244+
end
245+
237246
### TASKS
238247

239248
def task_endpoint
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe 'MeiliSearch::Index - Facet search' do
4+
include_context 'search books with author, genre, year'
5+
6+
before do
7+
response = index.update_filterable_attributes(['genre', 'year', 'author'])
8+
index.wait_for_task(response['taskUid'])
9+
end
10+
11+
it 'requires facet name parameter' do
12+
expect { index.facet_search }.to raise_error ArgumentError
13+
end
14+
15+
context 'without query parameter' do
16+
let(:results) { index.facet_search 'genre' }
17+
18+
it 'returns all genres' do
19+
expect(results).to include(
20+
'facetHits' => a_collection_including(
21+
a_hash_including('value' => 'fantasy'),
22+
a_hash_including('value' => 'adventure'),
23+
a_hash_including('value' => 'romance')
24+
)
25+
)
26+
end
27+
28+
it 'returns all genre counts' do
29+
expect(results).to include(
30+
'facetHits' => a_collection_including(
31+
a_hash_including('count' => 3),
32+
a_hash_including('count' => 3),
33+
a_hash_including('count' => 2)
34+
)
35+
)
36+
end
37+
38+
it 'filters correctly' do
39+
results = index.facet_search 'genre', filter: 'year < 1940'
40+
41+
expect(results['facetHits']).to contain_exactly(
42+
{
43+
'value' => 'adventure',
44+
'count' => 2
45+
},
46+
{
47+
'value' => 'romance',
48+
'count' => 2
49+
}
50+
)
51+
end
52+
end
53+
54+
context 'with facet_query argument' do
55+
let(:results) { index.facet_search 'genre', 'fan' }
56+
57+
it 'returns only matching genres' do
58+
expect(results).to include(
59+
'facetHits' => a_collection_containing_exactly(
60+
'value' => 'fantasy',
61+
'count' => 3
62+
)
63+
)
64+
end
65+
66+
it 'filters correctly' do
67+
results = index.facet_search 'genre', 'fantasy', filter: 'year < 2006'
68+
69+
expect(results['facetHits']).to contain_exactly(
70+
'value' => 'fantasy',
71+
'count' => 2
72+
)
73+
end
74+
end
75+
76+
context 'with q parameter' do
77+
it 'applies matching_strategy "all"' do
78+
results = index.facet_search 'author', 'J. K. Rowling', q: 'Potter Stories', matching_strategy: 'all'
79+
80+
expect(results['facetHits']).to be_empty
81+
end
82+
83+
it 'applies matching_strategy "last"' do
84+
results = index.facet_search 'author', 'J. K. Rowling', q: 'Potter Stories', matching_strategy: 'last'
85+
86+
expect(results).to include(
87+
'facetHits' => a_collection_containing_exactly(
88+
'value' => 'J. K. Rowling',
89+
'count' => 2
90+
)
91+
)
92+
end
93+
94+
it 'applies filter parameter' do
95+
results = index.facet_search 'author', 'J. K. Rowling', q: 'Potter', filter: 'year < 2007'
96+
97+
expect(results).to include(
98+
'facetHits' => a_collection_containing_exactly(
99+
'value' => 'J. K. Rowling',
100+
'count' => 1
101+
)
102+
)
103+
end
104+
105+
it 'applies attributes_to_search_on parameter' do
106+
results = index.facet_search 'author', 'J. K. Rowling', q: 'Potter', attributes_to_search_on: ['year']
107+
108+
expect(results['facetHits']).to be_empty
109+
end
110+
end
111+
end

0 commit comments

Comments
 (0)