meilisearch 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c31820aca925f28c1e53011587a9f6f2d9dfd210425ee3e1bce4c6e2728cb655
4
- data.tar.gz: a74b7e2540093dc1f7fc65f5da4259cd2c07e17460ce2497be66899559cd0137
3
+ metadata.gz: 9a36df5bca77a8d8487a6cfdf12ef055db52aec77d25d0a522e4fecb455d8714
4
+ data.tar.gz: e6a5b012fa2d4099be7ce43e5790ee032d612d68ce7fbcf697a6928458a23e51
5
5
  SHA512:
6
- metadata.gz: 9b07704bb782d34b98b68b39e6a243f2882e22bc088e1ea3d66ca89f5371efa6843aa7a9b58251d3a9d0acb68825b65e61037a70f9b1ca0cd0e7e6a614aad5a3
7
- data.tar.gz: c3a1018f981315a8e55135074ac88c688e94c8fab6ce0d2544c0db587d3ba3e9a91e24771455ddf32716c283931092c751ce4d7a413b45e9a26deaf4894f153e
6
+ metadata.gz: 37cba34617de2798ff77d3f5bd711862a84a14cbea9dca44349897dacff37f004184e6b71fad314ddefc3ce6a1cbcb124c5c9ed85781d7ee2028385bc20d3418
7
+ data.tar.gz: ce410e17029be8a779f10921aef8b28200dd3ae2fc1cb3924bbb5085596a1adc70c2a5e4aed5492751dee3d6f1ab4dbbdc7186673fe1041d2b4875819ab3ab65
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'meilisearch/version'
4
4
  require 'meilisearch/client'
5
+ require 'meilisearch/index'
5
6
 
6
7
  module MeiliSearch
7
8
  end
@@ -1,86 +1,87 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'httparty'
4
-
5
- require 'meilisearch/error'
6
- require 'meilisearch/client/keys'
7
- require 'meilisearch/client/stats'
8
- require 'meilisearch/client/health'
9
- require 'meilisearch/client/indexes'
10
- require 'meilisearch/client/documents'
11
- require 'meilisearch/client/prepare'
12
- require 'meilisearch/client/search'
3
+ require 'meilisearch/http_request'
13
4
 
14
5
  module MeiliSearch
15
- class Client
16
- include HTTParty
17
-
18
- include MeiliSearch::Client::Keys
19
- include MeiliSearch::Client::Stats
20
- include MeiliSearch::Client::Health
21
- include MeiliSearch::Client::Indexes
22
- include MeiliSearch::Client::Documents
23
- include MeiliSearch::Client::Prepare
24
- include MeiliSearch::Client::Search
25
-
26
- def initialize(url, api_key = nil)
27
- # api_key is is for basic api authorization
28
- @headers = {}
29
- @headers['X-Meili-Api-Key'] = api_key if api_key
30
- @headers['Content-Type'] = 'application/json'
31
- @base_url = url
6
+ class Client < HTTPRequest
7
+ ### INDEXES
8
+
9
+ def indexes
10
+ http_get '/indexes'
32
11
  end
33
12
 
34
- def get(path = '', query = {})
35
- response = self.class.get(
36
- (@base_url + path),
37
- query: query,
38
- headers: @headers
39
- )
40
- validate(response)
13
+ def show_index(index_uid)
14
+ index_object(index_uid).show
41
15
  end
42
16
 
43
- def post(path = '', body = nil)
44
- if body.nil?
45
- response = self.class.post(
46
- (@base_url + path),
47
- headers: @headers
48
- )
49
- else
50
- response = self.class.post(
51
- (@base_url + path),
52
- body: body.to_json,
53
- headers: @headers
54
- )
55
- end
56
- validate(response)
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'])
57
24
  end
58
25
 
59
- def put(path = '', body = {})
60
- response = self.class.put(
61
- (@base_url + path),
62
- body: body.to_json,
63
- headers: @headers
64
- )
65
- validate(response)
26
+ def delete_index(index_uid)
27
+ index_object(index_uid).delete
66
28
  end
67
29
 
68
- def delete(path = '')
69
- response = self.class.delete(
70
- (@base_url + path),
71
- headers: @headers
72
- )
73
- validate(response)
30
+ # Usage:
31
+ # client.index('indexUID')
32
+ def index(index_uid)
33
+ raise IndexUidError if index_uid.nil?
34
+
35
+ index_object(index_uid)
74
36
  end
