Skip to content

Commit 96ee18c

Browse files
authored
Merge branch 'main' into 218-documents-in-batches
2 parents 73e56df + 62765a9 commit 96ee18c

29 files changed

+125
-99
lines changed

.code-samples.meilisearch.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,15 @@ reset_sortable_attributes_1: |-
381381
client.index('books').reset_sortable_attributes
382382
search_parameter_guide_sort_1: |-
383383
client.index('books').search('science fiction', { sort: ['price:asc'] })
384+
geosearch_guide_filter_settings_1: |-
385+
client.index('restaurants').update_filterable_attributes(['_geo'])
386+
geosearch_guide_filter_usage_1: |-
387+
client.index('restaurants').search('', { filter: '_geoRadius(45.4628328, 9.1076931, 2000)' })
388+
geosearch_guide_filter_usage_2: |-
389+
client.index('restaurants').search('', { filter: '_geoRadius(45.4628328, 9.1076931, 2000) AND type = pizza' })
390+
geosearch_guide_sort_settings_1: |-
391+
client.index('restaurants').update_sortable_attributes(['_geo'])
392+
geosearch_guide_sort_usage_1: |-
393+
client.index('restaurants').search('', { sort: ['_geoPoint(48.8583701,2.2922926):asc'] })
394+
geosearch_guide_sort_usage_2: |-
395+
client.index('restaurants').search('', { sort: ['_geoPoint(48.8583701,2.2922926):asc', 'rating:desc'] })

.rubocop.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,3 @@ Style/SymbolArray:
2020

2121
Style/WordArray:
2222
EnforcedStyle: brackets
23-
24-
Style/GlobalVars:
25-
AllowedVariables:
26-
- $URL
27-
- $MASTER_KEY
28-
- $DEFAULT_SEARCH_RESPONSE_KEYS

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ group :development, :test do
1414
end
1515

1616
group :development do
17-
gem 'rubocop', '~> 1.20.0', require: false
17+
gem 'rubocop', '~> 1.22.1', require: false
1818
end

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ require 'meilisearch'
7878
client = MeiliSearch::Client.new('http://127.0.0.1:7700', 'masterKey')
7979

8080
# An index is where the documents are stored.
81-
index = client.index('books')
81+
index = client.index('movies')
8282

8383
documents = [
84-
{ book_id: 123, title: 'Pride and Prejudice' },
85-
{ book_id: 456, title: 'Le Petit Prince' },
86-
{ book_id: 1, title: 'Alice In Wonderland' },
87-
{ book_id: 1344, title: 'The Hobbit' },
88-
{ book_id: 4, title: 'Harry Potter and the Half-Blood Prince' },
89-
{ book_id: 42, title: 'The Hitchhiker\'s Guide to the Galaxy' }
84+
{ id: 1, title: 'Carol', genres: ['Romance', 'Drama'] },
85+
{ id: 2, title: 'Wonder Woman', genres: ['Action', 'Adventure'] },
86+
{ id: 3, title: 'Life of Pi', genres: ['Adventure', 'Drama'] },
87+
{ id: 4, title: 'Mad Max: Fury Road', genres: ['Adventure', 'Science Fiction'] },
88+
{ id: 5, title: 'Moana', genres: ['Fantasy', 'Action']},
89+
{ id: 6, title: 'Philadelphia', genres: ['Drama'] },
9090
]
91-
# If the index 'books' does not exist, MeiliSearch creates it when you first add the documents.
91+
# If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents.
9292
index.add_documents(documents) # => { "updateId": 0 }
9393
```
9494

@@ -100,20 +100,20 @@ With the `updateId`, you can check the status (`enqueued`, `processing`, `proces
100100

101101
``` ruby
102102
# MeiliSearch is typo-tolerant:
103-
puts index.search('harry pottre')
103+
puts index.search('carlo')
104104
```
105105
Output:
106106

107107
```ruby
108108
{
109109
"hits" => [{
110-
"book_id" => 4,
111-
"title" => "Harry Potter and the Half-Blood Prince"
110+
"id" => 1,
111+
"title" => "Carol"
112112
}],
113113
"offset" => 0,
114114
"limit" => 20,
115115
"processingTimeMs" => 1,
116-
"query" => "harry pottre"
116+
"query" => "carlo"
117117
}
118118
```
119119

