meilisearch 0.17.3 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/lib/meilisearch/client.rb +44 -23
- data/lib/meilisearch/http_request.rb +15 -4
- data/lib/meilisearch/index.rb +33 -49
- data/lib/meilisearch/task.rb +43 -0
- data/lib/meilisearch/version.rb +1 -1
- data/lib/meilisearch.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df541b398ac4b031ec615d5e20c6a19cd7c370cdeaf83dcf63d789374827f012
|
4
|
+
data.tar.gz: 9277554fe2d6f388491d506cbfda456e71a1cc90b1945d933cfa72a2147ee52c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc0446c08444d6bf48d796c62c9b92e5f008835463b08c916e52f0ac9ce81156bcb835cd645fd78c31b98907a06230cf60fe2dbcfdcf0102b9c3fe8f9dfc2732
|
7
|
+
data.tar.gz: ac4f2136062699556c365e296db97fe54c6085a228c2b6831b963a72557918c100b83f7e5241183b5d9d173927e127b1e2ad402045dc64ec71056c7b57663fb2
|
data/README.md
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
<a href="https://badge.fury.io/rb/meilisearch"><img src="https://badge.fury.io/rb/meilisearch.svg" alt="Latest Stable Version"></a>
|
18
18
|
<a href="https://github.com/meilisearch/meilisearch-ruby/actions"><img src="https://github.com/meilisearch/meilisearch-ruby/workflows/Tests/badge.svg" alt="Test"></a>
|
19
19
|
<a href="https://github.com/meilisearch/meilisearch-ruby/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-informational" alt="License"></a>
|
20
|
-
<a href="https://
|
20
|
+
<a href="https://ms-bors.herokuapp.com/repositories/6"><img src="https://bors.tech/images/badge_small.svg" alt="Bors enabled"></a>
|
21
21
|
</p>
|
22
22
|
|
23
23
|
<p align="center">⚡ The MeiliSearch API client written for Ruby 💎</p>
|
@@ -92,10 +92,10 @@ documents = [
|
|
92
92
|
{ id: 6, title: 'Philadelphia', genres: ['Drama'] },
|
93
93
|
]
|
94
94
|
# If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents.
|
95
|
-
index.add_documents(documents) # => { "
|
95
|
+
index.add_documents(documents) # => { "uid": 0 }
|
96
96
|
```
|
97
97
|
|
98
|
-
With the `
|
98
|
+
With the `uid`, you can check the status (`enqueued`, `processing`, `succeeded` or `failed`) of your documents addition using the [task](https://docs.meilisearch.com/reference/api/tasks.html#get-task).
|
99
99
|
|
100
100
|
💡 To customize the `Client`, for example, increasing the default timeout, please check out [this section](https://github.com/meilisearch/meilisearch-ruby/wiki/Client-Options) of the Wiki.
|
101
101
|
|
@@ -165,7 +165,7 @@ index.update_filterable_attributes([
|
|
165
165
|
|
166
166
|
You only need to perform this operation once.
|
167
167
|
|
168
|
-
Note that MeiliSearch will rebuild your index whenever you update `filterableAttributes`. Depending on the size of your dataset, this might take time. You can track the process using the [
|
168
|
+
Note that MeiliSearch will rebuild your index whenever you update `filterableAttributes`. Depending on the size of your dataset, this might take time. You can track the process using the [tasks](https://docs.meilisearch.com/reference/api/tasks.html#get-task)).
|
169
169
|
|
170
170
|
Then, you can perform the search:
|
171
171
|
|
@@ -198,7 +198,7 @@ JSON output:
|
|
198
198
|
|
199
199
|
## 🤖 Compatibility with MeiliSearch
|
200
200
|
|
201
|
-
This package only guarantees the compatibility with the [version v0.
|
201
|
+
This package only guarantees the compatibility with the [version v0.25.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.25.0).
|
202
202
|
|
203
203
|
## 💡 Learn More
|
204
204
|
|
data/lib/meilisearch/client.rb
CHANGED
@@ -22,36 +22,20 @@ module MeiliSearch
|
|
22
22
|
def create_index(index_uid, options = {})
|
23
23
|
body = Utils.transform_attributes(options.merge(uid: index_uid))
|
24
24
|
|
25
|
-
|
26
|
-
index_object(index_hash['uid'], index_hash['primaryKey'])
|
25
|
+
http_post '/indexes', body
|
27
26
|
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
index_instance = create_index(index_uid, options)
|
36
|
-
end
|
37
|
-
index_instance
|
28
|
+
# Synchronous version of create_index.
|
29
|
+
# Waits for the task to be achieved, be careful when using it.
|
30
|
+
def create_index!(index_uid, options = {})
|
31
|
+
task = create_index(index_uid, options)
|
32
|
+
wait_for_task(task['uid'])
|
38
33
|
end
|
39
34
|
|
40
35
|
def delete_index(index_uid)
|
41
36
|
index_object(index_uid).delete
|
42
37
|
end
|
43
38
|
|
44
|
-
# Usage:
|
45
|
-
# client.delete_index_if_exists('indexUID')
|
46
|
-
def delete_index_if_exists(index_uid)
|
47
|
-
index_object(index_uid).delete
|
48
|
-
true
|
49
|
-
rescue ApiError => e
|
50
|
-
raise e if e.code != 'index_not_found'
|
51
|
-
|
52
|
-
false
|
53
|
-
end
|
54
|
-
|
55
39
|
# Usage:
|
56
40
|
# client.index('indexUID')
|
57
41
|
def index(index_uid)
|
@@ -71,7 +55,26 @@ module MeiliSearch
|
|
71
55
|
def keys
|
72
56
|
http_get '/keys'
|
73
57
|
end
|
74
|
-
|
58
|
+
|
59
|
+
def key(key_uid)
|
60
|
+
http_get "/keys/#{key_uid}"
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_key(key_options)
|
64
|
+
body = Utils.transform_attributes(key_options)
|
65
|
+
|
66
|
+
http_post '/keys', body
|
67
|
+
end
|
68
|
+
|
69
|
+
def update_key(key_uid, key_options)
|
70
|
+
body = Utils.transform_attributes(key_options)
|
71
|
+
|
72
|
+
http_patch "/keys/#{key_uid}", body
|
73
|
+
end
|
74
|
+
|
75
|
+
def delete_key(key_uid)
|
76
|
+
http_delete "/keys/#{key_uid}"
|
77
|
+
end
|
75
78
|
|
76
79
|
### HEALTH
|
77
80
|
|
@@ -107,10 +110,28 @@ module MeiliSearch
|
|
107
110
|
end
|
108
111
|
alias get_dump_status dump_status
|
109
112
|
|
113
|
+
### TASKS
|
114
|
+
|
115
|
+
def tasks
|
116
|
+
task_endpoint.task_list
|
117
|
+
end
|
118
|
+
|
119
|
+
def task(task_uid)
|
120
|
+
task_endpoint.task(task_uid)
|
121
|
+
end
|
122
|
+
|
123
|
+
def wait_for_task(task_uid, timeout_in_ms = 5000, interval_in_ms = 50)
|
124
|
+
task_endpoint.wait_for_task(task_uid, timeout_in_ms, interval_in_ms)
|
125
|
+
end
|
126
|
+
|
110
127
|
private
|
111
128
|
|
112
129
|
def index_object(uid, primary_key = nil)
|
113
130
|
Index.new(uid, @base_url, @api_key, primary_key, @options)
|
114
131
|
end
|
132
|
+
|
133
|
+
def task_endpoint
|
134
|
+
@task_endpoint ||= Task.new(@base_url, @api_key, @options)
|
135
|
+
end
|
115
136
|
end
|
116
137
|
end
|
@@ -49,6 +49,16 @@ module MeiliSearch
|
|
49
49
|
)
|
50
50
|
end
|
51
51
|
|
52
|
+
def http_patch(relative_path = '', body = nil, query_params = nil)
|
53
|
+
send_request(
|
54
|
+
proc { |path, config| self.class.patch(path, config) },
|
55
|
+
relative_path,
|
56
|
+
query_params: query_params,
|
57
|
+
body: body,
|
58
|
+
options: @options
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
52
62
|
def http_delete(relative_path = '')
|
53
63
|
send_request(
|
54
64
|
proc { |path, config| self.class.delete(path, config) },
|
@@ -60,10 +70,11 @@ module MeiliSearch
|
|
60
70
|
private
|
61
71
|
|
62
72
|
def build_default_options_headers(api_key = nil)
|
63
|
-
{
|
64
|
-
'Content-Type' => 'application/json'
|
65
|
-
|
66
|
-
}.
|
73
|
+
header = {
|
74
|
+
'Content-Type' => 'application/json'
|
75
|
+
}
|
76
|
+
header = header.merge('Authorization' => "Bearer #{api_key}") unless api_key.nil?
|
77
|
+
header
|
67
78
|
end
|
68
79
|
|
69
80
|
def merge_options(default_options, added_options = {})
|
data/lib/meilisearch/index.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'meilisearch/http_request'
|
4
|
-
require 'timeout'
|
5
4
|
|
6
5
|
module MeiliSearch
|
7
6
|
class Index < HTTPRequest
|
@@ -31,10 +30,7 @@ module MeiliSearch
|
|
31
30
|
end
|
32
31
|
|
33
32
|
def update(body)
|
34
|
-
|
35
|
-
set_base_properties index_hash
|
36
|
-
|
37
|
-
self
|
33
|
+
http_put indexes_path(id: @uid), Utils.transform_attributes(body)
|
38
34
|
end
|
39
35
|
|
40
36
|
alias update_index update
|
@@ -78,8 +74,8 @@ module MeiliSearch
|
|
78
74
|
alias add_or_replace_documents add_documents
|
79
75
|
|
80
76
|
def add_documents!(documents, primary_key = nil)
|
81
|
-
|
82
|
-
|
77
|
+
task = add_documents(documents, primary_key)
|
78
|
+
wait_for_task(task['uid'])
|
83
79
|
end
|
84
80
|
alias replace_documents! add_documents!
|
85
81
|
alias add_or_replace_documents! add_documents!
|
@@ -112,41 +108,41 @@ module MeiliSearch
|
|
112
108
|
alias add_or_update_documents update_documents
|
113
109
|
|
114
110
|
def update_documents!(documents, primary_key = nil)
|
115
|
-
|
116
|
-
|
111
|
+
task = update_documents(documents, primary_key)
|
112
|
+
wait_for_task(task['uid'])
|
117
113
|
end
|
118
114
|
alias add_or_update_documents! update_documents!
|
119
115
|
|
120
116
|
def add_documents_in_batches(documents, batch_size = 1000, primary_key = nil)
|
121
|
-
|
117
|
+
tasks = []
|
122
118
|
documents.each_slice(batch_size) do |batch|
|
123
|
-
|
119
|
+
tasks.append(add_documents(batch, primary_key))
|
124
120
|
end
|
125
|
-
|
121
|
+
tasks
|
126
122
|
end
|
127
123
|
|
128
124
|
def add_documents_in_batches!(documents, batch_size = 1000, primary_key = nil)
|
129
|
-
|
125
|
+
tasks = add_documents_in_batches(documents, batch_size, primary_key)
|
130
126
|
responses = []
|
131
|
-
|
132
|
-
responses.append(
|
127
|
+
tasks.each do |task_obj|
|
128
|
+
responses.append(wait_for_task(task_obj['uid']))
|
133
129
|
end
|
134
130
|
responses
|
135
131
|
end
|
136
132
|
|
137
133
|
def update_documents_in_batches(documents, batch_size = 1000, primary_key = nil)
|
138
|
-
|
134
|
+
tasks = []
|
139
135
|
documents.each_slice(batch_size) do |batch|
|
140
|
-
|
136
|
+
tasks.append(update_documents(batch, primary_key))
|
141
137
|
end
|
142
|
-
|
138
|
+
tasks
|
143
139
|
end
|
144
140
|
|
145
141
|
def update_documents_in_batches!(documents, batch_size = 1000, primary_key = nil)
|
146
|
-
|
142
|
+
tasks = update_documents_in_batches(documents, batch_size, primary_key)
|
147
143
|
responses = []
|
148
|
-
|
149
|
-
responses.append(
|
144
|
+
tasks.each do |task_obj|
|
145
|
+
responses.append(wait_for_task(task_obj['uid']))
|
150
146
|
end
|
151
147
|
responses
|
152
148
|
end
|
@@ -161,8 +157,8 @@ module MeiliSearch
|
|
161
157
|
alias delete_multiple_documents delete_documents
|
162
158
|
|
163
159
|
def delete_documents!(documents_ids)
|
164
|
-
|
165
|
-
|
160
|
+
task = delete_documents(documents_ids)
|
161
|
+
wait_for_task(task['uid'])
|
166
162
|
end
|
167
163
|
alias delete_multiple_documents! delete_documents!
|
168
164
|
|
@@ -173,8 +169,8 @@ module MeiliSearch
|
|
173
169
|
alias delete_one_document delete_document
|
174
170
|
|
175
171
|
def delete_document!(document_id)
|
176
|
-
|
177
|
-
|
172
|
+
task = delete_document(document_id)
|
173
|
+
wait_for_task(task['uid'])
|
178
174
|
end
|
179
175
|
alias delete_one_document! delete_document!
|
180
176
|
|
@@ -183,8 +179,8 @@ module MeiliSearch
|
|
183
179
|
end
|
184
180
|
|
185
181
|
def delete_all_documents!
|
186
|
-
|
187
|
-
|
182
|
+
task = delete_all_documents
|
183
|
+
wait_for_task(task['uid'])
|
188
184
|
end
|
189
185
|
|
190
186
|
### SEARCH
|
@@ -195,31 +191,23 @@ module MeiliSearch
|
|
195
191
|
http_post "/indexes/#{@uid}/search", parsed_options
|
196
192
|
end
|
197
193
|
|
198
|
-
###
|
194
|
+
### TASKS
|
199
195
|
|
200
|
-
def
|
201
|
-
|
196
|
+
def task_endpoint
|
197
|
+
@task_endpoint ||= Task.new(@base_url, @api_key, @options)
|
202
198
|
end
|
199
|
+
private :task_endpoint
|
203
200
|
|
204
|
-
def
|
205
|
-
|
201
|
+
def task(task_uid)
|
202
|
+
task_endpoint.index_task(@uid, task_uid)
|
206
203
|
end
|
207
204
|
|
208
|
-
def
|
209
|
-
|
205
|
+
def tasks
|
206
|
+
task_endpoint.index_tasks(@uid)
|
210
207
|
end
|
211
208
|
|
212
|
-
def
|
213
|
-
|
214
|
-
loop do
|
215
|
-
get_update = get_update_status(update_id)
|
216
|
-
return get_update if achieved_upate?(get_update)
|
217
|
-
|
218
|
-
sleep interval_in_ms.to_f / 1000
|
219
|
-
end
|
220
|
-
end
|
221
|
-
rescue Timeout::Error
|
222
|
-
raise MeiliSearch::TimeoutError
|
209
|
+
def wait_for_task(task_uid, timeout_in_ms = 5000, interval_in_ms = 50)
|
210
|
+
task_endpoint.wait_for_task(task_uid, timeout_in_ms, interval_in_ms)
|
223
211
|
end
|
224
212
|
|
225
213
|
### STATS
|
@@ -236,10 +224,6 @@ module MeiliSearch
|
|
236
224
|
stats['isIndexing']
|
237
225
|
end
|
238
226
|
|
239
|
-
def last_update
|
240
|
-
stats['lastUpdate']
|
241
|
-
end
|
242
|
-
|
243
227
|
def field_distribution
|
244
228
|
stats['fieldDistribution']
|
245
229
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'meilisearch/http_request'
|
4
|
+
require 'timeout'
|
5
|
+
|
6
|
+
module MeiliSearch
|
7
|
+
class Task < HTTPRequest
|
8
|
+
def task_list
|
9
|
+
http_get '/tasks/'
|
10
|
+
end
|
11
|
+
|
12
|
+
def task(task_uid)
|
13
|
+
http_get "/tasks/#{task_uid}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def index_tasks(index_uid)
|
17
|
+
http_get "/indexes/#{index_uid}/tasks"
|
18
|
+
end
|
19
|
+
|
20
|
+
def index_task(index_uid, task_uid)
|
21
|
+
http_get "/indexes/#{index_uid}/tasks/#{task_uid}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def wait_for_task(task_uid, timeout_in_ms = 5000, interval_in_ms = 50)
|
25
|
+
Timeout.timeout(timeout_in_ms.to_f / 1000) do
|
26
|
+
loop do
|
27
|
+
task = task(task_uid)
|
28
|
+
return task if achieved_task?(task)
|
29
|
+
|
30
|
+
sleep interval_in_ms.to_f / 1000
|
31
|
+
end
|
32
|
+
end
|
33
|
+
rescue Timeout::Error
|
34
|
+
raise MeiliSearch::TimeoutError
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def achieved_task?(task)
|
40
|
+
task['status'] != 'enqueued' && task['status'] != 'processing'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/meilisearch/version.rb
CHANGED
data/lib/meilisearch.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meilisearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Meili
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- lib/meilisearch/error.rb
|
44
44
|
- lib/meilisearch/http_request.rb
|
45
45
|
- lib/meilisearch/index.rb
|
46
|
+
- lib/meilisearch/task.rb
|
46
47
|
- lib/meilisearch/utils.rb
|
47
48
|
- lib/meilisearch/version.rb
|
48
49
|
homepage: https://github.com/meilisearch/meilisearch-ruby
|