37
+ alias get_index index
75
38
 
76
- private
39
+ ### KEYS
40
+
41
+ def keys
42
+ http_get '/keys'
43
+ end
44
+ alias get_keys keys
77
45
 
78
- def validate(response)
79
- unless response.success?
80
- raise ClientError, "#{response.code}: #{response.message}\n#{response.body}"
81
- end
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
82
 
83
- response.parsed_response
83
+ def index_object(uid)
84
+ Index.new(uid, @base_url, @api_key)
84
85
  end
85
86
  end
86
87
  end
@@ -2,5 +2,44 @@
2
2
 
3
3
  module MeiliSearch
4
4
  class MeiliSearchError < StandardError; end
5
- class ClientError < MeiliSearchError; end
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
17
+
18
+ class HTTPError < MeiliSearchError
19
+ attr_reader :status
20
+ attr_reader :message
21
+ attr_reader :http_body
22
+ attr_reader :http_body_message
23
+ attr_reader :details
24
+
25
+ alias code status
26
+ alias body http_body
27
+ alias body_message http_body_message
28
+
29
+ def initialize(status, message, http_body, details = nil)
30
+ @status = status
31
+ unless http_body.nil? || http_body.empty?
32
+ @http_body = JSON.parse(http_body)
33
+ @http_body_message = @http_body['message']
34
+ end
35
+ @message = message.capitalize
36
+ @message = "#{@message} - #{@http_body_message.capitalize}" unless @http_body_message.nil?
37
+ @details = details
38
+ end
39
+
40
+ def to_s
41
+ final_message = @details.nil? ? @message : "#{@message}. #{@details}"
42
+ "#{@status}: #{final_message}."
43
+ end
44
+ end
6
45
  end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+ require 'meilisearch/error'
5
+
6
+ module MeiliSearch
7
+ class HTTPRequest
8
+ include HTTParty
9
+
10
+ def initialize(url, api_key = nil)
11
+ @base_url = url
12
+ @api_key = api_key
13
+ @headers = {
14
+ 'Content-Type' => 'application/json',
15
+ 'X-Meili-API-Key' => api_key
16
+ }.compact
17
+ end
18
+
19
+ def http_get(path = '', query_params = {})
20
+ response = self.class.get(
21
+ @base_url + path,
22
+ query: query_params,
23
+ headers: @headers,
24
+ timeout: 1
25
+ )
26
+ validate(response)
27
+ end
28
+
29
+ def http_post(path = '', body = nil, query_params = nil)
30
+ body = body.to_json unless body.nil?
31
+ response = self.class.post(
32
+ @base_url + path,
33
+ {
34
+ body: body,
35
+ query: query_params,
36
+ headers: @headers,
37
+ timeout: 1
38
+ }.compact
39
+ )
40
+ validate(response)
41
+ end
42
+
43
+ def http_put(path = '', body = nil, query_params = nil)
44
+ body = body.to_json unless body.nil?
45
+ response = self.class.put(
46
+ @base_url + path,
47
+ {
48
+ body: body,
49
+ query: query_params,
50
+ headers: @headers,
51
+ timeout: 1
52
+ }.compact
53
+ )
54
+ validate(response)
55
+ end
56
+
57
+ def http_delete(path = '')
58
+ response = self.class.delete(
59
+ @base_url + path,
60
+ headers: @headers,
61
+ timeout: 1
62
+ )
63
+ validate(response)
64
+ end
65
+
66
+ private
67
+
68
+ def validate(response)
69
+ raise HTTPError.new(response.code, response.message, response.body) unless response.success?
70
+
71
+ response.parsed_response
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,273 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'meilisearch/http_request'
4
+ require 'timeout'
5
+
6
+ module MeiliSearch
7
+ class Index < HTTPRequest
8
+ attr_reader :uid
9
+
10
+ def initialize(index_uid, url, api_key = nil)
11
+ @uid = index_uid
12
+ super(url, api_key)
13
+ end
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
+
30
+ def primary_key
31
+ show['primaryKey']
32
+ end
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
272
+ end
273
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MeiliSearch
4
- VERSION = '0.1.0'
4
+ VERSION = '0.11.0'
5
5
  end
