meilisearch 0.12.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17248185a6d2ba10e2e5fac61b6d9d07a0cac218a2accc4cd5b3bd130517f837
4
- data.tar.gz: dd20f35451242677ec05ac52d95cbc14915dea6676562ef23c58a58655db24ad
3
+ metadata.gz: e60c9c4ac5631947edf24d990c37fd06e09bbbb59b6eabd554fcacc7d8f231ed
4
+ data.tar.gz: 5373d86aacf0791fa30f068d97ba9f5b857fa75930c3580ddd20449cd2db8e7b
5
5
  SHA512:
6
- metadata.gz: f0c0c7a6726257c62e14108f33df551cd5ec3d7c5f4b6f8eb3fa975988da3915d7b3167e0074c3e21134f49d1a40d84a55e4145ae7b4ffac45cd1daa8954e00d
7
- data.tar.gz: 3cb711d0577b92fe428b90ec16d2cbc7fb593aba63f014206c17a88bca2ba4de0fdd58b51e2b014640ae7118996142b9edc4c4d4d00250fc8a6893df117e3527
6
+ metadata.gz: d7496a3f2ea08ed35ff277c0176c52fe8120290678a1594bd49637e96b03e825aad11bfd55370040fd3563577fea9fbc6a3a7df335bb400a78d2a46707072ff2
7
+ data.tar.gz: db46abc6f60ec202641480eb0ac2232b2892ea966590d955735f4ab7a5ce98cc52493c87da7bb1ccc5d4399f95b0b4c7639619ad0a30ed4caa4f21e3af7aabf3
@@ -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
- res = http_post '/indexes', body
23
- index_object(res['uid'])
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
- create_index(index_uid, options)
24
+ index_instance = fetch_index(index_uid)
29
25
  rescue ApiError => e
30
- raise e unless e.code == 'index_already_exists'
26
+ raise e unless e.code == 'index_not_found'
27
+
28
+ index_instance = create_index(index_uid, options)
31
29
  end
32
- index_object(index_uid)
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
- alias get_index index
42
+
43
+ def fetch_index(index_uid)
44
+ index_object(index_uid).fetch_info
45
+ end
45
46
 
46
47
  ### KEYS
47
48
 
@@ -63,32 +64,31 @@ 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
73
70
  http_get '/version'
74
71
  end
75
72
 
76
- def sysinfo
77
- http_get '/sys-info'
73
+ def stats
74
+ http_get '/stats'
78
75
  end
79
76
 
80
- def pretty_sysinfo
81
- http_get '/sys-info/pretty'
77
+ ### DUMPS
78
+
79
+ def create_dump
80
+ http_post '/dumps'
82
81
  end
83
82
 
84
- def stats
85
- http_get '/stats'
83
+ def dump_status(dump_uid)
84
+ http_get "/dumps/#{dump_uid}/status"
86
85
  end
86
+ alias get_dump_status dump_status
87
87
 
88
88
  private
89
89
 
90
- def index_object(uid)
91
- 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)
92
92
  end
93
93
  end
94
94
  end
@@ -2,14 +2,16 @@
2
2
 
3
3
  module MeiliSearch
4
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
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
@@ -21,7 +23,7 @@ module MeiliSearch
21
23
  @http_message = http_message
22
24
  @ms_message ||= 'MeiliSearch API has not returned any error message'
23
25
  @ms_link ||= '<no documentation link found>'
24
- @message = "#{http_code} #{http_message} - #{@ms_message.capitalize}. See #{ms_link}."
26
+ @message = "#{http_code} #{http_message} - #{@ms_message}. See #{ms_link}."
25
27
  super(details)
26
28
  end
27
29
 
@@ -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
@@ -67,7 +68,8 @@ module MeiliSearch
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
 
@@ -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 show
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 primary_key
31
- show['primaryKey']
34
+ def fetch_primary_key
35
+ fetch_info.primary_key
32
36
  end
33
- alias get_primary_key primary_key
37
+ alias get_primary_key fetch_primary_key
34
38
 
35
39
  ### DOCUMENTS
36
40
 
@@ -81,16 +85,8 @@ module MeiliSearch
81
85
  ### SEARCH
