meilisearch 0.9.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/meilisearch/client.rb +78 -8
- data/lib/meilisearch/error.rb +48 -24
- data/lib/meilisearch/http_request.rb +39 -43
- data/lib/meilisearch/index.rb +235 -17
- data/lib/meilisearch/version.rb +1 -1
- metadata +10 -16
- 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: 92d1afdaa529593e643fa0e297bf3b8d56671c2163937fb5f30e1dd0193f2725
|
4
|
+
data.tar.gz: f7849b8a8a9343a706c05b74e23c1959c330bde18bb8366ba04adf6efa9577b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f887ad9f507f236fe54a6f56df028c4d33e3e730d1d56c886e774b1cf055b6aa153fe2ec51a3ad5f775309027deaa9c496de2da8e6bfd988efffa046097f346
|
7
|
+
data.tar.gz: 433afbfd38336ef77cd8bb6538dd7ebf3a100d14b8f436236b907c968eaa7875372863bf90d32272404af01395e8968f50f65aed8a7674e0ad9f132798b48d58
|
data/lib/meilisearch/client.rb
CHANGED
@@ -1,16 +1,86 @@
|
|
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 = options.merge(uid: index_uid)
|
22
|
+
res = http_post '/indexes', body
|
23
|
+
index_object(res['uid'])
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_or_create_index(index_uid, options = {})
|
27
|
+
begin
|
28
|
+
create_index(index_uid, options)
|
29
|
+
rescue ApiError => e
|
30
|
+
raise e unless e.code == 'index_already_exists'
|
31
|
+
end
|
32
|
+
index_object(index_uid)
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete_index(index_uid)
|
36
|
+
index_object(index_uid).delete
|
37
|
+
end
|
38
|
+
|
39
|
+
# Usage:
|
40
|
+
# client.index('indexUID')
|
41
|
+
def index(index_uid)
|
42
|
+
index_object(index_uid)
|
43
|
+
end
|
44
|
+
alias get_index index
|
45
|
+
|
46
|
+
### KEYS
|
47
|
+
|
48
|
+
def keys
|
49
|
+
http_get '/keys'
|
50
|
+
end
|
51
|
+
alias get_keys keys
|
52
|
+
|
53
|
+
### HEALTH
|
54
|
+
|
55
|
+
def healthy?
|
56
|
+
http_get '/health'
|
57
|
+
true
|
58
|
+
rescue StandardError
|
59
|
+
false
|
60
|
+
end
|
61
|
+
|
62
|
+
def health
|
63
|
+
http_get '/health'
|
64
|
+
end
|
65
|
+
|
66
|
+
def update_health(bool)
|
67
|
+
http_put '/health', health: bool
|
68
|
+
end
|
69
|
+
|
70
|
+
### STATS
|
71
|
+
|
72
|
+
def version
|
73
|
+
http_get '/version'
|
74
|
+
end
|
75
|
+
|
76
|
+
def stats
|
77
|
+
http_get '/stats'
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def index_object(uid)
|
83
|
+
Index.new(uid, @base_url, @api_key)
|
84
|
+
end
|
15
85
|
end
|
16
86
|
end
|
data/lib/meilisearch/error.rb
CHANGED
@@ -1,34 +1,58 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module MeiliSearch
|
4
|
-
class
|
5
|
-
|
4
|
+
class ApiError < StandardError
|
5
|
+
attr_reader :http_code # e.g. 400, 404...
|
6
|
+
attr_reader :http_message # e.g. Bad Request, Not Found...
|
7
|
+
attr_reader :http_body # The response body received from the MeiliSearch API
|
8
|
+
attr_reader :ms_code # The error code given by the MeiliSearch API
|
9
|
+
attr_reader :ms_type # The error type given by the MeiliSearch API
|
10
|
+
attr_reader :ms_link # The documentation link given by the MeiliSearch API
|
11
|
+
attr_reader :ms_message # The error message given by the MeiliSearch API
|
12
|
+
attr_reader :message # The detailed error message of this error class
|
6
13
|
|
7
|
-
|
8
|
-
|
14
|
+
alias code ms_code
|
15
|
+
alias type ms_type
|
16
|
+
alias link ms_link
|
17
|
+
|
18
|
+
def initialize(http_code, http_message, http_body)
|
19
|
+
get_meilisearch_error_info(http_body) unless http_body.nil? || http_body.empty?
|
20
|
+
@http_code = http_code
|
21
|
+
@http_message = http_message
|
22
|
+
@ms_message ||= 'MeiliSearch API has not returned any error message'
|
23
|
+
@ms_link ||= '<no documentation link found>'
|
24
|
+
@message = "#{http_code} #{http_message} - #{@ms_message}. See #{ms_link}."
|
25
|
+
super(details)
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_meilisearch_error_info(http_body)
|
29
|
+
@http_body = JSON.parse(http_body)
|
30
|
+
@ms_code = @http_body['errorCode']
|
31
|
+
@ms_message = @http_body['message']
|
32
|
+
@ms_type = @http_body['errorType']
|
33
|
+
@ms_link = @http_body['errorLink']
|
34
|
+
end
|
35
|
+
|
36
|
+
def details
|
37
|
+
"MeiliSearch::ApiError - code: #{@ms_code} - type: #{ms_type} - message: #{@ms_message} - link: #{ms_link}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class CommunicationError < StandardError
|
9
42
|
attr_reader :message
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
alias code status
|
15
|
-
alias body http_body
|
16
|
-
alias body_message http_body_message
|
17
|
-
|
18
|
-
def initialize(status, message, http_body, details = nil)
|
19
|
-
@status = status
|
20
|
-
unless http_body.nil? || http_body.empty?
|
21
|
-
@http_body = JSON.parse(http_body)
|
22
|
-
@http_body_message = @http_body['message']
|
23
|
-
end
|
24
|
-
@message = message.capitalize
|
25
|
-
@message = "#{@message} - #{@http_body_message.capitalize}" unless @http_body_message.nil?
|
26
|
-
@details = details
|
43
|
+
|
44
|
+
def initialize(message)
|
45
|
+
@message = "An error occurred while trying to connect to the MeiliSearch instance: #{message}"
|
46
|
+
super(@message)
|
27
47
|
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class TimeoutError < StandardError
|
51
|
+
attr_reader :message
|
28
52
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
53
|
+
def initialize
|
54
|
+
@message = 'The update was not processed in the expected time'
|
55
|
+
super(@message)
|
32
56
|
end
|
33
57
|
end
|
34
58
|
end
|
@@ -16,67 +16,63 @@ module MeiliSearch
|
|
16
16
|
}.compact
|
17
17
|
end
|
18
18
|
|
19
|
-
def http_get(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
timeout: 1
|
19
|
+
def http_get(relative_path = '', query_params = {})
|
20
|
+
send_request(
|
21
|
+
proc { |path, config| self.class.get(path, config) },
|
22
|
+
relative_path,
|
23
|
+
query_params
|
25
24
|
)
|
26
|
-
validate(response)
|
27
25
|
end
|
28
26
|
|
29
|
-
def http_post(
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
timeout: 1
|
36
|
-
}.compact
|
37
|
-
response = self.class.post(
|
38
|
-
@base_url + path,
|
39
|
-
params
|
27
|
+
def http_post(relative_path = '', body = nil, query_params = nil)
|
28
|
+
send_request(
|
29
|
+
proc { |path, config| self.class.post(path, config) },
|
30
|
+
relative_path,
|
31
|
+
query_params,
|
32
|
+
body
|
40
33
|
)
|
41
|
-
validate(response)
|
42
34
|
end
|
43
35
|
|
44
|
-
def http_put(
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
headers: @headers,
|
51
|
-
timeout: 1
|
36
|
+
def http_put(relative_path = '', body = nil, query_params = nil)
|
37
|
+
send_request(
|
38
|
+
proc { |path, config| self.class.put(path, config) },
|
39
|
+
relative_path,
|
40
|
+
query_params,
|
41
|
+
body
|
52
42
|
)
|
53
|
-
validate(response)
|
54
43
|
end
|
55
44
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
body: body,
|
61
|
-
headers: @headers,
|
62
|
-
timeout: 1
|
45
|
+
def http_delete(relative_path = '')
|
46
|
+
send_request(
|
47
|
+
proc { |path, config| self.class.delete(path, config) },
|
48
|
+
relative_path
|
63
49
|
)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def send_request(http_method, relative_path, query_params = nil, body = nil)
|
55
|
+
config = http_config(query_params, body)
|
56
|
+
begin
|
57
|
+
response = http_method.call(@base_url + relative_path, config)
|
58
|
+
rescue Errno::ECONNREFUSED => e
|
59
|
+
raise CommunicationError, e.message
|
60
|
+
end
|
64
61
|
validate(response)
|
65
62
|
end
|
66
63
|
|
67
|
-
def
|
68
|
-
|
69
|
-
|
64
|
+
def http_config(query_params, body)
|
65
|
+
body = body.to_json unless body.nil?
|
66
|
+
{
|
70
67
|
headers: @headers,
|
68
|
+
query: query_params,
|
69
|
+
body: body,
|
71
70
|
timeout: 1
|
72
|
-
|
73
|
-
validate(response)
|
71
|
+
}.compact
|
74
72
|
end
|
75
73
|
|
76
|
-
private
|
77
|
-
|
78
74
|
def validate(response)
|
79
|
-
raise
|
75
|
+
raise ApiError.new(response.code, response.message, response.body) unless response.success?
|
80
76
|
|
81
77
|
response.parsed_response
|
82
78
|
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,243 @@ 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.compact
|
85
|
+
http_post "/indexes/#{@uid}/search", { q: query }.merge(parsed_options)
|
86
|
+
end
|
87
|
+
|
88
|
+
### UPDATES
|
89
|
+
|
90
|
+
def get_update_status(update_id)
|
91
|
+
http_get "/indexes/#{@uid}/updates/#{update_id}"
|
92
|
+
end
|
93
|
+
|
94
|
+
def get_all_update_status
|
95
|
+
http_get "/indexes/#{@uid}/updates"
|
96
|
+
end
|
97
|
+
|
98
|
+
def wait_for_pending_update(update_id, timeout_in_ms = 5000, interval_in_ms = 50)
|
99
|
+
Timeout.timeout(timeout_in_ms.to_f / 1000) do
|
100
|
+
loop do
|
101
|
+
get_update = get_update_status(update_id)
|
102
|
+
return get_update if get_update['status'] != 'enqueued'
|
103
|
+
|
104
|
+
sleep interval_in_ms.to_f / 1000
|
105
|
+
end
|
106
|
+
end
|
107
|
+
rescue Timeout::Error
|
108
|
+
raise MeiliSearch::TimeoutError
|
109
|
+
end
|
110
|
+
|
111
|
+
### STATS
|
112
|
+
|
113
|
+
def stats
|
114
|
+
http_get "/indexes/#{@uid}/stats"
|
115
|
+
end
|
116
|
+
|
117
|
+
def number_of_documents
|
118
|
+
stats['numberOfDocuments']
|
119
|
+
end
|
120
|
+
|
121
|
+
def indexing?
|
122
|
+
stats['isIndexing']
|
123
|
+
end
|
124
|
+
|
125
|
+
def last_update
|
126
|
+
stats['lastUpdate']
|
127
|
+
end
|
128
|
+
|
129
|
+
def fields_distribution
|
130
|
+
stats['fieldsDistribution']
|
131
|
+
end
|
132
|
+
|
133
|
+
### SETTINGS - GENERAL
|
134
|
+
|
135
|
+
def settings
|
136
|
+
http_get "/indexes/#{@uid}/settings"
|
137
|
+
end
|
138
|
+
alias get_settings settings
|
139
|
+
|
140
|
+
def update_settings(settings)
|
141
|
+
http_post "/indexes/#{@uid}/settings", settings
|
142
|
+
end
|
143
|
+
|
144
|
+
def reset_settings
|
145
|
+
http_delete "/indexes/#{@uid}/settings"
|
146
|
+
end
|
147
|
+
|
148
|
+
### SETTINGS - RANKING RULES
|
149
|
+
|
150
|
+
def ranking_rules
|
151
|
+
http_get "/indexes/#{@uid}/settings/ranking-rules"
|
152
|
+
end
|
153
|
+
alias get_ranking_rules ranking_rules
|
154
|
+
|
155
|
+
def update_ranking_rules(ranking_rules)
|
156
|
+
http_post "/indexes/#{@uid}/settings/ranking-rules", ranking_rules
|
157
|
+
end
|
158
|
+
|
159
|
+
def reset_ranking_rules
|
160
|
+
http_delete "/indexes/#{@uid}/settings/ranking-rules"
|
161
|
+
end
|
162
|
+
|
163
|
+
### SETTINGS - SYNONYMS
|
164
|
+
|
165
|
+
def synonyms
|
166
|
+
http_get "/indexes/#{@uid}/settings/synonyms"
|
167
|
+
end
|
168
|
+
alias get_synonyms synonyms
|
169
|
+
|
170
|
+
def update_synonyms(synonyms)
|
171
|
+
http_post "/indexes/#{@uid}/settings/synonyms", synonyms
|
172
|
+
end
|
173
|
+
|
174
|
+
def reset_synonyms
|
175
|
+
http_delete "/indexes/#{@uid}/settings/synonyms"
|
176
|
+
end
|
177
|
+
|
178
|
+
### SETTINGS - STOP-WORDS
|
179
|
+
|
180
|
+
def stop_words
|
181
|
+
http_get "/indexes/#{@uid}/settings/stop-words"
|
182
|
+
end
|
183
|
+
alias get_stop_words stop_words
|
184
|
+
|
185
|
+
def update_stop_words(stop_words)
|
186
|
+
body = stop_words.is_a?(Array) ? stop_words : [stop_words]
|
187
|
+
http_post "/indexes/#{@uid}/settings/stop-words", body
|
188
|
+
end
|
189
|
+
|
190
|
+
def reset_stop_words
|
191
|
+
http_delete "/indexes/#{@uid}/settings/stop-words"
|
192
|
+
end
|
193
|
+
|
194
|
+
### SETTINGS - DINSTINCT ATTRIBUTE
|
195
|
+
|
196
|
+
def distinct_attribute
|
197
|
+
http_get "/indexes/#{@uid}/settings/distinct-attribute"
|
198
|
+
end
|
199
|
+
alias get_distinct_attribute distinct_attribute
|
200
|
+
|
201
|
+
def update_distinct_attribute(distinct_attribute)
|
202
|
+
http_post "/indexes/#{@uid}/settings/distinct-attribute", distinct_attribute
|
203
|
+
end
|
204
|
+
|
205
|
+
def reset_distinct_attribute
|
206
|
+
http_delete "/indexes/#{@uid}/settings/distinct-attribute"
|
207
|
+
end
|
208
|
+
|
209
|
+
### SETTINGS - SEARCHABLE ATTRIBUTES
|
210
|
+
|
211
|
+
def searchable_attributes
|
212
|
+
http_get "/indexes/#{@uid}/settings/searchable-attributes"
|
213
|
+
end
|
214
|
+
alias get_searchable_attributes searchable_attributes
|
215
|
+
|
216
|
+
def update_searchable_attributes(searchable_attributes)
|
217
|
+
http_post "/indexes/#{@uid}/settings/searchable-attributes", searchable_attributes
|
218
|
+
end
|
219
|
+
|
220
|
+
def reset_searchable_attributes
|
221
|
+
http_delete "/indexes/#{@uid}/settings/searchable-attributes"
|
222
|
+
end
|
223
|
+
|
224
|
+
### SETTINGS - DISPLAYED ATTRIBUTES
|
225
|
+
|
226
|
+
def displayed_attributes
|
227
|
+
http_get "/indexes/#{@uid}/settings/displayed-attributes"
|
228
|
+
end
|
229
|
+
alias get_displayed_attributes displayed_attributes
|
230
|
+
|
231
|
+
def update_displayed_attributes(displayed_attributes)
|
232
|
+
http_post "/indexes/#{@uid}/settings/displayed-attributes", displayed_attributes
|
233
|
+
end
|
234
|
+
|
235
|
+
def reset_displayed_attributes
|
236
|
+
http_delete "/indexes/#{@uid}/settings/displayed-attributes"
|
237
|
+
end
|
238
|
+
|
239
|
+
### SETTINGS - ATTRIBUTES FOR FACETING
|
240
|
+
|
241
|
+
def attributes_for_faceting
|
242
|
+
http_get "/indexes/#{@uid}/settings/attributes-for-faceting"
|
243
|
+
end
|
244
|
+
alias get_attributes_for_faceting attributes_for_faceting
|
245
|
+
|
246
|
+
def update_attributes_for_faceting(attributes_for_faceting)
|
247
|
+
http_post "/indexes/#{@uid}/settings/attributes-for-faceting", attributes_for_faceting
|
248
|
+
end
|
249
|
+
|
250
|
+
def reset_attributes_for_faceting
|
251
|
+
http_delete "/indexes/#{@uid}/settings/attributes-for-faceting"
|
252
|
+
end
|
35
253
|
end
|
36
254
|
end
|
data/lib/meilisearch/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meilisearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.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-03
|
11
|
+
date: 2020-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.17.1
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.19.0
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 0.17.1
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.19.0
|
27
33
|
description: An easy-to-use ruby client for Meilisearch API. See https://github.com/meilisearch/MeiliSearch
|
28
34
|
email: bonjour@meilisearch.com
|
29
35
|
executables: []
|
@@ -32,21 +38,9 @@ extra_rdoc_files: []
|
|
32
38
|
files:
|
33
39
|
- lib/meilisearch.rb
|
34
40
|
- lib/meilisearch/client.rb
|
35
|
-
- lib/meilisearch/client/health.rb
|
36
|
-
- lib/meilisearch/client/indexes.rb
|
37
|
-
- lib/meilisearch/client/keys.rb
|
38
|
-
- lib/meilisearch/client/stats.rb
|
39
41
|
- lib/meilisearch/error.rb
|
40
42
|
- lib/meilisearch/http_request.rb
|
41
43
|
- lib/meilisearch/index.rb
|
42
|
-
- lib/meilisearch/index/base.rb
|
43
|
-
- lib/meilisearch/index/documents.rb
|
44
|
-
- lib/meilisearch/index/search.rb
|
45
|
-
- lib/meilisearch/index/settings.rb
|
46
|
-
- lib/meilisearch/index/stats.rb
|
47
|
-
- lib/meilisearch/index/stop_words.rb
|
48
|
-
- lib/meilisearch/index/synonyms.rb
|
49
|
-
- lib/meilisearch/index/updates.rb
|
50
44
|
- lib/meilisearch/version.rb
|
51
45
|
homepage: https://github.com/meilisearch/meilisearch-ruby
|
52
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
|