metadata CHANGED
@@ -1,30 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meilisearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.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: 2019-11-20 00:00:00.000000000 Z
11
+ date: 2020-06-15 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
27
- description: A simple ruby client for Meilisearch API. See https://github.com/meilisearch/MeiliDB
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 0.19.0
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: []
30
36
  extensions: []
@@ -32,18 +38,11 @@ extra_rdoc_files: []
32
38
  files:
33
39
  - lib/meilisearch.rb
34
40
  - lib/meilisearch/client.rb
35
- - lib/meilisearch/client/documents.rb
36
- - lib/meilisearch/client/health.rb
37
- - lib/meilisearch/client/indexes.rb
38
- - lib/meilisearch/client/keys.rb
39
- - lib/meilisearch/client/objects.rb
40
- - lib/meilisearch/client/prepare.rb
41
- - lib/meilisearch/client/search.rb
42
- - lib/meilisearch/client/stats.rb
43
- - lib/meilisearch/dataset.rb
44
41
  - lib/meilisearch/error.rb
42
+ - lib/meilisearch/http_request.rb
43
+ - lib/meilisearch/index.rb
45
44
  - lib/meilisearch/version.rb
46
- homepage: https://github.com/meilisearch/ruby-meili-api
45
+ homepage: https://github.com/meilisearch/meilisearch-ruby
47
46
  licenses:
48
47
  - MIT
49
48
  metadata: {}
@@ -65,5 +64,5 @@ requirements: []
65
64
  rubygems_version: 3.0.3
66
65
  signing_key:
67
66
  specification_version: 4
