meilisearch 0.14.0 → 0.15.4

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: a1861bef27e914a71fc706d4b0758a585842cc33421fa8a7ecacb0a45f146903
4
- data.tar.gz: 33b66d0151cc205fd7d964b78608cd5f6641f2d9740d3b28d3fd2f52ee36d98c
3
+ metadata.gz: 03f23776fd7b1baeabbfcc33fcd848f8bd89f56655579756d9e2c06492f8d824
4
+ data.tar.gz: d5137b74a7def336e41e746d56f714847be1f73185c5f05abf70a03310cc79b4
5
5
  SHA512:
6
- metadata.gz: 7600f98e465ddf28304b52f5ee12c199d7f6486b2230b2e1bea3d988bc41b3936875fbbf6f5a03ee5a6ac416d40e5dcddd8abc906415b6be44f67ba52c79a56d
7
- data.tar.gz: d3e8eecfdd30d26a7bbb2dac5c7e216406093782015d232765315897a24744c02e2fac8113c169e4dfc7f5bd2cbe2cdbd3042c5fcb1aaab3e1d5212626b485ee
6
+ metadata.gz: c2c1fee375d80f6e0c372438b3fbb4c76b4c504f0c7ddf1d12d810e89f93f8173e838b1d6d8cf1d57ba02f75277f784660379c8961ccb47884eb2e37d7a43f06
7
+ data.tar.gz: ab566b980a0ab15a5ffef99fb47520f667783c098e3ea81fa35784a12d1806846b18a80f42116f0605e2770655a62f35b97e8881983b08ff865de28fcde89c7a
@@ -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
 
@@ -73,10 +74,21 @@ module MeiliSearch
73
74
  http_get '/stats'
74
75
  end
75
76
 
77
+ ### DUMPS
78
+
79
+ def create_dump
80
+ http_post '/dumps'
81
+ end
82
+
83
+ def dump_status(dump_uid)
84
+ http_get "/dumps/#{dump_uid}/status"
85
+ end
86
+ alias get_dump_status dump_status
87
+
76
88
  private
77
89
 
78
- def index_object(uid)
79
- 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, @options)
80
92
  end
81
93
  end
82
94
  end
@@ -7,6 +7,8 @@ module MeiliSearch
7
7
  class HTTPRequest
8
8
  include HTTParty
9
9
 
10
+ attr_reader :options
11
+
10
12
  def initialize(url, api_key = nil, options = {})
11
13
  @base_url = url
12
14
  @api_key = api_key
@@ -63,7 +65,7 @@ module MeiliSearch
63
65
  end
64
66
 
65
67
  def http_config(query_params, body)
66
- body = body.to_json unless body.nil?
68
+ body = body.to_json
67
69
  {
68
70
  headers: @headers,
69
71
  query: query_params,
@@ -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, options = {})
11
11
  @uid = index_uid
12
- super(url, api_key)
12
+ @primary_key = primary_key
13
+ super(url, api_key, options)
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
 
@@ -53,12 +57,25 @@ module MeiliSearch
53
57
  alias replace_documents add_documents
54
58
  alias add_or_replace_documents add_documents
55
59
 
60
+ def add_documents!(documents, primary_key = nil)
61
+ update = add_documents(documents, primary_key)
62
+ wait_for_pending_update(update['updateId'])
63
+ end
64
+ alias replace_documents! add_documents!
65
+ alias add_or_replace_documents! add_documents!
66
+
56
67
  def update_documents(documents, primary_key = nil)
57
68
  documents = [documents] if documents.is_a?(Hash)
58
69
  http_put "/indexes/#{@uid}/documents", documents, { primaryKey: primary_key }.compact
59
70
  end
60
71
  alias add_or_update_documents update_documents
61
72
 
73
+ def update_documents!(documents, primary_key = nil)
74
+ update = update_documents(documents, primary_key)
75
+ wait_for_pending_update(update['updateId'])
76
+ end
77
+ alias add_or_update_documents! update_documents!
78
+
62
79
  def delete_documents(documents_ids)
63
80
  if documents_ids.is_a?(Array)
64
81
  http_post "/indexes/#{@uid}/documents/delete-batch", documents_ids
@@ -68,21 +85,38 @@ module MeiliSearch
68
85
  end
69
86
  alias delete_multiple_documents delete_documents
70
87
 
88
+ def delete_documents!(documents_ids)
89
+ update = delete_documents(documents_ids)
90
+ wait_for_pending_update(update['updateId'])
91
+ end
92
+ alias delete_multiple_documents! delete_documents!
93
+
71
94
  def delete_document(document_id)
72
95
  encode_document = URI.encode_www_form_component(document_id)
73
96
  http_delete "/indexes/#{@uid}/documents/#{encode_document}"
74
97
  end
75
98
  alias delete_one_document delete_document
76
99
 
