Skip to content

Commit c904eaa

Browse files
meili-bors[bot]meili-botbrunoocasali
authored
Merge #425
425: Changes related to the next Meilisearch release (v1.1.0) r=curquiza a=meili-bot Related to this issue: meilisearch/integration-guides#251 This PR: - gathers the changes related to the next Meilisearch release (v1.1.0) so that this package is ready when the official release is out. - should pass the tests against the [latest pre-release of Meilisearch](https://github.com/meilisearch/meilisearch/releases). - might eventually contain test failures until the Meilisearch v1.1.0 is out. ⚠️ This PR should NOT be merged until the next release of Meilisearch (v1.1.0) is out. _This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/main/resources/pre-release-week.md) purpose._ Co-authored-by: meili-bot <[email protected]> Co-authored-by: Bruno Casali <[email protected]>
2 parents a295b64 + ea55e0f commit c904eaa

10 files changed

+97
-13
lines changed

.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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe 'MeiliSearch::Client - Multiple Index Search' do
4+
before do
5+
client.create_index('books')
6+
client.create_index('movies')
7+
end
8+
9+
it 'does a custom search with two different indexes' do
10+
response = client.multi_search([
11+
{ index_uid: 'books', q: 'prince' },
12+
{ index_uid: 'movies', q: 'prince' }
13+
])
14+
15+
expect(response['results'].count).to eq(2)
16+
expect(response['results'][0]['estimatedTotalHits']).to eq(0)
17+
expect(response['results'][1]['estimatedTotalHits']).to eq(0)
18+
end
19+
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)

spec/meilisearch/utils_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,30 @@
2020
expect(data).to eq({ 'date' => '2012-12-21T19:05:00+00:00' })
2121
end
2222
end
23+
24+
describe '.transform_attributes' do
25+
it 'transforms snake_case into camelCased keys' do
26+
data = described_class.transform_attributes({
27+
index_name: 'books',
28+
my_UID: '123'
29+
})
30+
31+
expect(data).to eq({ 'indexName' => 'books', 'myUid' => '123' })
32+
end
33+
34+
it 'transforms snake_case into camel cased keys from array' do
35+
data = described_class
36+
.transform_attributes([
37+
{ index_uid: 'books', q: 'prince' },
38+
{ index_uid: 'movies', q: 'prince' }
39+
])
40+
41+
expect(data).to eq(
42+
[
43+
{ 'indexUid' => 'books', 'q' => 'prince' },
44+
{ 'indexUid' => 'movies', 'q' => 'prince' }
45+
]
46+
)
47+
end
48+
end
2349
end

0 commit comments

Comments
 (0)