Skip to content

Commit 660a315

Browse files
authored
Merge branch 'main' into meili-bot/bump-version
2 parents f1a807d + 2bb24e2 commit 660a315

File tree

11 files changed

+140
-81
lines changed

11 files changed

+140
-81
lines changed

.code-samples.meilisearch.yaml

Lines changed: 42 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ update_faceting_settings_1: |-
6969
index('books').update_faceting({ max_values_per_facet: 2 })
7070
reset_faceting_settings_1: |-
7171
index('books').reset_faceting
72-
settings_guide_faceting_1: |-
73-
index('books').update_faceting({ max_values_per_facet: 5 })
74-
settings_guide_pagination_1: |-
75-
index('books').update_pagination({ max_total_hits: 50 })
7672
get_one_index_1: |-
7773
client.fetch_index('movies')
7874
list_all_indexes_1: |-
@@ -281,6 +277,10 @@ filtering_guide_3: |-
281277
client.index('movies').search('Planet of the Apes', {
282278
filter: 'rating >= 3 AND (NOT director = "Tim Burton")'
283279
})
280+
filtering_guide_nested_1: |-
281+
client.index('movies_ratings').search('thriller', {
282+
filter: 'rating.users >= 90'
283+
})
284284
search_parameter_guide_query_1: |-
285285
client.index('movies').search('shifu')
286286
search_parameter_guide_offset_1: |-
@@ -327,60 +327,6 @@ search_parameter_guide_matching_strategy_2: |-
327327
client.index('movies').search('big fat liar', {
328328
matching_strategy: 'all'
329329
})
330-
settings_guide_synonyms_1: |-
331-
client.index('tops').update_settings({
332-
synonyms: {
333-
sweater: ['jumper'],
334-
jumper: ['sweater']
335-
}
336-
})
337-
settings_guide_stop_words_1: |-
338-
client.index('movies').update_settings({
339-
stop_words: [
340-
'the',
341-
'a',
342-
'an'
343-
]
344-
})
345-
settings_guide_ranking_rules_1: |-
346-
client.index('movies').update_settings({
347-
ranking_rules: [
348-
'words',
349-
'typo',
350-
'proximity',
351-
'attribute',
352-
'sort',
353-
'exactness',
354-
'release_date:asc',
355-
'rank:desc'
356-
]
357-
})
358-
settings_guide_distinct_1: |-
359-
client.index('jackets').update_distinct_attribute('product_id')
360-
settings_guide_searchable_1: |-
361-
client.index('movies').update_settings({
362-
searchable_attributes: [
363-
'title',
364-
'overview',
365-
'genres'
366-
]
367-
})
368-
settings_guide_displayed_1: |-
369-
client.index('movies').update_settings({
370-
displayed_attributes: [
371-
'title',
372-
'overview',
373-
'genres',
374-
'release_date'
375-
]
376-
})
377-
settings_guide_sortable_1: |-
378-
client.index('books').update_settings({
379-
sortable_attributes: [
380-
'price',
381-
'author'
382-
]
383-
})
384330
add_movies_json_1: |-
385331
require 'json'
386332
@@ -389,8 +335,8 @@ add_movies_json_1: |-
389335
client.index('movies').add_documents(movies)
390336
documents_guide_add_movie_1: |-
391337
client.index('movies').add_documents([{
392-
"movie_id": "123sq178",
393-
"title": "Amelie Poulain"
338+
movie_id: '123sq178',
339+
title: 'Amelie Poulain'
394340
}])
395341
getting_started_add_documents_md: |-
396342
```bash
@@ -416,11 +362,33 @@ getting_started_search_md: |-
416362
```
417363
418364
[About this SDK](https://www.github.com/meilisearch/meilisearch-ruby)
419-
faceted_search_update_settings_1: |-
365+
filtering_update_settings_1: |-
420366
client.index('movies').update_filterable_attributes([
421367
'director',
422368
'genres'
423369
])
370+
faceted_search_1: |-
371+
client.index('books').search('classic', {
372+
facets: ['genres', 'rating', 'language']
373+
})
374+
faceted_search_2: |-
375+
client.multi_search([
376+
{
377+
indexUid: 'books',
378+
facets: ['language', 'genres', 'author', 'format'],
379+
filter: [['language = English', 'language = French'], ['genres = Fiction']]
380+
},
381+
{
382+
indexUid: 'books',
383+
facets: ['language'],
384+
filter: [['genres = Fiction']]
385+
},
386+
{
387+
indexUid: 'books',
388+
facets: ['genres'],
389+
filter: [['language = English', 'language = French']]
390+
}
391+
])
424392
faceted_search_filter_1: |-
425393
client.index('movies').search('thriller', {
426394
filter: [['genres = Horror', 'genres = Mystery'], 'director = "Jordan Peele"']
@@ -431,6 +399,8 @@ faceted_search_walkthrough_filter_1: |-
431399
client.index('movies').search('thriller', {
432400
filter: [['genres = Horror', 'genres = Mystery'], 'director = "Jordan Peele"']
433401
})
402+
faceted_search_update_settings_1: |-
403+
client.index('books').update_filterable_attributes(['genres', 'rating', 'language'])
434404
post_dump_1: |-
435405
client.create_dump
436406
phrase_search_1: |-
@@ -457,6 +427,8 @@ update_sortable_attributes_1: |-
457427
'price',
458428
'author'
459429
])
430+
sorting_guide_sort_nested_1: |-
431+
client.index('books').search('science fiction', { sort: ['rating.users:asc'] })
460432
reset_sortable_attributes_1: |-
461433
client.index('books').reset_sortable_attributes
462434
search_parameter_guide_sort_1: |-
@@ -467,6 +439,8 @@ geosearch_guide_filter_usage_1: |-
467439
client.index('restaurants').search('', { filter: '_geoRadius(45.472735, 9.184019, 2000)' })
468440
geosearch_guide_filter_usage_2: |-
469441
client.index('restaurants').search('', { filter: '_geoRadius(45.472735, 9.184019, 2000) AND type = pizza' })
442+
geosearch_guide_filter_usage_3: |-
443+
client.index('restaurants').search('', { filter: ['_geoBoundingBox([45.494181, 9.179175], [45.449484, 9.214024])'] })
470444
geosearch_guide_sort_settings_1: |-
471445
client.index('restaurants').update_sortable_attributes(['_geo'])
472446
geosearch_guide_sort_usage_1: |-
@@ -622,10 +596,10 @@ typo_tolerance_guide_4: |-
622596
two_typos: 10
623597
}
624598
})
625-
settings_guide_typo_tolerance_1: |-
626-
index('books').update_typo_tolerance({
627-
min_word_size_for_typos: {
628-
two_typos: 12
629-
},
630-
disable_on_attributes: ['title']
631-
})
599+
multi_search_1: |-
600+
client.multi_search([
601+
{ index_uid: 'books', q: 'prince' },
602+
{ index_uid: 'movies', q: 'pooh', limit: 5 }
603+
{ index_uid: 'movies', q: 'nemo', limit: 5 }
604+
{ index_uid: 'movie_ratings', q: 'us' }
605+
])

