Skip to content

Commit

Permalink
Merge #425 #432
Browse files Browse the repository at this point in the history
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._


432: Update version for the next release (v0.23.0) r=curquiza a=meili-bot

This version introduces features released on Meilisearch v1.1.0 🎉
Check out the changelog of [Meilisearch v1.1.0](https://github.com/meilisearch/meilisearch/releases/tag/v1.1.0) for more information on the changes.

### 🚀 Enhancements

- Add a new optional argument to `add_documents_csv`. This argument allows you to customize the separator character in your `csv` file. (#429) `@brunoocasali.`
- Add `client.multi_search()` method to execute multiple search requests simultaneously with different configurations. (#430) `@brunoocasali`
    Usage example:

    ```ruby
    client.multi_search([
      { index_uid: 'books', q: 'prince' },
      { index_uid: 'movies', q: 'prince' },
    ])
    ```
  ⚠️ The `SearchQuery` was not meant to be used if the regular `$index->search()` requests (yet).

Co-authored-by: meili-bot <74670311+meili-bot@users.noreply.github.com>
Co-authored-by: Bruno Casali <brunoocasali@gmail.com>
  • Loading branch information
3 people committed Apr 3, 2023
3 parents a295b64 + ea55e0f + f1a807d commit 8395077
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 14 deletions.
14 changes: 7 additions & 7 deletions .rubocop_todo.yml
@@ -1,29 +1,29 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-07-27 15:08:15 UTC using RuboCop version 1.32.0.
# on 2023-03-30 12:31:09 UTC using RuboCop version 1.48.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Include.
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequireMFA:
Exclude:
- 'meilisearch.gemspec'

# Offense count: 46
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
# IgnoredMethods: refine
# Offense count: 45
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 626
Max: 624

# Offense count: 2
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 317
Max: 318

# Offense count: 1
# Configuration parameters: Max, CountKeywordArgs.
Expand Down
1 change: 1 addition & 0 deletions lib/meilisearch.rb
Expand Up @@ -3,6 +3,7 @@
require 'meilisearch/version'
require 'meilisearch/utils'
require 'meilisearch/http_request'
require 'meilisearch/multi_search'
require 'meilisearch/tenant_token'
require 'meilisearch/task'
require 'meilisearch/client'
Expand Down
1 change: 1 addition & 0 deletions lib/meilisearch/client.rb
Expand Up @@ -3,6 +3,7 @@
module MeiliSearch
class Client < HTTPRequest
include MeiliSearch::TenantToken
include MeiliSearch::MultiSearch

### INDEXES

Expand Down
8 changes: 6 additions & 2 deletions lib/meilisearch/index.rb
Expand Up @@ -96,9 +96,13 @@ def add_documents_ndjson(documents, primary_key = nil)
alias replace_documents_ndjson add_documents_ndjson
alias add_or_replace_documents_ndjson add_documents_ndjson

def add_documents_csv(documents, primary_key = nil)
def add_documents_csv(documents, primary_key = nil, delimiter = nil)
options = { headers: { 'Content-Type' => 'text/csv' }, convert_body?: false }
http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact, options

http_post "/indexes/#{@uid}/documents", documents, {
primaryKey: primary_key,
csvDelimiter: delimiter
}.compact, options
end
alias replace_documents_csv add_documents_csv
alias add_or_replace_documents_csv add_documents_csv
Expand Down
11 changes: 11 additions & 0 deletions lib/meilisearch/multi_search.rb
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module MeiliSearch
module MultiSearch
def multi_search(data)
body = Utils.transform_attributes(data)

http_post '/multi-search', queries: body
end
end
end
2 changes: 1 addition & 1 deletion lib/meilisearch/version.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module MeiliSearch
VERSION = '0.22.0'
VERSION = '0.23.0'

def self.qualified_version
"Meilisearch Ruby (v#{VERSION})"
Expand Down
19 changes: 19 additions & 0 deletions spec/meilisearch/client/multi_search_spec.rb
@@ -0,0 +1,19 @@
# frozen_string_literal: true

RSpec.describe 'MeiliSearch::Client - Multiple Index Search' do
before do
client.create_index('books')
client.create_index('movies')
end

it 'does a custom search with two different indexes' do
response = client.multi_search([
{ index_uid: 'books', q: 'prince' },
{ index_uid: 'movies', q: 'prince' }
])

expect(response['results'].count).to eq(2)
expect(response['results'][0]['estimatedTotalHits']).to eq(0)
expect(response['results'][1]['estimatedTotalHits']).to eq(0)
end
end
17 changes: 17 additions & 0 deletions spec/meilisearch/index/documents_spec.rb
Expand Up @@ -78,6 +78,23 @@
expect(index.documents['results'].count).to eq(3)
end

it 'adds CSV documents (as an array of documents with a different separator)' do
documents = <<~CSV
"objectRef:number"|"title:string"|"comment:string"
"1239"|"Pride and Prejudice"|"A great book"
"4569"|"Le Petit Prince"|"A french book"
"49"|"Harry Potter and the Half-Blood Prince"|"The best book"
CSV

response = index.add_documents_csv(documents, 'objectRef', '|')
index.wait_for_task(response['taskUid'])

expect(index.documents['results'].count).to eq(3)
expect(index.documents['results'][1]['objectRef']).to eq(4569)
expect(index.documents['results'][1]['title']).to eq('Le Petit Prince')
expect(index.documents['results'][1]['comment']).to eq('A french book')
end

it 'adds documents in a batch (as a array of documents)' do
task = index.add_documents_in_batches(documents, 5)
expect(task).to be_a(Array)
Expand Down
9 changes: 6 additions & 3 deletions spec/meilisearch/index/search/facets_distribution_spec.rb
Expand Up @@ -12,7 +12,8 @@
response = index.search('prinec', facets: ['genre', 'author'])
expect(response.keys).to contain_exactly(
*DEFAULT_SEARCH_RESPONSE_KEYS,
'facetDistribution'
'facetDistribution',
'facetStats'
)
expect(response['estimatedTotalHits']).to eq(2)
expect(response['facetDistribution'].keys).to contain_exactly('genre', 'author')
Expand All @@ -27,7 +28,8 @@
response = index.search('', facets: ['genre', 'author'])
expect(response.keys).to contain_exactly(
*DEFAULT_SEARCH_RESPONSE_KEYS,
'facetDistribution'
'facetDistribution',
'facetStats'
)
expect(response['estimatedTotalHits']).to eq(documents.count)
expect(response['facetDistribution'].keys).to contain_exactly('genre', 'author')
Expand All @@ -42,7 +44,8 @@
response = index.search('', facets: ['year'])
expect(response.keys).to contain_exactly(
*DEFAULT_SEARCH_RESPONSE_KEYS,
'facetDistribution'
'facetDistribution',
'facetStats'
)
expect(response['estimatedTotalHits']).to eq(documents.count)
expect(response['facetDistribution'].keys).to contain_exactly('year')
Expand Down
4 changes: 3 additions & 1 deletion spec/meilisearch/index/search/multi_params_spec.rb
Expand Up @@ -66,9 +66,11 @@
response = index.update_filterable_attributes(['genre'])
index.wait_for_task(response['taskUid'])
response = index.search('prinec', facets: ['genre'], limit: 1)

expect(response.keys).to contain_exactly(
*DEFAULT_SEARCH_RESPONSE_KEYS,
'facetDistribution'
'facetDistribution',
'facetStats'
)
expect(response['estimatedTotalHits']).to eq(2)
expect(response['hits'].count).to eq(1)
Expand Down
26 changes: 26 additions & 0 deletions spec/meilisearch/utils_spec.rb
Expand Up @@ -20,4 +20,30 @@
expect(data).to eq({ 'date' => '2012-12-21T19:05:00+00:00' })
end
end

describe '.transform_attributes' do
it 'transforms snake_case into camelCased keys' do
data = described_class.transform_attributes({
index_name: 'books',
my_UID: '123'
})

expect(data).to eq({ 'indexName' => 'books', 'myUid' => '123' })
end

it 'transforms snake_case into camel cased keys from array' do
data = described_class
.transform_attributes([
{ index_uid: 'books', q: 'prince' },
{ index_uid: 'movies', q: 'prince' }
])

expect(data).to eq(
[
{ 'indexUid' => 'books', 'q' => 'prince' },
{ 'indexUid' => 'movies', 'q' => 'prince' }
]
)
end
end
end

0 comments on commit 8395077

Please sign in to comment.