meilisearch 0.13.2 → 0.15.2
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/lib/meilisearch/client.rb +24 -16
- data/lib/meilisearch/error.rb +10 -8
- data/lib/meilisearch/http_request.rb +5 -3
- data/lib/meilisearch/index.rb +51 -9
- data/lib/meilisearch/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1a2bd63d9c8d081f0c4f9402f754fcd710b57a1e362aec937976b97bc2a7d32
|
4
|
+
data.tar.gz: c438bda2666f88704c58b0ced8c55803211848bd7a26ccf0059db36b29a860b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31339aea14f0be79d11aaac5b9c4b278a6a87201c291ba50608888339dff7e94730d9d2f6201967fac7ea7a6ce9e05da7418f964481c37bb00f875a22d1dd51e
|
7
|
+
data.tar.gz: 78c68477abafc1b5391fb4b5f527d71acf6b3fa3daf0d71855d595bcbc023338c152af37744b5f7c74126cc8d684b5ac0548a08a7021dc830f078ec734f8919f
|
data/lib/meilisearch/client.rb
CHANGED
@@ -10,26 +10,24 @@ module MeiliSearch
|
|
10
10
|
http_get '/indexes'
|
11
11
|
end
|
12
12
|
|
13
|
-
def show_index(index_uid)
|
14
|
-
index_object(index_uid).show
|
15
|
-
end
|
16
|
-
|
17
13
|
# Usage:
|
18
14
|
# client.create_index('indexUID')
|
19
15
|
# client.create_index('indexUID', primaryKey: 'id')
|
20
16
|
def create_index(index_uid, options = {})
|
21
17
|
body = options.merge(uid: index_uid)
|
22
|
-
|
23
|
-
index_object(
|
18
|
+
index_hash = http_post '/indexes', body
|
19
|
+
index_object(index_hash['uid'], index_hash['primaryKey'])
|
24
20
|
end
|
25
21
|
|
26
22
|
def get_or_create_index(index_uid, options = {})
|
27
23
|
begin
|
28
|
-
|
24
|
+
index_instance = fetch_index(index_uid)
|
29
25
|
rescue ApiError => e
|
30
|
-
raise e unless e.code == '
|
26
|
+
raise e unless e.code == 'index_not_found'
|
27
|
+
|
28
|
+
index_instance = create_index(index_uid, options)
|
31
29
|
end
|
32
|
-
|
30
|
+
index_instance
|
33
31
|
end
|
34
32
|
|
35
33
|
def delete_index(index_uid)
|
@@ -41,7 +39,10 @@ module MeiliSearch
|
|
41
39
|
def index(index_uid)
|
42
40
|
index_object(index_uid)
|
43
41
|
end
|
44
|
-
|
42
|
+
|
43
|
+
def fetch_index(index_uid)
|
44
|
+
index_object(index_uid).fetch_info
|
45
|
+
end
|
45
46
|
|
46
47
|
### KEYS
|
47
48
|
|
@@ -63,10 +64,6 @@ module MeiliSearch
|
|
63
64
|
http_get '/health'
|
64
65
|
end
|
65
66
|
|
66
|
-
def update_health(bool)
|
67
|
-
http_put '/health', health: bool
|
68
|
-
end
|
69
|
-
|
70
67
|
### STATS
|
71
68
|
|
72
69
|
def version
|
@@ -77,10 +74,21 @@ module MeiliSearch
|
|
77
74
|
http_get '/stats'
|
78
75
|
end
|
79
76
|
|
77
|
+
### DUMPS
|
78
|
+
|
79
|
+
def create_dump
|
80
|
+
http_post '/dumps'
|
81
|
+
end
|
82
|
+
|
83
|
+
def dump_status(dump_uid)
|
84
|
+
http_get "/dumps/#{dump_uid}/status"
|
85
|
+
end
|
86
|
+
alias get_dump_status dump_status
|
87
|
+
|
80
88
|
private
|
81
89
|
|
82
|
-
def index_object(uid)
|
83
|
-
Index.new(uid, @base_url, @api_key)
|
90
|
+
def index_object(uid, primary_key = nil)
|
91
|
+
Index.new(uid, @base_url, @api_key, primary_key)
|
84
92
|
end
|
85
93
|
end
|
86
94
|
end
|
data/lib/meilisearch/error.rb
CHANGED
@@ -2,14 +2,16 @@
|
|
2
2
|
|
3
3
|
module MeiliSearch
|
4
4
|
class ApiError < StandardError
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
# :http_code # e.g. 400, 404...
|
6
|
+
# :http_message # e.g. Bad Request, Not Found...
|
7
|
+
# :http_body # The response body received from the MeiliSearch API
|
8
|
+
# :ms_code # The error code given by the MeiliSearch API
|
9
|
+
# :ms_type # The error type given by the MeiliSearch API
|
10
|
+
# :ms_link # The documentation link given by the MeiliSearch API
|
11
|
+
# :ms_message # The error message given by the MeiliSearch API
|
12
|
+
# :message # The detailed error message of this error class
|
13
|
+
|
14
|
+
attr_reader :http_code, :http_message, :http_body, :ms_code, :ms_type, :ms_link, :ms_message, :message
|
13
15
|
|
14
16
|
alias code ms_code
|
15
17
|
alias type ms_type
|
@@ -7,9 +7,10 @@ module MeiliSearch
|
|
7
7
|
class HTTPRequest
|
8
8
|
include HTTParty
|
9
9
|
|
10
|
-
def initialize(url, api_key = nil)
|
10
|
+
def initialize(url, api_key = nil, options = {})
|
11
11
|
@base_url = url
|
12
12
|
@api_key = api_key
|
13
|
+
@options = options
|
13
14
|
@headers = {
|
14
15
|
'Content-Type' => 'application/json',
|
15
16
|
'X-Meili-API-Key' => api_key
|
@@ -62,12 +63,13 @@ module MeiliSearch
|
|
62
63
|
end
|
63
64
|
|
64
65
|
def http_config(query_params, body)
|
65
|
-
body = body.to_json
|
66
|
+
body = body.to_json
|
66
67
|
{
|
67
68
|
headers: @headers,
|
68
69
|
query: query_params,
|
69
70
|
body: body,
|
70
|
-
timeout: 1
|
71
|
+
timeout: @options[:timeout] || 1,
|
72
|
+
max_retries: @options[:max_retries] || 0
|
71
73
|
}.compact
|
72
74
|
end
|
73
75
|
|
data/lib/meilisearch/index.rb
CHANGED
@@ -5,20 +5,24 @@ require 'timeout'
|
|
5
5
|
|
6
6
|
module MeiliSearch
|
7
7
|
class Index < HTTPRequest
|
8
|
-
attr_reader :uid
|
8
|
+
attr_reader :uid, :primary_key
|
9
9
|
|
10
|
-
def initialize(index_uid, url, api_key = nil)
|
10
|
+
def initialize(index_uid, url, api_key = nil, primary_key = nil)
|
11
11
|
@uid = index_uid
|
12
|
+
@primary_key = primary_key
|
12
13
|
super(url, api_key)
|
13
14
|
end
|
14
15
|
|
15
|
-
def
|
16
|
-
http_get "/indexes/#{@uid}"
|
16
|
+
def fetch_info
|
17
|
+
index_hash = http_get "/indexes/#{@uid}"
|
18
|
+
@primary_key = index_hash['primaryKey']
|
19
|
+
self
|
17
20
|
end
|
18
|
-
alias show_index show
|
19
21
|
|
20
22
|
def update(body)
|
21
|
-
http_put "/indexes/#{@uid}", body
|
23
|
+
index_hash = http_put "/indexes/#{@uid}", body
|
24
|
+
@primary_key = index_hash['primaryKey']
|
25
|
+
self
|
22
26
|
end
|
23
27
|
alias update_index update
|
24
28
|
|
@@ -27,10 +31,10 @@ module MeiliSearch
|
|
27
31
|
end
|
28
32
|
alias delete_index delete
|
29
33
|
|
30
|
-
def
|
31
|
-
|
34
|
+
def fetch_primary_key
|
35
|
+
fetch_info.primary_key
|
32
36
|
end
|
33
|
-
alias get_primary_key
|
37
|
+
alias get_primary_key fetch_primary_key
|
34
38
|
|
35
39
|
### DOCUMENTS
|
36
40
|
|
@@ -53,12 +57,25 @@ module MeiliSearch
|
|
53
57
|
alias replace_documents add_documents
|
54
58
|
alias add_or_replace_documents add_documents
|
55
59
|
|
60
|
+
def add_documents!(documents, primary_key = nil)
|
61
|
+
update = add_documents(documents, primary_key)
|
62
|
+
wait_for_pending_update(update['updateId'])
|
63
|
+
end
|
64
|
+
alias replace_documents! add_documents!
|
65
|
+
alias add_or_replace_documents! add_documents!
|
66
|
+
|
56
67
|
def update_documents(documents, primary_key = nil)
|
57
68
|
documents = [documents] if documents.is_a?(Hash)
|
58
69
|
http_put "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact
|
59
70
|
end
|
60
71
|
alias add_or_update_documents update_documents
|
61
72
|
|
73
|
+
def update_documents!(documents, primary_key = nil)
|
74
|
+
update = update_documents(documents, primary_key)
|
75
|
+
wait_for_pending_update(update['updateId'])
|
76
|
+
end
|
77
|
+
alias add_or_update_documents! update_documents!
|
78
|
+
|
62
79
|
def delete_documents(documents_ids)
|
63
80
|
if documents_ids.is_a?(Array)
|
64
81
|
http_post "/indexes/#{@uid}/documents/delete-batch", documents_ids
|
@@ -68,16 +85,33 @@ module MeiliSearch
|
|
68
85
|
end
|
69
86
|
alias delete_multiple_documents delete_documents
|
70
87
|
|
88
|
+
def delete_documents!(documents_ids)
|
89
|
+
update = delete_documents(documents_ids)
|
90
|
+
wait_for_pending_update(update['updateId'])
|
91
|
+
end
|
92
|
+
alias delete_multiple_documents! delete_documents!
|
93
|
+
|
71
94
|
def delete_document(document_id)
|
72
95
|
encode_document = URI.encode_www_form_component(document_id)
|
73
96
|
http_delete "/indexes/#{@uid}/documents/#{encode_document}"
|
74
97
|
end
|
75
98
|
alias delete_one_document delete_document
|
76
99
|
|
100
|
+
def delete_document!(document_id)
|
101
|
+
update = delete_document(document_id)
|
102
|
+
wait_for_pending_update(update['updateId'])
|
103
|
+
end
|
104
|
+
alias delete_one_document! delete_document!
|
105
|
+
|
77
106
|
def delete_all_documents
|
78
107
|
http_delete "/indexes/#{@uid}/documents"
|
79
108
|
end
|
80
109
|
|
110
|
+
def delete_all_documents!
|
111
|
+
update = delete_all_documents
|
112
|
+
wait_for_pending_update(update['updateId'])
|
113
|
+
end
|
114
|
+
|
81
115
|
### SEARCH
|
82
116
|
|
83
117
|
def search(query, options = {})
|
@@ -140,6 +174,7 @@ module MeiliSearch
|
|
140
174
|
def update_settings(settings)
|
141
175
|
http_post "/indexes/#{@uid}/settings", settings
|
142
176
|
end
|
177
|
+
alias settings= update_settings
|
143
178
|
|
144
179
|
def reset_settings
|
145
180
|
http_delete "/indexes/#{@uid}/settings"
|
@@ -155,6 +190,7 @@ module MeiliSearch
|
|
155
190
|
def update_ranking_rules(ranking_rules)
|
156
191
|
http_post "/indexes/#{@uid}/settings/ranking-rules", ranking_rules
|
157
192
|
end
|
193
|
+
alias ranking_rules= update_ranking_rules
|
158
194
|
|
159
195
|
def reset_ranking_rules
|
160
196
|
http_delete "/indexes/#{@uid}/settings/ranking-rules"
|
@@ -170,6 +206,7 @@ module MeiliSearch
|
|
170
206
|
def update_synonyms(synonyms)
|
171
207
|
http_post "/indexes/#{@uid}/settings/synonyms", synonyms
|
172
208
|
end
|
209
|
+
alias synonyms= update_synonyms
|
173
210
|
|
174
211
|
def reset_synonyms
|
175
212
|
http_delete "/indexes/#{@uid}/settings/synonyms"
|
@@ -186,6 +223,7 @@ module MeiliSearch
|
|
186
223
|
body = stop_words.is_a?(Array) ? stop_words : [stop_words]
|
187
224
|
http_post "/indexes/#{@uid}/settings/stop-words", body
|
188
225
|
end
|
226
|
+
alias stop_words= update_stop_words
|
189
227
|
|
190
228
|
def reset_stop_words
|
191
229
|
http_delete "/indexes/#{@uid}/settings/stop-words"
|
@@ -201,6 +239,7 @@ module MeiliSearch
|
|
201
239
|
def update_distinct_attribute(distinct_attribute)
|
202
240
|
http_post "/indexes/#{@uid}/settings/distinct-attribute", distinct_attribute
|
203
241
|
end
|
242
|
+
alias distinct_attribute= update_distinct_attribute
|
204
243
|
|
205
244
|
def reset_distinct_attribute
|
206
245
|
http_delete "/indexes/#{@uid}/settings/distinct-attribute"
|
@@ -216,6 +255,7 @@ module MeiliSearch
|
|
216
255
|
def update_searchable_attributes(searchable_attributes)
|
217
256
|
http_post "/indexes/#{@uid}/settings/searchable-attributes", searchable_attributes
|
218
257
|
end
|
258
|
+
alias searchable_attributes= update_searchable_attributes
|
219
259
|
|
220
260
|
def reset_searchable_attributes
|
221
261
|
http_delete "/indexes/#{@uid}/settings/searchable-attributes"
|
@@ -231,6 +271,7 @@ module MeiliSearch
|
|
231
271
|
def update_displayed_attributes(displayed_attributes)
|
232
272
|
http_post "/indexes/#{@uid}/settings/displayed-attributes", displayed_attributes
|
233
273
|
end
|
274
|
+
alias displayed_attributes= update_displayed_attributes
|
234
275
|
|
235
276
|
def reset_displayed_attributes
|
236
277
|
http_delete "/indexes/#{@uid}/settings/displayed-attributes"
|
@@ -246,6 +287,7 @@ module MeiliSearch
|
|
246
287
|
def update_attributes_for_faceting(attributes_for_faceting)
|
247
288
|
http_post "/indexes/#{@uid}/settings/attributes-for-faceting", attributes_for_faceting
|
248
289
|
end
|
290
|
+
alias attributes_for_faceting= update_attributes_for_faceting
|
249
291
|
|
250
292
|
def reset_attributes_for_faceting
|
251
293
|
http_delete "/indexes/#{@uid}/settings/attributes-for-faceting"
|
data/lib/meilisearch/version.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.15.2
|
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: 2021-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -54,14 +54,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
54
|
requirements:
|
55
55
|
- - ">="
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version:
|
57
|
+
version: 2.6.0
|
58
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
requirements: []
|
64
|
-
rubygems_version: 3.0.3
|
64
|
+
rubygems_version: 3.0.3.1
|
65
65
|
signing_key:
|
66
66
|
specification_version: 4
|
67
67
|
summary: An easy-to-use ruby client for Meilisearch API
|