.rubocop_todo.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2022-07-27 15:08:15 UTC using RuboCop version 1.32.0.
3+
# on 2023-03-30 12:31:09 UTC using RuboCop version 1.48.1.
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

99
# Offense count: 1
1010
# This cop supports safe autocorrection (--autocorrect).
11-
# Configuration parameters: Include.
11+
# Configuration parameters: Severity, Include.
1212
# Include: **/*.gemspec
1313
Gemspec/RequireMFA:
1414
Exclude:
1515
- 'meilisearch.gemspec'
1616

17-
# Offense count: 46
18-
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
19-
# IgnoredMethods: refine
17+
# Offense count: 45
18+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
19+
# AllowedMethods: refine
2020
Metrics/BlockLength:
21-
Max: 626
21+
Max: 624
2222

2323
# Offense count: 2
2424
# Configuration parameters: CountComments, CountAsOne.
2525
Metrics/ClassLength:
26-
Max: 317
26+
Max: 318
2727

2828
# Offense count: 1
2929
# Configuration parameters: Max, CountKeywordArgs.

lib/meilisearch.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'meilisearch/version'
44
require 'meilisearch/utils'
55
require 'meilisearch/http_request'
6+
require 'meilisearch/multi_search'
67
require 'meilisearch/tenant_token'
78
require 'meilisearch/task'
89
require 'meilisearch/client'

lib/meilisearch/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module MeiliSearch
44
class Client < HTTPRequest
55
include MeiliSearch::TenantToken
6+
include MeiliSearch::MultiSearch
67

78
### INDEXES
89

lib/meilisearch/index.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,13 @@ def add_documents_ndjson(documents, primary_key = nil)
9696
alias replace_documents_ndjson add_documents_ndjson
9797
alias add_or_replace_documents_ndjson add_documents_ndjson
9898

