Skip to content

Commit bb41c1c

Browse files
authored
Merge branch 'main' into fix-matching-strategy-spec
2 parents 648eae2 + fb6bbc0 commit bb41c1c

File tree

9 files changed

+197
-55
lines changed

9 files changed

+197
-55
lines changed

.code-samples.meilisearch.yaml

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ delete_documents_by_filter_1: |-
1414
get_documents_1: |-
1515
client.index('movies').get_documents(limit: 2, filter: 'genres = action')
1616
getting_started_faceting: |-
17-
client.index('movies').update_faceting(max_values_per_facet: 2)
17+
client.index('movies').update_faceting({
18+
max_values_per_facet: 2,
19+
sort_facet_values_by: {
20+
genres: 'count'
21+
}
22+
})
1823
getting_started_pagination: |-
1924
client.index('movies').update_pagination(max_total_hits: 500)
2025
synonyms_guide_1: |-
@@ -74,9 +79,15 @@ update_pagination_settings_1: |-
7479
reset_pagination_settings_1: |-
7580
index('books').reset_pagination
7681
get_faceting_settings_1: |-
77-
index('books').faceting
82+
client.index('books').faceting
7883
update_faceting_settings_1: |-
79-
index('books').update_faceting({ max_values_per_facet: 2 })
84+
client.index('books').update_faceting({
85+
max_values_per_facet: 2,
86+
sort_facet_values_by: {
87+
'*': 'alpha',
88+
genres: 'count'
89+
}
90+
})
8091
reset_faceting_settings_1: |-
8192
index('books').reset_faceting
8293
get_one_index_1: |-
@@ -311,7 +322,7 @@ search_parameter_guide_crop_1: |-
311322
search_parameter_guide_crop_marker_1: |-
312323
client.index('movies').search('shifu', {
313324
attributes_to_crop: ['overview'],
314-
crop_marker: "[…]"
325+
crop_marker: '[…]'
315326
})
316327
search_parameter_guide_highlight_1: |-
317328
client.index('movies').search('winter feast', {
@@ -350,11 +361,6 @@ add_movies_json_1: |-
350361
movies_json = File.read('movies.json')
351362
movies = JSON.parse(movies_json)
352363
client.index('movies').add_documents(movies)
353-
documents_guide_add_movie_1: |-
354-
client.index('movies').add_documents([{
355-
movie_id: '123sq178',
356-
title: 'Amelie Poulain'
357-
}])
358364
getting_started_add_documents_md: |-
359365
```bash
360366
$ bundle add meilisearch
@@ -388,26 +394,6 @@ faceted_search_1: |-
388394
client.index('books').search('classic', {
389395
facets: ['genres', 'rating', 'language']
390396
})
391-
faceted_search_2: |-
392-
client.multi_search([
393-
{
394-
indexUid: 'books',
395-
facets: ['language', 'genres', 'author', 'format'],
396-
filter: [['language = English', 'language = French'], ['genres = Fiction']]
397-
},
398-
{
399-
indexUid: 'books',
400-
facets: ['language'],
401-
filter: [['genres = Fiction']]
402-
},
403-
{
404-
indexUid: 'books',
405-
facets: ['genres'],
406-
filter: [['language = English', 'language = French']]
407-
}
408-
])
409-
faceted_search_facets_1: |-
410-
client.index('movies').search('Batman', { facets: ['genres'] })
411397
faceted_search_walkthrough_filter_1: |-
412398
client.index('movies').search('thriller', {
413399
filter: [['genres = Horror', 'genres = Mystery'], 'director = "Jordan Peele"']
@@ -549,9 +535,6 @@ getting_started_update_displayed_attributes: |-
549535
'overview',
550536
'poster'
551537
])
552-
getting_started_communicating_with_a_protected_instance: |-
553-
client = MeiliSearch::Client.new('http://localhost:7700', 'apiKey')
554-
client.index('movies').search
555538
getting_started_add_meteorites: |-
556539
file = File.read('meteorites.json')
557540
json = JSON.parse(file)
@@ -609,10 +592,38 @@ typo_tolerance_guide_4: |-
609592
two_typos: 10
610593
}
611594
})
595+
search_parameter_guide_facet_stats_1: |-
596+
client.index('movie_ratings').search('Batman', {
597+
facets: ['genres', 'rating']
598+
})
612599
multi_search_1: |-
613600
client.multi_search([
614601
{ index_uid: 'books', q: 'prince' },
615602
{ index_uid: 'movies', q: 'pooh', limit: 5 }
616603
{ index_uid: 'movies', q: 'nemo', limit: 5 }
617604
{ index_uid: 'movie_ratings', q: 'us' }
618605
])
606+
facet_search_2: |-
607+
client.index('books').update_faceting(
608+
sort_facet_values_by: {
609+
genres: 'count'
610+
}
611+
)
612+
get_dictionary_1: |-
613+
client.index('books').dictionary
614+
update_dictionary_1: |-
615+
client.index('books').update_dictionary(['J. R. R.', 'W. E. B.'])
616+
reset_dictionary_1: |-
617+
client.index('books').reset_dictionary
618+
get_separator_tokens_1: |-
619+
client.index('articles').separator_tokens
620+
update_separator_tokens_1: |-
621+
client.index('articles').update_separator_tokens(['|', '…'])
622+
reset_separator_tokens_1: |-
623+
client.index('articles').reset_separator_tokens
624+
get_non_separator_tokens_1: |-
625+
client.index('articles').non_separator_tokens
626+
update_non_separator_tokens_1: |-
627+
client.index('articles').update_non_separator_tokens(['@', '#'])
628+
reset_non_separator_tokens_1: |-
629+
client.index('articles').reset_non_separator_tokens

.github/workflows/gempush.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-20.04
1212

1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515
- name: Set up Ruby 2.6
1616
uses: actions/setup-ruby@v1
1717
with:

.github/workflows/pre-release-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
name: integration-tests-against-rc (ruby ${{ matrix.ruby-version }})
1818
runs-on: ubuntu-20.04
1919
steps:
20-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2121
- name: Set up Ruby ${{ matrix.ruby-version }}
2222
uses: ruby/setup-ruby@v1
2323
with:

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
name: integration-tests (ruby ${{ matrix.ruby-version }})
2222
runs-on: ubuntu-20.04
2323
steps:
24-
- uses: actions/checkout@v3
24+
- uses: actions/checkout@v4
2525
- name: Set up Ruby ${{ matrix.ruby-version }}
2626
uses: ruby/setup-ruby@v1
2727
with:
@@ -41,7 +41,7 @@ jobs:
4141
name: linter-check
4242
runs-on: ubuntu-20.04
4343
steps:
44-
- uses: actions/checkout@v3
44+
- uses: actions/checkout@v4
4545
- name: Set up Ruby
4646
uses: ruby/setup-ruby@v1
4747
with:
@@ -55,7 +55,7 @@ jobs:
5555
name: Yaml linting check
5656
runs-on: ubuntu-latest
5757
steps:
58-
- uses: actions/checkout@v3
58+
- uses: actions/checkout@v4
5959
- name: Yaml lint check
6060
uses: ibiqlik/action-yamllint@v3
6161
with:

.rubocop_todo.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-05-20 02:24:12 UTC using RuboCop version 1.50.2.
3+
# on 2023-10-10 14:01:22 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: 1
10-
# This cop supports safe autocorrection (--autocorrect).
11-
# Configuration parameters: Severity, Include.
12-
# Include: **/*.gemspec
13-
Gemspec/RequireMFA:
14-
Exclude:
15-
- 'meilisearch.gemspec'
16-
17-
# Offense count: 47
9+
# Offense count: 52
1810
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
1911
# AllowedMethods: refine
2012
Metrics/BlockLength:
21-
Max: 624
13+
Max: 671
2214

2315
# Offense count: 2
2416
# Configuration parameters: CountComments, CountAsOne.
2517
Metrics/ClassLength:
26-
Max: 328
18+
Max: 358
2719

2820
# Offense count: 1
2921
# Configuration parameters: Max, CountKeywordArgs.

lib/meilisearch/error.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# frozen_string_literal: true
22

33
module MeiliSearch
4-
class ApiError < StandardError
4+
class Error < StandardError
5+
end
6+
7+
class ApiError < Error
58
# :http_code # e.g. 400, 404...
69
# :http_message # e.g. Bad Request, Not Found...
710
# :http_body # The response body received from the MeiliSearch API
@@ -45,7 +48,7 @@ def details
4548
end
4649
end
4750

48-
class CommunicationError < StandardError
51+
class CommunicationError < Error
4952
attr_reader :message
5053

5154
def initialize(message)
@@ -54,7 +57,7 @@ def initialize(message)
5457
end
5558
end
5659

57-
class TimeoutError < StandardError
60+
class TimeoutError < Error
5861
attr_reader :message
5962

6063
def initialize(message = nil)
@@ -64,8 +67,8 @@ def initialize(message = nil)
6467
end
6568

6669
module TenantToken
67-
class ExpireOrInvalidSignature < StandardError; end
68-
class InvalidApiKey < StandardError; end
69-
class InvalidSearchRules < StandardError; end
70+
class ExpireOrInvalidSignature < MeiliSearch::Error; end
71+
class InvalidApiKey < MeiliSearch::Error; end
72+
class InvalidSearchRules < MeiliSearch::Error; end
7073
end
7174
end

lib/meilisearch/index.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,5 +461,49 @@ def update_faceting(faceting_attributes)
461461
def reset_faceting
462462
http_delete("/indexes/#{@uid}/settings/faceting")
463463
end
464+
465+
### SETTINGS - DICTIONARY
466+
467+
def dictionary
468+
http_get("/indexes/#{@uid}/settings/dictionary")
469+
end
470+
471+
def update_dictionary(dictionary_attributes)
472+
attributes = Utils.transform_attributes(dictionary_attributes)
473+
http_put("/indexes/#{@uid}/settings/dictionary", attributes)
474+
end
475+
476+
def reset_dictionary
477+
http_delete("/indexes/#{@uid}/settings/dictionary")
478+
end
479+
### SETTINGS - SEPARATOR TOKENS
480+
481+
def separator_tokens
482+
http_get("/indexes/#{@uid}/settings/separator-tokens")
483+
end
484+
485+
def update_separator_tokens(separator_tokens_attributes)
486+
attributes = Utils.transform_attributes(separator_tokens_attributes)
487+
http_put("/indexes/#{@uid}/settings/separator-tokens", attributes)
488+
end
489+
490+
def reset_separator_tokens
491+
http_delete("/indexes/#{@uid}/settings/separator-tokens")
492+
end
493+
494+
### SETTINGS - NON SEPARATOR TOKENS
495+
496+
def non_separator_tokens
497+
http_get("/indexes/#{@uid}/settings/non-separator-tokens")
498+
end
499+
500+
def update_non_separator_tokens(non_separator_tokens_attributes)
501+
attributes = Utils.transform_attributes(non_separator_tokens_attributes)
502+
http_put("/indexes/#{@uid}/settings/non-separator-tokens", attributes)
503+
end
504+
505+
def reset_non_separator_tokens
506+
http_delete("/indexes/#{@uid}/settings/non-separator-tokens")
507+
end
464508
end
465509
end

spec/meilisearch/client/errors_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# frozen_string_literal: true
22

33
RSpec.describe 'MeiliSearch::Client - Errors' do
4+
describe 'MeiliSearch::Error' do
5+
it 'catches all other errors' do
6+
expect(MeiliSearch::TimeoutError.ancestors).to include(MeiliSearch::Error)
7+
expect(MeiliSearch::CommunicationError.ancestors).to include(MeiliSearch::Error)
8+
expect(MeiliSearch::ApiError.ancestors).to include(MeiliSearch::Error)
9+
expect(MeiliSearch::TenantToken::InvalidApiKey.ancestors).to include(MeiliSearch::Error)
10+
expect(MeiliSearch::TenantToken::InvalidSearchRules.ancestors).to include(MeiliSearch::Error)
11+
expect(MeiliSearch::TenantToken::ExpireOrInvalidSignature.ancestors).to include(MeiliSearch::Error)
12+
end
13+
end
14+
415
context 'when request takes to long to answer' do
516
it 'raises MeiliSearch::TimeoutError' do
617
timed_client = MeiliSearch::Client.new(URL, MASTER_KEY, { timeout: 0.000001 })

0 commit comments

Comments
 (0)