68
- summary: A simple ruby client for Meilisearch API
67
+ summary: An easy-to-use ruby client for Meilisearch API
69
68
  test_files: []
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MeiliSearch
4
- class Client
5
- module Documents
6
- def add_documents(index_name, documents)
7
- documents.each_slice(1000).map do |slice|
8
- post "/indexes/#{index_name}/documents", slice
9
- end
10
- end
11
-
12
- def document(index_name, document_uid)
13
- get "/indexes/#{index_name}/documents/#{document_uid}"
14
- end
15
-
16
- def get_all_documents(index_name)
17
- get "/indexes/#{index_name}/documents"
18
- end
19
-
20
- def batch_documents
21
- raise NotImplementedError
22
- end
23
-
24
- def update_documents
25
- raise NotImplementedError
26
- end
27
-
28
- def delete_one_document(index_name, document_uid)
29
- delete "/indexes/#{index_name}/documents/#{document_uid}"
30
- end
31
-
32
- def delete_multiple_documents(index_name, document_uids)
33
- post "/indexes/#{index_name}/documents/delete", document_uids
34
- end
35
-
36
- def clear_all_documents(index_name)
37
- delete "/indexes/#{index_name}/documents"
38
- end
39
- end
40
- end
41
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MeiliSearch
4
- class Client
5
- module Health
6
- def is_healthy?
7
- get '/health'
8
- true
9
- rescue StandardError
10
- false
11
- end
12
-
13
- def health
14
- get '/health'
15
- end
16
-
17
- def update_health(bool)
18
- put '/health', health: bool
19
- end
20
- end
21
- end
22
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MeiliSearch
4
- class Client
5
- module Indexes
6
- def indexes
7
- get '/indexes'
8
- end
9
-
10
- def index(index_uid)
11
- get "/indexes/#{index_uid}"
12
- end
13
-
14
- def create_index(index_uid, schema = nil)
15
- if schema.nil?
16
- post "/indexes/#{index_uid}"
17
- else
18
- post "/indexes/#{index_uid}", schema
19
- end
20
- end
21
-
22
- def update_index(index_uid, schema = nil)
23
- put "/indexes/#{index_uid}", schema
24
- end
25
-
26
- def delete_index(index_uid)
27
- delete "/indexes/#{index_uid}"
28
- end
29
- end
30
- end
31
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MeiliSearch
4
- class Client
5
- module Keys
6
- def keys
7
- get '/keys'
8
- end
9
-
10
- def key(key_hash)
11
- get "/keys/#{key_hash}"
12
- end
13
-
14
- def create_key(options = {})
15
- post '/keys', options
16
- end
17
-
18
- def update_key(key_hash, options = {})
19
- put "/keys/#{key_hash}", options
20
- end
21
-
22
- def delete_key(key_hash)
23
- delete "/keys/#{key_hash}"
24
- end
25
- end
26
- end
27
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MeiliSearch
4
- class Client
5
- module Objects
6
- def add_objects(index_name, objects)
7
- if objects.size <= 1000
8
- post "/indexes/#{index_name}/objects", objects
9
- else
10
- objects.each_slice(1000) do |slice|
11
- post "/indexes/#{index_name}/objects", slice
12
- end
13
- end
14
- end
15
-
16
- def object(index_name, object_identifier)
17
- get "/indexes/#{index_name}/objects/#{object_identifier}"
18
- end
19
-
20
- def browse(index_name)
21
- get "/indexes/#{index_name}/objects"
22
- end
23
-
24
- def batch_objects
25
- raise NotImplementedError
26
- end
27
-
28
- def update_objects
29
- raise NotImplementedError
30
- end
31
-
32
- def delete_objects(index_name, object_ids)
33
- delete "/indexes/#{index_name}/objects", object_ids
34
- end
35
- end
36
- end
37
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MeiliSearch
4
- class Client
5
- module Prepare
6
- def rollout
7
- put '/prepare/rollout'
8
- end
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MeiliSearch
4
- class Client
5
- module Search
6
- def search(index_uid, query, options = {})
7
- get "/indexes/#{index_uid}/search", { q: query }.merge(options)
8
- end
9
- end
10
- end
11
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MeiliSearch
4
- class Client
5
- module Stats
6
- def version
7
- get '/version'
8
- end
9
-
10
- def sysinfo
11
- get '/sys-info'
12
- end
13
-
14
- def stats
15
- get '/stats'
16
- end
17
-
18
- def stats_index(index_uid)
19
- get "/stats/#{index_uid}"
20
- end
21
-
22
- def number_of_documents_in_index(index_uid)
23
- stats_index(index_uid)['numberOfDocuments']
24
- end
25
-
26
- def index_is_indexing?(index_uid)
27
- stats_index(index_uid)['isIndexing']
28
- end
29
-
30
- def index_last_update(index_uid)
31
- stats_index(index_uid)['lastUpdate']
32
- end
33
-
34
- def index_fields_frequency(index_uid)
35
- stats_index(index_uid)['fieldsFrequency']
36
- end
37
- end
38
- end
39
- end
@@ -1,76 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MeiliSearch
4
- # This class represents the dataset we can index
5
- class Dataset
6
- class NotEnumerable < StandardError; end
7
- class CannotDetermineHeader < StandardError; end
8
- class ExtensionNotRecognized < StandardError; end
9
-
10
- attr_accessor :data
11
-
12
- def self.new_from_s3(s3_file)
13
- filename = s3_file.filename.to_s
14
- if filename.match?(/.csv$/)
15
- data = CSV.parse(s3_file.download, headers: true)
16
- elsif filename.match?(/.json$/)
17
- data = JSON.parse(s3_file.download)
18
- else
19
- raise Dataset::ExtensionNotRecognized
20
- end
21
- new(data)
22
- end
23
-
24
- def initialize(data)
25
- @data = data
26
- raise Dataset::NotEnumerable unless enumerable?
27
- end
28
-
29
- def clean
30
- encode_to_utf8
31
- replace_nil_values
32
- @data
33
- end
34
-
35
- def headers
36
- if @data.class == Array
37
- @data.first.keys
38
- elsif @data.class == CSV::Table
39
- @data.headers
40
- else
41
- raise CannotDetermineHeader
42
- end
43
- end
44
-
45
- def schema
46
- schema = headers.map do |attribute|
47
- [attribute, [:indexed, :displayed]]
48
- end.to_h
49
-
50
- # Find first attribute containing id
51
- identifier = headers.detect { |attribute| attribute[/id/i] }
52
-
53
- # Then give it the :identifier attribute
54
- schema[identifier].push :identifier
55
- schema
56
- end
57
-
58
- private
59
-
60
- def replace_nil_values
61
- @data = @data.map do |record|
62
- record.each do |key, value|
63
- record[key] = '' if value.nil?
64
- end
65
- end
66
- end
67
-
68
- def encode_to_utf8
69
- @data = @data.map(&:to_h).map(&:to_utf8)
70
- end
71
-
72
- def enumerable?
73
- @data.respond_to? :each
74
- end
75
- end
76
- end