99-
def add_documents_csv(documents, primary_key = nil)
99+
def add_documents_csv(documents, primary_key = nil, delimiter = nil)
100100
options = { headers: { 'Content-Type' => 'text/csv' }, convert_body?: false }
101-
http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact, options
101+
102+
http_post "/indexes/#{@uid}/documents", documents, {
103+
primaryKey: primary_key,
104+
csvDelimiter: delimiter
105+
}.compact, options
102106
end
103107
alias replace_documents_csv add_documents_csv
104108
alias add_or_replace_documents_csv add_documents_csv

lib/meilisearch/multi_search.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module MeiliSearch
4+
module MultiSearch
5+
def multi_search(data)
6+
body = Utils.transform_attributes(data)
7+
8+
http_post '/multi-search', queries: body
9+
end
10+
end
11+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe 'MeiliSearch::Client - Multiple Index Search' do
4+
before do
5+
client.create_index('books')
6+
task = client.create_index('movies')
7+
client.wait_for_task(task['taskUid'])
8+
end
9+
10+
it 'does a custom search with two different indexes' do
11+
response = client.multi_search([
12+
{ index_uid: 'books', q: 'prince' },
13+
{ index_uid: 'movies', q: 'prince' }
14+
])
15+
16+
expect(response['results'].count).to eq(2)
17+
expect(response['results'][0]['estimatedTotalHits']).to eq(0)
18+
expect(response['results'][1]['estimatedTotalHits']).to eq(0)
19+
end
20+
end

spec/meilisearch/index/documents_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,23 @@
7878
expect(index.documents['results'].count).to eq(3)
7979
end
8080

81+
it 'adds CSV documents (as an array of documents with a different separator)' do
82+
documents = <<~CSV
83+
"objectRef:number"|"title:string"|"comment:string"
84+
"1239"|"Pride and Prejudice"|"A great book"
85+
"4569"|"Le Petit Prince"|"A french book"
86+
"49"|"Harry Potter and the Half-Blood Prince"|"The best book"
87+
CSV
88+
89+
response = index.add_documents_csv(documents, 'objectRef', '|')
90+
index.wait_for_task(response['taskUid'])
91+
92+
expect(index.documents['results'].count).to eq(3)
93+
expect(index.documents['results'][1]['objectRef']).to eq(4569)
94+
expect(index.documents['results'][1]['title']).to eq('Le Petit Prince')
95+
expect(index.documents['results'][1]['comment']).to eq('A french book')
96+
end
97+
8198
it 'adds documents in a batch (as a array of documents)' do
8299
task = index.add_documents_in_batches(documents, 5)
83100
expect(task).to be_a(Array)

spec/meilisearch/index/search/facets_distribution_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
response = index.search('prinec', facets: ['genre', 'author'])
1313
expect(response.keys).to contain_exactly(
1414
*DEFAULT_SEARCH_RESPONSE_KEYS,
15-
'facetDistribution'
15+
'facetDistribution',
16+
'facetStats'
1617
)
1718
expect(response['estimatedTotalHits']).to eq(2)
1819
expect(response['facetDistribution'].keys).to contain_exactly('genre', 'author')
@@ -27,7 +28,8 @@
2728
response = index.search('', facets: ['genre', 'author'])
2829
expect(response.keys).to contain_exactly(
2930
*DEFAULT_SEARCH_RESPONSE_KEYS,
30-
'facetDistribution'
31+
'facetDistribution',
32+
'facetStats'
3133
)
3234
expect(response['estimatedTotalHits']).to eq(documents.count)
3335
expect(response['facetDistribution'].keys).to contain_exactly('genre', 'author')
@@ -42,7 +44,8 @@
4244
response = index.search('', facets: ['year'])
4345
expect(response.keys).to contain_exactly(
4446
*DEFAULT_SEARCH_RESPONSE_KEYS,
45-
'facetDistribution'
47+
'facetDistribution',
48+
'facetStats'
4649
)
4750
expect(response['estimatedTotalHits']).to eq(documents.count)
4851
expect(response['facetDistribution'].keys).to contain_exactly('year')

spec/meilisearch/index/search/multi_params_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@
6666
response = index.update_filterable_attributes(['genre'])
6767
index.wait_for_task(response['taskUid'])
6868
response = index.search('prinec', facets: ['genre'], limit: 1)
69+
6970
expect(response.keys).to contain_exactly(
7071
*DEFAULT_SEARCH_RESPONSE_KEYS,
71-
'facetDistribution'
72+
'facetDistribution',
73+
'facetStats'
7274
)
7375
expect(response['estimatedTotalHits']).to eq(2)
7476
expect(response['hits'].count).to eq(1)

0 commit comments

Comments
 (0)