100
+ def delete_document!(document_id)
101
+ update = delete_document(document_id)
102
+ wait_for_pending_update(update['updateId'])
103
+ end
104
+ alias delete_one_document! delete_document!
105
+
77
106
  def delete_all_documents
78
107
  http_delete "/indexes/#{@uid}/documents"
79
108
  end
80
109
 
110
+ def delete_all_documents!
111
+ update = delete_all_documents
112
+ wait_for_pending_update(update['updateId'])
113
+ end
114
+
81
115
  ### SEARCH
82
116
 
83
117
  def search(query, options = {})
84
118
  parsed_options = options.compact
85
- http_post "/indexes/#{@uid}/search", { q: query }.merge(parsed_options)
119
+ http_post "/indexes/#{@uid}/search", { q: query.to_s }.merge(parsed_options)
86
120
  end
87
121
 
88
122
  ### UPDATES
@@ -140,6 +174,7 @@ module MeiliSearch
140
174
  def update_settings(settings)
141
175
  http_post "/indexes/#{@uid}/settings", settings
142
176
  end
177
+ alias settings= update_settings
143
178
 
144
179
  def reset_settings
145
180
  http_delete "/indexes/#{@uid}/settings"
@@ -155,6 +190,7 @@ module MeiliSearch
155
190
  def update_ranking_rules(ranking_rules)
156
191
  http_post "/indexes/#{@uid}/settings/ranking-rules", ranking_rules
157
192
  end
193
+ alias ranking_rules= update_ranking_rules
158
194
 
159
195
  def reset_ranking_rules
160
196
  http_delete "/indexes/#{@uid}/settings/ranking-rules"
@@ -170,6 +206,7 @@ module MeiliSearch
170
206
  def update_synonyms(synonyms)
171
207
  http_post "/indexes/#{@uid}/settings/synonyms", synonyms
172
208
  end
209
+ alias synonyms= update_synonyms
173
210
 
174
211
  def reset_synonyms
175
212
  http_delete "/indexes/#{@uid}/settings/synonyms"
@@ -186,6 +223,7 @@ module MeiliSearch
186
223
  body = stop_words.is_a?(Array) ? stop_words : [stop_words]
187
224
  http_post "/indexes/#{@uid}/settings/stop-words", body
188
225
  end
226
+ alias stop_words= update_stop_words
189
227
 
190
228
  def reset_stop_words
191
229
  http_delete "/indexes/#{@uid}/settings/stop-words"
@@ -201,6 +239,7 @@ module MeiliSearch
201
239
  def update_distinct_attribute(distinct_attribute)
202
240
  http_post "/indexes/#{@uid}/settings/distinct-attribute", distinct_attribute
203
241
  end
242
+ alias distinct_attribute= update_distinct_attribute
204
243
 
205
244
  def reset_distinct_attribute
206
245
  http_delete "/indexes/#{@uid}/settings/distinct-attribute"
@@ -216,6 +255,7 @@ module MeiliSearch
216
255
  def update_searchable_attributes(searchable_attributes)
217
256
  http_post "/indexes/#{@uid}/settings/searchable-attributes", searchable_attributes
218
257
  end
258
+ alias searchable_attributes= update_searchable_attributes
219
259
 
220
260
  def reset_searchable_attributes
221
261
  http_delete "/indexes/#{@uid}/settings/searchable-attributes"
@@ -231,6 +271,7 @@ module MeiliSearch
231
271
  def update_displayed_attributes(displayed_attributes)
232
272
  http_post "/indexes/#{@uid}/settings/displayed-attributes", displayed_attributes
233
273
  end
274
+ alias displayed_attributes= update_displayed_attributes
234
275
 
235
276
  def reset_displayed_attributes
236
277
  http_delete "/indexes/#{@uid}/settings/displayed-attributes"
@@ -246,6 +287,7 @@ module MeiliSearch
246
287
  def update_attributes_for_faceting(attributes_for_faceting)
247
288
  http_post "/indexes/#{@uid}/settings/attributes-for-faceting", attributes_for_faceting
248
289
  end
290
+ alias attributes_for_faceting= update_attributes_for_faceting
249
291
 
250
292
  def reset_attributes_for_faceting
251
293
  http_delete "/indexes/#{@uid}/settings/attributes-for-faceting"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MeiliSearch
4
- VERSION = '0.14.0'
4
+ VERSION = '0.15.4'
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.14.0
4
+ version: 0.15.4
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-04 00:00:00.000000000 Z
11
+ date: 2021-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -54,14 +54,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
54
  requirements:
55
55
  - - ">="
56
56
  - !ruby/object:Gem::Version
57
- version: '0'
57
+ version: 2.6.0
58
58
  required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.1.4
64
+ rubygems_version: 3.0.3.1
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: An easy-to-use ruby client for Meilisearch API