82
86
 
83
87
  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)
88
+ parsed_options = options.compact
89
+ http_post "/indexes/#{@uid}/search", { q: query }.merge(parsed_options)
94
90
  end
95
91
 
96
92
  ### UPDATES
@@ -148,6 +144,7 @@ module MeiliSearch
148
144
  def update_settings(settings)
149
145
  http_post "/indexes/#{@uid}/settings", settings
150
146
  end
147
+ alias settings= update_settings
151
148
 
152
149
  def reset_settings
153
150
  http_delete "/indexes/#{@uid}/settings"
@@ -163,6 +160,7 @@ module MeiliSearch
163
160
  def update_ranking_rules(ranking_rules)
164
161
  http_post "/indexes/#{@uid}/settings/ranking-rules", ranking_rules
165
162
  end
163
+ alias ranking_rules= update_ranking_rules
166
164
 
167
165
  def reset_ranking_rules
168
166
  http_delete "/indexes/#{@uid}/settings/ranking-rules"
@@ -178,6 +176,7 @@ module MeiliSearch
178
176
  def update_synonyms(synonyms)
179
177
  http_post "/indexes/#{@uid}/settings/synonyms", synonyms
180
178
  end
179
+ alias synonyms= update_synonyms
181
180
 
182
181
  def reset_synonyms
183
182
  http_delete "/indexes/#{@uid}/settings/synonyms"
@@ -194,6 +193,7 @@ module MeiliSearch
194
193
  body = stop_words.is_a?(Array) ? stop_words : [stop_words]
195
194
  http_post "/indexes/#{@uid}/settings/stop-words", body
196
195
  end
196
+ alias stop_words= update_stop_words
197
197
 
198
198
  def reset_stop_words
199
199
  http_delete "/indexes/#{@uid}/settings/stop-words"
@@ -209,6 +209,7 @@ module MeiliSearch
209
209
  def update_distinct_attribute(distinct_attribute)
210
210
  http_post "/indexes/#{@uid}/settings/distinct-attribute", distinct_attribute
211
211
  end
212
+ alias distinct_attribute= update_distinct_attribute
212
213
 
213
214
  def reset_distinct_attribute
214
215
  http_delete "/indexes/#{@uid}/settings/distinct-attribute"
@@ -224,6 +225,7 @@ module MeiliSearch
224
225
  def update_searchable_attributes(searchable_attributes)
225
226
  http_post "/indexes/#{@uid}/settings/searchable-attributes", searchable_attributes
226
227
  end
228
+ alias searchable_attributes= update_searchable_attributes
227
229
 
228
230
  def reset_searchable_attributes
229
231
  http_delete "/indexes/#{@uid}/settings/searchable-attributes"
@@ -239,22 +241,12 @@ module MeiliSearch
239
241
  def update_displayed_attributes(displayed_attributes)
240
242
  http_post "/indexes/#{@uid}/settings/displayed-attributes", displayed_attributes
241
243
  end
244
+ alias displayed_attributes= update_displayed_attributes
242
245
 
243
246
  def reset_displayed_attributes
244
247
  http_delete "/indexes/#{@uid}/settings/displayed-attributes"
245
248
  end
246
249
 
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
250
  ### SETTINGS - ATTRIBUTES FOR FACETING
259
251
 
260
252
  def attributes_for_faceting
@@ -265,6 +257,7 @@ module MeiliSearch
265
257
  def update_attributes_for_faceting(attributes_for_faceting)
266
258
  http_post "/indexes/#{@uid}/settings/attributes-for-faceting", attributes_for_faceting
267
259
  end
260
+ alias attributes_for_faceting= update_attributes_for_faceting
268
261
 
269
262
  def reset_attributes_for_faceting
270
263
  http_delete "/indexes/#{@uid}/settings/attributes-for-faceting"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MeiliSearch
4
- VERSION = '0.12.0'
4
+ VERSION = '0.15.0'
5
5
  end
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.12.0
4
+ version: 0.15.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-07-09 00:00:00.000000000 Z
11
+ date: 2020-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.0.3
64
+ rubygems_version: 3.1.4
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: An easy-to-use ruby client for Meilisearch API