meilisearch 0.10.0 → 0.11.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/lib/meilisearch/client.rb +79 -8
- data/lib/meilisearch/error.rb +11 -0
- data/lib/meilisearch/http_request.rb +16 -26
- data/lib/meilisearch/index.rb +254 -17
- data/lib/meilisearch/version.rb +1 -1
- metadata +2 -14
- data/lib/meilisearch/client/health.rb +0 -22
- data/lib/meilisearch/client/indexes.rb +0 -50
- data/lib/meilisearch/client/keys.rb +0 -12
- data/lib/meilisearch/client/stats.rb +0 -23
- data/lib/meilisearch/index/base.rb +0 -22
- data/lib/meilisearch/index/documents.rb +0 -51
- data/lib/meilisearch/index/search.rb +0 -11
- data/lib/meilisearch/index/settings.rb +0 -87
- data/lib/meilisearch/index/stats.rb +0 -27
- data/lib/meilisearch/index/stop_words.rb +0 -21
- data/lib/meilisearch/index/synonyms.rb +0 -20
- data/lib/meilisearch/index/updates.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a36df5bca77a8d8487a6cfdf12ef055db52aec77d25d0a522e4fecb455d8714
|
4
|
+
data.tar.gz: e6a5b012fa2d4099be7ce43e5790ee032d612d68ce7fbcf697a6928458a23e51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37cba34617de2798ff77d3f5bd711862a84a14cbea9dca44349897dacff37f004184e6b71fad314ddefc3ce6a1cbcb124c5c9ed85781d7ee2028385bc20d3418
|
7
|
+
data.tar.gz: ce410e17029be8a779f10921aef8b28200dd3ae2fc1cb3924bbb5085596a1adc70c2a5e4aed5492751dee3d6f1ab4dbbdc7186673fe1041d2b4875819ab3ab65
|
data/lib/meilisearch/client.rb
CHANGED
@@ -1,16 +1,87 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'meilisearch/http_request'
|
4
|
-
require 'meilisearch/client/keys'
|
5
|
-
require 'meilisearch/client/stats'
|
6
|
-
require 'meilisearch/client/health'
|
7
|
-
require 'meilisearch/client/indexes'
|
8
4
|
|
9
5
|
module MeiliSearch
|
10
6
|
class Client < HTTPRequest
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
### INDEXES
|
8
|
+
|
9
|
+
def indexes
|
10
|
+
http_get '/indexes'
|
11
|
+
end
|
12
|
+
|
13
|
+
def show_index(index_uid)
|
14
|
+
index_object(index_uid).show
|
15
|
+
end
|
16
|
+
|
17
|
+
# Usage:
|
18
|
+
# client.create_index('indexUID')
|
19
|
+
# client.create_index('indexUID', primaryKey: 'id')
|
20
|
+
def create_index(index_uid, options = {})
|
21
|
+
body = { uid: index_uid }.merge(options)
|
22
|
+
res = http_post '/indexes', body
|
23
|
+
index_object(res['uid'])
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete_index(index_uid)
|
27
|
+
index_object(index_uid).delete
|
28
|
+
end
|
29
|
+
|
30
|
+
# Usage:
|
31
|
+
# client.index('indexUID')
|
32
|
+
def index(index_uid)
|
33
|
+
raise IndexUidError if index_uid.nil?
|
34
|
+
|
35
|
+
index_object(index_uid)
|
36
|
+
end
|
37
|
+
alias get_index index
|
38
|
+
|
39
|
+
### KEYS
|
40
|
+
|
41
|
+
def keys
|
42
|
+
http_get '/keys'
|
43
|
+
end
|
44
|
+
alias get_keys keys
|
45
|
+
|
46
|
+
### HEALTH
|
47
|
+
|
48
|
+
def healthy?
|
49
|
+
http_get '/health'
|
50
|
+
true
|
51
|
+
rescue StandardError
|
52
|
+
false
|
53
|
+
end
|
54
|
+
|
55
|
+
def health
|
56
|
+
http_get '/health'
|
57
|
+
end
|
58
|
+
|
59
|
+
def update_health(bool)
|
60
|
+
http_put '/health', health: bool
|
61
|
+
end
|
62
|
+
|
63
|
+
### STATS
|
64
|
+
|
65
|
+
def version
|
66
|
+
http_get '/version'
|
67
|
+
end
|
68
|
+
|
69
|
+
def sysinfo
|
70
|
+
http_get '/sys-info'
|
71
|
+
end
|
72
|
+
|
73
|
+
def pretty_sysinfo
|
74
|
+
http_get '/sys-info/pretty'
|
75
|
+
end
|
76
|
+
|
77
|
+
def stats
|
78
|
+
http_get '/stats'
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def index_object(uid)
|
84
|
+
Index.new(uid, @base_url, @api_key)
|
85
|
+
end
|
15
86
|
end
|
16
87
|
end
|
data/lib/meilisearch/error.rb
CHANGED
@@ -3,6 +3,17 @@
|
|
3
3
|
module MeiliSearch
|
4
4
|
class MeiliSearchError < StandardError; end
|
5
5
|
class IndexUidError < MeiliSearchError; end
|
6
|
+
class MeiliSearchTimeoutError < MeiliSearchError
|
7
|
+
attr_reader :message
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@message = "MeiliSearchTimeoutError: update wasn't processed in the expected time"
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
"#{@message}."
|
15
|
+
end
|
16
|
+
end
|
6
17
|
|
7
18
|
class HTTPError < MeiliSearchError
|
8
19
|
attr_reader :status
|
@@ -16,50 +16,40 @@ module MeiliSearch
|
|
16
16
|
}.compact
|
17
17
|
end
|
18
18
|
|
19
|
-
def http_get(path = '',
|
19
|
+
def http_get(path = '', query_params = {})
|
20
20
|
response = self.class.get(
|
21
21
|
@base_url + path,
|
22
|
-
query:
|
22
|
+
query: query_params,
|
23
23
|
headers: @headers,
|
24
24
|
timeout: 1
|
25
25
|
)
|
26
26
|
validate(response)
|
27
27
|
end
|
28
28
|
|
29
|
-
def http_post(path = '', body = nil,
|
29
|
+
def http_post(path = '', body = nil, query_params = nil)
|
30
30
|
body = body.to_json unless body.nil?
|
31
|
-
params = {
|
32
|
-
body: body,
|
33
|
-
query: params,
|
34
|
-
headers: @headers,
|
35
|
-
timeout: 1
|
36
|
-
}.compact
|
37
31
|
response = self.class.post(
|
38
32
|
@base_url + path,
|
39
|
-
|
33
|
+
{
|
34
|
+
body: body,
|
35
|
+
query: query_params,
|
36
|
+
headers: @headers,
|
37
|
+
timeout: 1
|
38
|
+
}.compact
|
40
39
|
)
|
41
40
|
validate(response)
|
42
41
|
end
|
43
42
|
|
44
|
-
def http_put(path = '', body = nil,
|
43
|
+
def http_put(path = '', body = nil, query_params = nil)
|
45
44
|
body = body.to_json unless body.nil?
|
46
45
|
response = self.class.put(
|
47
46
|
@base_url + path,
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
def http_patch(path = '', body = nil)
|
57
|
-
body = body.to_json unless body.nil?
|
58
|
-
response = self.class.patch(
|
59
|
-
@base_url + path,
|
60
|
-
body: body,
|
61
|
-
headers: @headers,
|
62
|
-
timeout: 1
|
47
|
+
{
|
48
|
+
body: body,
|
49
|
+
query: query_params,
|
50
|
+
headers: @headers,
|
51
|
+
timeout: 1
|
52
|
+
}.compact
|
63
53
|
)
|
64
54
|
validate(response)
|
65
55
|
end
|
data/lib/meilisearch/index.rb
CHANGED
@@ -1,26 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'meilisearch/http_request'
|
4
|
-
require '
|
5
|
-
require 'meilisearch/index/documents'
|
6
|
-
require 'meilisearch/index/search'
|
7
|
-
require 'meilisearch/index/stats'
|
8
|
-
require 'meilisearch/index/settings'
|
9
|
-
require 'meilisearch/index/updates'
|
10
|
-
require 'meilisearch/index/stop_words'
|
11
|
-
require 'meilisearch/index/synonyms'
|
4
|
+
require 'timeout'
|
12
5
|
|
13
6
|
module MeiliSearch
|
14
7
|
class Index < HTTPRequest
|
15
|
-
include MeiliSearch::Index::Base
|
16
|
-
include MeiliSearch::Index::Documents
|
17
|
-
include MeiliSearch::Index::Search
|
18
|
-
include MeiliSearch::Index::Stats
|
19
|
-
include MeiliSearch::Index::Settings
|
20
|
-
include MeiliSearch::Index::Updates
|
21
|
-
include MeiliSearch::Index::StopWords
|
22
|
-
include MeiliSearch::Index::Synonyms
|
23
|
-
|
24
8
|
attr_reader :uid
|
25
9
|
|
26
10
|
def initialize(index_uid, url, api_key = nil)
|
@@ -28,9 +12,262 @@ module MeiliSearch
|
|
28
12
|
super(url, api_key)
|
29
13
|
end
|
30
14
|
|
15
|
+
def show
|
16
|
+
http_get "/indexes/#{@uid}"
|
17
|
+
end
|
18
|
+
alias show_index show
|
19
|
+
|
20
|
+
def update(body)
|
21
|
+
http_put "/indexes/#{@uid}", body
|
22
|
+
end
|
23
|
+
alias update_index update
|
24
|
+
|
25
|
+
def delete
|
26
|
+
http_delete "/indexes/#{@uid}"
|
27
|
+
end
|
28
|
+
alias delete_index delete
|
29
|
+
|
31
30
|
def primary_key
|
32
31
|
show['primaryKey']
|
33
32
|
end
|
34
33
|
alias get_primary_key primary_key
|
34
|
+
|
35
|
+
### DOCUMENTS
|
36
|
+
|
37
|
+
def document(document_id)
|
38
|
+
encode_document = URI.encode_www_form_component(document_id)
|
39
|
+
http_get "/indexes/#{@uid}/documents/#{encode_document}"
|
40
|
+
end
|
41
|
+
alias get_document document
|
42
|
+
alias get_one_document document
|
43
|
+
|
44
|
+
def documents(options = {})
|
45
|
+
http_get "/indexes/#{@uid}/documents", options
|
46
|
+
end
|
47
|
+
alias get_documents documents
|
48
|
+
|
49
|
+
def add_documents(documents, primary_key = nil)
|
50
|
+
documents = [documents] if documents.is_a?(Hash)
|
51
|
+
http_post "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact
|
52
|
+
end
|
53
|
+
alias replace_documents add_documents
|
54
|
+
alias add_or_replace_documents add_documents
|
55
|
+
|
56
|
+
def update_documents(documents, primary_key = nil)
|
57
|
+
documents = [documents] if documents.is_a?(Hash)
|
58
|
+
http_put "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact
|
59
|
+
end
|
60
|
+
alias add_or_update_documents update_documents
|
61
|
+
|
62
|
+
def delete_documents(documents_ids)
|
63
|
+
if documents_ids.is_a?(Array)
|
64
|
+
http_post "/indexes/#{@uid}/documents/delete-batch", documents_ids
|
65
|
+
else
|
66
|
+
delete_document(documents_ids)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
alias delete_multiple_documents delete_documents
|
70
|
+
|
71
|
+
def delete_document(document_id)
|
72
|
+
encode_document = URI.encode_www_form_component(document_id)
|
73
|
+
http_delete "/indexes/#{@uid}/documents/#{encode_document}"
|
74
|
+
end
|
75
|
+
alias delete_one_document delete_document
|
76
|
+
|
77
|
+
def delete_all_documents
|
78
|
+
http_delete "/indexes/#{@uid}/documents"
|
79
|
+
end
|
80
|
+
|
81
|
+
### SEARCH
|
82
|
+
|
83
|
+
def search(query, options = {})
|
84
|
+
parsed_options = options.transform_keys(&:to_sym).map do |k, v|
|
85
|
+
if [:facetFilters, :facetsDistribution].include?(k)
|
86
|
+
[k, v.inspect]
|
87
|
+
elsif v.is_a?(Array)
|
88
|
+
[k, v.join(',')]
|
89
|
+
else
|
90
|
+
[k, v]
|
91
|
+
end
|
92
|
+
end.to_h
|
93
|
+
http_get "/indexes/#{@uid}/search", { q: query }.merge(parsed_options)
|
94
|
+
end
|
95
|
+
|
96
|
+
### UPDATES
|
97
|
+
|
98
|
+
def get_update_status(update_id)
|
99
|
+
http_get "/indexes/#{@uid}/updates/#{update_id}"
|
100
|
+
end
|
101
|
+
|
102
|
+
def get_all_update_status
|
103
|
+
http_get "/indexes/#{@uid}/updates"
|
104
|
+
end
|
105
|
+
|
106
|
+
def wait_for_pending_update(update_id, timeout_in_ms = 5000, interval_in_ms = 50)
|
107
|
+
Timeout.timeout(timeout_in_ms.to_f / 1000) do
|
108
|
+
loop do
|
109
|
+
get_update = get_update_status(update_id)
|
110
|
+
return get_update if get_update['status'] != 'enqueued'
|
111
|
+
|
112
|
+
sleep interval_in_ms.to_f / 1000
|
113
|
+
end
|
114
|
+
end
|
115
|
+
rescue Timeout::Error
|
116
|
+
raise MeiliSearch::MeiliSearchTimeoutError
|
117
|
+
end
|
118
|
+
|
119
|
+
### STATS
|
120
|
+
|
121
|
+
def stats
|
122
|
+
http_get "/indexes/#{@uid}/stats"
|
123
|
+
end
|
124
|
+
|
125
|
+
def number_of_documents
|
126
|
+
stats['numberOfDocuments']
|
127
|
+
end
|
128
|
+
|
129
|
+
def indexing?
|
130
|
+
stats['isIndexing']
|
131
|
+
end
|
132
|
+
|
133
|
+
def last_update
|
134
|
+
stats['lastUpdate']
|
135
|
+
end
|
136
|
+
|
137
|
+
def fields_distribution
|
138
|
+
stats['fieldsDistribution']
|
139
|
+
end
|
140
|
+
|
141
|
+
### SETTINGS - GENERAL
|
142
|
+
|
143
|
+
def settings
|
144
|
+
http_get "/indexes/#{@uid}/settings"
|
145
|
+
end
|
146
|
+
alias get_settings settings
|
147
|
+
|
148
|
+
def update_settings(settings)
|
149
|
+
http_post "/indexes/#{@uid}/settings", settings
|
150
|
+
end
|
151
|
+
|
152
|
+
def reset_settings
|
153
|
+
http_delete "/indexes/#{@uid}/settings"
|
154
|
+
end
|
155
|
+
|
156
|
+
### SETTINGS - RANKING RULES
|
157
|
+
|
158
|
+
def ranking_rules
|
159
|
+
http_get "/indexes/#{@uid}/settings/ranking-rules"
|
160
|
+
end
|
161
|
+
alias get_ranking_rules ranking_rules
|
162
|
+
|
163
|
+
def update_ranking_rules(ranking_rules)
|
164
|
+
http_post "/indexes/#{@uid}/settings/ranking-rules", ranking_rules
|
165
|
+
end
|
166
|
+
|
167
|
+
def reset_ranking_rules
|
168
|
+
http_delete "/indexes/#{@uid}/settings/ranking-rules"
|
169
|
+
end
|
170
|
+
|
171
|
+
### SETTINGS - SYNONYMS
|
172
|
+
|
173
|
+
def synonyms
|
174
|
+
http_get "/indexes/#{@uid}/settings/synonyms"
|
175
|
+
end
|
176
|
+
alias get_synonyms synonyms
|
177
|
+
|
178
|
+
def update_synonyms(synonyms)
|
179
|
+
http_post "/indexes/#{@uid}/settings/synonyms", synonyms
|
180
|
+
end
|
181
|
+
|
182
|
+
def reset_synonyms
|
183
|
+
http_delete "/indexes/#{@uid}/settings/synonyms"
|
184
|
+
end
|
185
|
+
|
186
|
+
### SETTINGS - STOP-WORDS
|
187
|
+
|
188
|
+
def stop_words
|
189
|
+
http_get "/indexes/#{@uid}/settings/stop-words"
|
190
|
+
end
|
191
|
+
alias get_stop_words stop_words
|
192
|
+
|
193
|
+
def update_stop_words(stop_words)
|
194
|
+
body = stop_words.is_a?(Array) ? stop_words : [stop_words]
|
195
|
+
http_post "/indexes/#{@uid}/settings/stop-words", body
|
196
|
+
end
|
197
|
+
|
198
|
+
def reset_stop_words
|
199
|
+
http_delete "/indexes/#{@uid}/settings/stop-words"
|
200
|
+
end
|
201
|
+
|
202
|
+
### SETTINGS - DINSTINCT ATTRIBUTE
|
203
|
+
|
204
|
+
def distinct_attribute
|
205
|
+
http_get "/indexes/#{@uid}/settings/distinct-attribute"
|
206
|
+
end
|
207
|
+
alias get_distinct_attribute distinct_attribute
|
208
|
+
|
209
|
+
def update_distinct_attribute(distinct_attribute)
|
210
|
+
http_post "/indexes/#{@uid}/settings/distinct-attribute", distinct_attribute
|
211
|
+
end
|
212
|
+
|
213
|
+
def reset_distinct_attribute
|
214
|
+
http_delete "/indexes/#{@uid}/settings/distinct-attribute"
|
215
|
+
end
|
216
|
+
|
217
|
+
### SETTINGS - SEARCHABLE ATTRIBUTES
|
218
|
+
|
219
|
+
def searchable_attributes
|
220
|
+
http_get "/indexes/#{@uid}/settings/searchable-attributes"
|
221
|
+
end
|
222
|
+
alias get_searchable_attributes searchable_attributes
|
223
|
+
|
224
|
+
def update_searchable_attributes(searchable_attributes)
|
225
|
+
http_post "/indexes/#{@uid}/settings/searchable-attributes", searchable_attributes
|
226
|
+
end
|
227
|
+
|
228
|
+
def reset_searchable_attributes
|
229
|
+
http_delete "/indexes/#{@uid}/settings/searchable-attributes"
|
230
|
+
end
|
231
|
+
|
232
|
+
### SETTINGS - DISPLAYED ATTRIBUTES
|
233
|
+
|
234
|
+
def displayed_attributes
|
235
|
+
http_get "/indexes/#{@uid}/settings/displayed-attributes"
|
236
|
+
end
|
237
|
+
alias get_displayed_attributes displayed_attributes
|
238
|
+
|
239
|
+
def update_displayed_attributes(displayed_attributes)
|
240
|
+
http_post "/indexes/#{@uid}/settings/displayed-attributes", displayed_attributes
|
241
|
+
end
|
242
|
+
|
243
|
+
def reset_displayed_attributes
|
244
|
+
http_delete "/indexes/#{@uid}/settings/displayed-attributes"
|
245
|
+
end
|
246
|
+
|
247
|
+
### SETTINGS - ACCEPT NEW FIELS VALUE
|
248
|
+
|
249
|
+
def accept_new_fields
|
250
|
+
http_get "/indexes/#{@uid}/settings/accept-new-fields"
|
251
|
+
end
|
252
|
+
alias get_accept_new_fields accept_new_fields
|
253
|
+
|
254
|
+
def update_accept_new_fields(accept_new_fields)
|
255
|
+
http_post "/indexes/#{@uid}/settings/accept-new-fields", accept_new_fields
|
256
|
+
end
|
257
|
+
|
258
|
+
### SETTINGS - ATTRIBUTES FOR FACETING
|
259
|
+
|
260
|
+
def attributes_for_faceting
|
261
|
+
http_get "/indexes/#{@uid}/settings/attributes-for-faceting"
|
262
|
+
end
|
263
|
+
alias get_attributes_for_faceting attributes_for_faceting
|
264
|
+
|
265
|
+
def update_attributes_for_faceting(attributes_for_faceting)
|
266
|
+
http_post "/indexes/#{@uid}/settings/attributes-for-faceting", attributes_for_faceting
|
267
|
+
end
|
268
|
+
|
269
|
+
def reset_attributes_for_faceting
|
270
|
+
http_delete "/indexes/#{@uid}/settings/attributes-for-faceting"
|
271
|
+
end
|
35
272
|
end
|
36
273
|
end
|
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.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Meili
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -38,21 +38,9 @@ extra_rdoc_files: []
|
|
38
38
|
files:
|
39
39
|
- lib/meilisearch.rb
|
40
40
|
- lib/meilisearch/client.rb
|
41
|
-
- lib/meilisearch/client/health.rb
|
42
|
-
- lib/meilisearch/client/indexes.rb
|
43
|
-
- lib/meilisearch/client/keys.rb
|
44
|
-
- lib/meilisearch/client/stats.rb
|
45
41
|
- lib/meilisearch/error.rb
|
46
42
|
- lib/meilisearch/http_request.rb
|
47
43
|
- lib/meilisearch/index.rb
|
48
|
-
- lib/meilisearch/index/base.rb
|
49
|
-
- lib/meilisearch/index/documents.rb
|
50
|
-
- lib/meilisearch/index/search.rb
|
51
|
-
- lib/meilisearch/index/settings.rb
|
52
|
-
- lib/meilisearch/index/stats.rb
|
53
|
-
- lib/meilisearch/index/stop_words.rb
|
54
|
-
- lib/meilisearch/index/synonyms.rb
|
55
|
-
- lib/meilisearch/index/updates.rb
|
56
44
|
- lib/meilisearch/version.rb
|
57
45
|
homepage: https://github.com/meilisearch/meilisearch-ruby
|
58
46
|
licenses:
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MeiliSearch
|
4
|
-
class Client < HTTPRequest
|
5
|
-
module Health
|
6
|
-
def healthy?
|
7
|
-
http_get '/health'
|
8
|
-
true
|
9
|
-
rescue StandardError
|
10
|
-
false
|
11
|
-
end
|
12
|
-
|
13
|
-
def health
|
14
|
-
http_get '/health'
|
15
|
-
end
|
16
|
-
|
17
|
-
def update_health(bool)
|
18
|
-
http_put '/health', health: bool
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MeiliSearch
|
4
|
-
class Client < HTTPRequest
|
5
|
-
module Indexes
|
6
|
-
def indexes
|
7
|
-
http_get '/indexes'
|
8
|
-
end
|
9
|
-
|
10
|
-
def show_index(index_uid)
|
11
|
-
index_object(index_uid).show
|
12
|
-
end
|
13
|
-
|
14
|
-
# Usage:
|
15
|
-
# create_index('indexUID')
|
16
|
-
# create_index(uid: 'indexUID')
|
17
|
-
# create_index(uid: 'indexUID', primaryKey: 'id')
|
18
|
-
def create_index(attributes)
|
19
|
-
body = if attributes.is_a?(Hash)
|
20
|
-
attributes
|
21
|
-
else
|
22
|
-
{ uid: attributes }
|
23
|
-
end
|
24
|
-
res = http_post '/indexes', body
|
25
|
-
index_object(res['uid'])
|
26
|
-
end
|
27
|
-
|
28
|
-
def delete_index(index_uid)
|
29
|
-
index_object(index_uid).delete
|
30
|
-
end
|
31
|
-
|
32
|
-
# Usage:
|
33
|
-
# index('indexUID')
|
34
|
-
# index(uid: 'indexUID')
|
35
|
-
def index(attribute)
|
36
|
-
uid = attribute.is_a?(Hash) ? attribute[:uid] : attribute
|
37
|
-
raise IndexUidError if uid.nil?
|
38
|
-
|
39
|
-
index_object(uid)
|
40
|
-
end
|
41
|
-
alias get_index index
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def index_object(uid)
|
46
|
-
Index.new(uid, @base_url, @api_key)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MeiliSearch
|
4
|
-
class Client < HTTPRequest
|
5
|
-
module Stats
|
6
|
-
def version
|
7
|
-
http_get '/version'
|
8
|
-
end
|
9
|
-
|
10
|
-
def sysinfo
|
11
|
-
http_get '/sys-info'
|
12
|
-
end
|
13
|
-
|
14
|
-
def pretty_sysinfo
|
15
|
-
http_get '/sys-info/pretty'
|
16
|
-
end
|
17
|
-
|
18
|
-
def stats
|
19
|
-
http_get '/stats'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MeiliSearch
|
4
|
-
class Index < HTTPRequest
|
5
|
-
module Base
|
6
|
-
def show
|
7
|
-
http_get "/indexes/#{@uid}"
|
8
|
-
end
|
9
|
-
alias show_index show
|
10
|
-
|
11
|
-
def update(body)
|
12
|
-
http_put "/indexes/#{@uid}", body
|
13
|
-
end
|
14
|
-
alias update_index update
|
15
|
-
|
16
|
-
def delete
|
17
|
-
http_delete "/indexes/#{@uid}"
|
18
|
-
end
|
19
|
-
alias delete_index delete
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MeiliSearch
|
4
|
-
class Index < HTTPRequest
|
5
|
-
module Documents
|
6
|
-
def document(document_id)
|
7
|
-
encode_document = URI.encode_www_form_component(document_id)
|
8
|
-
http_get "/indexes/#{@uid}/documents/#{encode_document}"
|
9
|
-
end
|
10
|
-
alias get_document document
|
11
|
-
alias get_one_document document
|
12
|
-
|
13
|
-
def documents(options = {})
|
14
|
-
http_get "/indexes/#{@uid}/documents", options
|
15
|
-
end
|
16
|
-
alias get_documents documents
|
17
|
-
|
18
|
-
def add_documents(documents, primary_key = nil)
|
19
|
-
documents = [documents] if documents.is_a?(Hash)
|
20
|
-
http_post "/indexes/#{@uid}/documents", documents, primaryKey: primary_key
|
21
|
-
end
|
22
|
-
alias replace_documents add_documents
|
23
|
-
alias add_or_replace_documents add_documents
|
24
|
-
|
25
|
-
def update_documents(documents, primary_key = nil)
|
26
|
-
documents = [documents] if documents.is_a?(Hash)
|
27
|
-
http_put "/indexes/#{@uid}/documents", documents, primaryKey: primary_key
|
28
|
-
end
|
29
|
-
alias add_or_update_documents update_documents
|
30
|
-
|
31
|
-
def delete_documents(documents_ids)
|
32
|
-
if documents_ids.is_a?(Array)
|
33
|
-
http_post "/indexes/#{@uid}/documents/delete-batch", documents_ids
|
34
|
-
else
|
35
|
-
delete_document(documents_ids)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
alias delete_multiple_documents delete_documents
|
39
|
-
|
40
|
-
def delete_document(document_id)
|
41
|
-
encode_document = URI.encode_www_form_component(document_id)
|
42
|
-
http_delete "/indexes/#{@uid}/documents/#{encode_document}"
|
43
|
-
end
|
44
|
-
alias delete_one_document delete_document
|
45
|
-
|
46
|
-
def delete_all_documents
|
47
|
-
http_delete "/indexes/#{@uid}/documents"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MeiliSearch
|
4
|
-
class Index < HTTPRequest
|
5
|
-
module Settings
|
6
|
-
# General routes
|
7
|
-
def settings
|
8
|
-
http_get "/indexes/#{@uid}/settings"
|
9
|
-
end
|
10
|
-
alias get_settings settings
|
11
|
-
|
12
|
-
def update_settings(settings)
|
13
|
-
http_post "/indexes/#{@uid}/settings", settings
|
14
|
-
end
|
15
|
-
|
16
|
-
def reset_settings
|
17
|
-
http_delete "/indexes/#{@uid}/settings"
|
18
|
-
end
|
19
|
-
|
20
|
-
# Sub-routes ranking rules
|
21
|
-
def ranking_rules
|
22
|
-
http_get "/indexes/#{@uid}/settings/ranking-rules"
|
23
|
-
end
|
24
|
-
alias get_ranking_rules ranking_rules
|
25
|
-
|
26
|
-
def update_ranking_rules(ranking_rules)
|
27
|
-
http_post "/indexes/#{@uid}/settings/ranking-rules", ranking_rules
|
28
|
-
end
|
29
|
-
|
30
|
-
def reset_ranking_rules
|
31
|
-
http_delete "/indexes/#{@uid}/settings/ranking-rules"
|
32
|
-
end
|
33
|
-
|
34
|
-
# Sub-routes distinct attribute
|
35
|
-
def distinct_attribute
|
36
|
-
http_get "/indexes/#{@uid}/settings/distinct-attribute"
|
37
|
-
end
|
38
|
-
alias get_distinct_attribute distinct_attribute
|
39
|
-
|
40
|
-
def update_distinct_attribute(distinct_attribute)
|
41
|
-
http_post "/indexes/#{@uid}/settings/distinct-attribute", distinct_attribute
|
42
|
-
end
|
43
|
-
|
44
|
-
def reset_distinct_attribute
|
45
|
-
http_delete "/indexes/#{@uid}/settings/distinct-attribute"
|
46
|
-
end
|
47
|
-
|
48
|
-
# Sub-routes searchable attributes
|
49
|
-
def searchable_attributes
|
50
|
-
http_get "/indexes/#{@uid}/settings/searchable-attributes"
|
51
|
-
end
|
52
|
-
alias get_searchable_attributes searchable_attributes
|
53
|
-
|
54
|
-
def update_searchable_attributes(searchable_attributes)
|
55
|
-
http_post "/indexes/#{@uid}/settings/searchable-attributes", searchable_attributes
|
56
|
-
end
|
57
|
-
|
58
|
-
def reset_searchable_attributes
|
59
|
-
http_delete "/indexes/#{@uid}/settings/searchable-attributes"
|
60
|
-
end
|
61
|
-
|
62
|
-
# Sub-routes displayed attributes
|
63
|
-
def displayed_attributes
|
64
|
-
http_get "/indexes/#{@uid}/settings/displayed-attributes"
|
65
|
-
end
|
66
|
-
alias get_displayed_attributes displayed_attributes
|
67
|
-
|
68
|
-
def update_displayed_attributes(displayed_attributes)
|
69
|
-
http_post "/indexes/#{@uid}/settings/displayed-attributes", displayed_attributes
|
70
|
-
end
|
71
|
-
|
72
|
-
def reset_displayed_attributes
|
73
|
-
http_delete "/indexes/#{@uid}/settings/displayed-attributes"
|
74
|
-
end
|
75
|
-
|
76
|
-
# Sub-routes accept-new-fields
|
77
|
-
def accept_new_fields
|
78
|
-
http_get "/indexes/#{@uid}/settings/accept-new-fields"
|
79
|
-
end
|
80
|
-
alias get_accept_new_fields accept_new_fields
|
81
|
-
|
82
|
-
def update_accept_new_fields(accept_new_fields)
|
83
|
-
http_post "/indexes/#{@uid}/settings/accept-new-fields", accept_new_fields
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MeiliSearch
|
4
|
-
class Index < HTTPRequest
|
5
|
-
module Stats
|
6
|
-
def stats
|
7
|
-
http_get "/indexes/#{@uid}/stats"
|
8
|
-
end
|
9
|
-
|
10
|
-
def number_of_documents
|
11
|
-
stats['numberOfDocuments']
|
12
|
-
end
|
13
|
-
|
14
|
-
def indexing?
|
15
|
-
stats['isIndexing']
|
16
|
-
end
|
17
|
-
|
18
|
-
def last_update
|
19
|
-
stats['lastUpdate']
|
20
|
-
end
|
21
|
-
|
22
|
-
def fields_frequency
|
23
|
-
stats['fieldsFrequency']
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MeiliSearch
|
4
|
-
class Index < HTTPRequest
|
5
|
-
module StopWords
|
6
|
-
def stop_words
|
7
|
-
http_get "/indexes/#{@uid}/settings/stop-words"
|
8
|
-
end
|
9
|
-
alias get_stop_words stop_words
|
10
|
-
|
11
|
-
def update_stop_words(stop_words)
|
12
|
-
body = stop_words.is_a?(Array) ? stop_words : [stop_words]
|
13
|
-
http_post "/indexes/#{@uid}/settings/stop-words", body
|
14
|
-
end
|
15
|
-
|
16
|
-
def reset_stop_words
|
17
|
-
http_delete "/indexes/#{@uid}/settings/stop-words"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MeiliSearch
|
4
|
-
class Index < HTTPRequest
|
5
|
-
module Synonyms
|
6
|
-
def synonyms
|
7
|
-
http_get "/indexes/#{@uid}/settings/synonyms"
|
8
|
-
end
|
9
|
-
alias get_synonyms synonyms
|
10
|
-
|
11
|
-
def update_synonyms(synonyms)
|
12
|
-
http_post "/indexes/#{@uid}/settings/synonyms", synonyms
|
13
|
-
end
|
14
|
-
|
15
|
-
def reset_synonyms
|
16
|
-
http_delete "/indexes/#{@uid}/settings/synonyms"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module MeiliSearch
|
4
|
-
class Index < HTTPRequest
|
5
|
-
module Updates
|
6
|
-
def get_update_status(update_id)
|
7
|
-
http_get "/indexes/#{@uid}/updates/#{update_id}"
|
8
|
-
end
|
9
|
-
|
10
|
-
def get_all_update_status
|
11
|
-
http_get "/indexes/#{@uid}/updates"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|