@@ -123,7 +123,7 @@ All the supported options are described in the [search parameters](https://docs.
123123

124124
```ruby
125125
index.search(
126-
'hob',
126+
'wonder',
127127
attributesToHighlight: ['*']
128128
)
129129
```
@@ -134,24 +134,24 @@ JSON output:
134134
{
135135
"hits": [
136136
{
137-
"book_id": 1344,
138-
"title": "The Hobbit",
137+
"id": 2,
138+
"title": "Wonder Woman",
139139
"_formatted": {
140-
"book_id": 1344,
141-
"title": "The <em>Hob</em>bit"
140+
"id": 2,
141+
"title": "<em>Wonder</em> Woman"
142142
}
143143
}
144144
],
145145
"offset": 0,
146146
"limit": 20,
147147
"processingTimeMs": 0,
148-
"query": "hob"
148+
"query": "wonder"
149149
}
150150
```
151151

152152
## 🤖 Compatibility with MeiliSearch
153153

154-
This package only guarantees the compatibility with the [version v0.22.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.22.0).
154+
This package only guarantees the compatibility with the [version v0.23.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.23.0).
155155

156156
## 💡 Learn More
157157

lib/meilisearch/client.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ def delete_index(index_uid)
3434
index_object(index_uid).delete
3535
end
3636

37+
# Usage:
38+
# client.delete_index_if_exists('indexUID')
39+
def delete_index_if_exists(index_uid)
40+
index_object(index_uid).delete
41+
true
42+
rescue ApiError => e
43+
raise e if e.code != 'index_not_found'
44+
45+
false
46+
end
47+
3748
# Usage:
3849
# client.index('indexUID')
3950
def index(index_uid)

meilisearch.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ Gem::Specification.new do |s|
2323
]
2424

2525
s.required_ruby_version = '>= 2.6.0'
26-
s.add_dependency 'httparty', '>= 0.17.1', '< 0.20.0'
26+
s.add_dependency 'httparty', '>= 0.17.1', '< 0.21.0'
2727
end

spec/meilisearch/client/dumps_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
RSpec.describe 'MeiliSearch::Client - Dumps' do
44
before(:all) do
5-
@client = MeiliSearch::Client.new($URL, $MASTER_KEY)
5+
@client = MeiliSearch::Client.new(URL, MASTER_KEY)
66
clear_all_indexes(@client)
77
end
88

spec/meilisearch/client/health_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
RSpec.describe 'MeiliSearch::Client - Health' do
4-
let(:client) { MeiliSearch::Client.new($URL, $MASTER_KEY) }
4+
let(:client) { MeiliSearch::Client.new(URL, MASTER_KEY) }
55
let(:wrong_client) { MeiliSearch::Client.new('bad_url') }
66

77
it 'is healthy when the url is valid' do

spec/meilisearch/client/indexes_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
RSpec.describe 'MeiliSearch::Client - Indexes' do
44
before(:all) do
5-
@client = MeiliSearch::Client.new($URL, $MASTER_KEY)
5+
@client = MeiliSearch::Client.new(URL, MASTER_KEY)
66
clear_all_indexes(@client)
77
@uid1 = 'uid1'
88
@uid2 = 'uid2'
99
@uid3 = 'uid3'
1010
@uid4 = 'uid4'
1111
@uid5 = 'uid5'
12+
@uid6 = 'uid6'
13+
@uid7 = 'uid7'
1214
@primary_key = 'objectId'
1315
end
1416

@@ -116,4 +118,12 @@
116118
expect { @client.fetch_index(@uid5) }.to raise_index_not_found_meilisearch_api_error
117119
expect(@client.indexes.count).to eq(0)
118120
end
121+
122+
it 'deletes index if index exists' do
123+
@client.create_index(@uid6)
124+
expect(@client.delete_index_if_exists(@uid6)).to eq(true)
125+
expect { @client.fetch_index(@uid6) }.to raise_index_not_found_meilisearch_api_error
126+
expect(@client.delete_index_if_exists(@uid6)).to eq(false)
127+
expect(@client.indexes.count).to eq(0)
128+
end
119129
end

spec/meilisearch/client/keys_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
RSpec.describe 'MeiliSearch::Client - Keys' do
44
before(:all) do
5-
@client = MeiliSearch::Client.new($URL, $MASTER_KEY)
5+
@client = MeiliSearch::Client.new(URL, MASTER_KEY)
66
@uid = 'uid'
77
@client.create_index(@uid)
88
end
@@ -20,37 +20,37 @@
2020

2121
it 'fails to get settings if public key used' do
2222
public_key = @client.keys['public']
23-
new_client = MeiliSearch::Client.new($URL, public_key)
23+
new_client = MeiliSearch::Client.new(URL, public_key)
2424
expect do
2525
new_client.index(@uid).settings
2626
end.to raise_meilisearch_api_error_with(403, 'invalid_token', 'authentication_error')
2727
end
2828

2929
it 'fails to get keys if private key used' do
3030
private_key = @client.keys['private']
31-
new_client = MeiliSearch::Client.new($URL, private_key)
31+
new_client = MeiliSearch::Client.new(URL, private_key)
3232
expect do
3333
new_client.keys
3434
end.to raise_meilisearch_api_error_with(403, 'invalid_token', 'authentication_error')
3535
end
3636

3737
it 'fails to search if no key used' do
38-
new_client = MeiliSearch::Client.new($URL)
38+
new_client = MeiliSearch::Client.new(URL)
3939
expect do
4040
new_client.index(@uid).settings
4141
end.to raise_meilisearch_api_error_with(401, 'missing_authorization_header', 'authentication_error')
4242
end
4343

4444
it 'succeeds to search when using public key' do
4545
public_key = @client.keys['public']
46-
new_client = MeiliSearch::Client.new($URL, public_key)
46+
new_client = MeiliSearch::Client.new(URL, public_key)
4747
response = new_client.index(@uid).search('test')
4848
expect(response).to have_key('hits')
4949
end
5050

5151
it 'succeeds to get settings when using private key' do
5252
private_key = @client.keys['private']
53-
new_client = MeiliSearch::Client.new($URL, private_key)
53+
new_client = MeiliSearch::Client.new(URL, private_key)
5454
response = new_client.index(@uid).settings
5555
expect(response).to have_key('rankingRules')
5656
end

0 commit comments

Comments
 (0)