meilisearch 0.8.0 → 0.11.1

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: 25dd43cb7f3a566eac6eb6b9cc195bf10fbb29a98b1b6b85efcfac3e5e068edd
4
- data.tar.gz: 73631da64c2a50f196e459f5696fa0a2d2d4075778dba5dca5777bce99098d7e
3
+ metadata.gz: 53ba8f68eca0a4b76da0d0a967c2ee67757496072a13acb79d82de18f29c2fc4
4
+ data.tar.gz: 0ec5a423d738a7274cf85362d87919994fe137aac50768e0fe6efc22d3d4a9f7
5
5
  SHA512:
6
- metadata.gz: 4f2747c0d558e2cf31b6c169735f38a243ddfeac2a86b932b2e32c3ea47335350a045b10645c5e42687bd0e8dce8b0656d42ae51f1286dabdc403f5e4762ad3e
7
- data.tar.gz: 9c78a7b30755ce6da5a81153108d52dd63203a251358d2b6a8d7811bce329b812970b77dacbbf9f9b42183229ef14c3a72e6bb37e7f828269c129b410066164b
6
+ metadata.gz: 5ac3a7446b8b86e952337866228149ca7ab2767c56bcba623e86e53c25ae934bf39bd238640945799d2ec9a6ea4928fa672da9f69b7e3ecb9a3c12ebb603e485
7
+ data.tar.gz: fc6d734865d2e23827143e15acf9738091753be549899c3e10230adff950fedba1881e1915b30ac8de78d910a243156fb19b2852f21d3a5e93480337af188f37
@@ -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
- include MeiliSearch::Client::Keys
12
- include MeiliSearch::Client::Stats
13
- include MeiliSearch::Client::Health
14
- include MeiliSearch::Client::Indexes
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 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
@@ -2,7 +2,18 @@
2
2
 
3
3
  module MeiliSearch
4
4
  class MeiliSearchError < StandardError; end
5
- class IndexIdentifierError < 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
6
17
 
7
18
  class HTTPError < MeiliSearchError
8
19
  attr_reader :status
@@ -16,45 +16,40 @@ module MeiliSearch
16
16
  }.compact
17
17
  end
18
18
 
19
- def http_get(path = '', query = {})
19
+ def http_get(path = '', query_params = {})
20
20
  response = self.class.get(
21
21
  @base_url + path,
22
- query: query,
23
- headers: @headers
22
+ query: query_params,
23
+ headers: @headers,
24
+ timeout: 1
24
25
  )
25
26
  validate(response)
26
27
  end
27
28
 
28
- def http_post(path = '', body = nil)
29
- response = if body.nil?
30
- self.class.post(
31
- @base_url + path,
32
- headers: @headers
33
- )
34
- else
35
- self.class.post(
36
- @base_url + path,
37
- body: body.to_json,
38
- headers: @headers
39
- )
40
- end
41
- validate(response)
42
- end
43
-
44
- def http_put(path = '', body = {})
45
- response = self.class.put(
29
+ def http_post(path = '', body = nil, query_params = nil)
30
+ body = body.to_json unless body.nil?
31
+ response = self.class.post(
46
32
  @base_url + path,
47
- body: body.to_json,
48
- headers: @headers
33
+ {
34
+ body: body,
35
+ query: query_params,
36
+ headers: @headers,
37
+ timeout: 1
38
+ }.compact
49
39
  )
50
40
  validate(response)
51
41
  end
52
42
 
53
- def http_patch(path = '', body = {})
54
- response = self.class.patch(
43
+ def http_put(path = '', body = nil, query_params = nil)
44
+ body = body.to_json unless body.nil?
45
+ response = self.class.put(
55
46
  @base_url + path,
56
- body: body.to_json,
57
- headers: @headers
47
+ {
48
+ body: body,
49
+ query: query_params,
50
+ headers: @headers,
51
+ timeout: 1
52
+ }.compact
58
53
  )
59
54
  validate(response)
60
55
  end
@@ -62,7 +57,8 @@ module MeiliSearch
62
57
  def http_delete(path = '')
63
58
  response = self.class.delete(
64
59
  @base_url + path,
65
- headers: @headers
60
+ headers: @headers,
61
+ timeout: 1
66
62
  )
67
63
  validate(response)
68
64
  end
@@ -1,26 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'meilisearch/http_request'
4
- require 'meilisearch/index/base'
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,15 +12,262 @@ module MeiliSearch
28
12
  super(url, api_key)
29
13
  end
30
14
 
31
- def name
32
- index_name_from_uid
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"
33
154
  end
34
- alias get_name name
35
155
 
36
- private
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
37
268
 
38
- def index_name_from_uid
39
- show['name']
269
+ def reset_attributes_for_faceting
270
+ http_delete "/indexes/#{@uid}/settings/attributes-for-faceting"
40
271
  end
41
272
  end
42
273
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MeiliSearch
4
- VERSION = '0.8.0'
4
+ VERSION = '0.11.1'
5
5
  end
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.8.0
4
+ version: 0.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Meili
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-17 00:00:00.000000000 Z
11
+ date: 2020-06-23 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,71 +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('name')
16
- # create_index(name: 'name')
17
- # create_index(name: 'name', uid: 'uid')
18
- # create_index(name: 'name', schema: {...})
19
- # create_index(name: 'name', uid: 'uid', schema: {...})
20
- def create_index(attributes)
21
- body = if attributes.is_a?(Hash)
22
- attributes
23
- else
24
- { name: attributes }
25
- end
26
- res = http_post '/indexes', body
27
- index_object(res['uid'])
28
- end
29
-
30
- def delete_index(index_uid)
31
- index_object(index_uid).delete
32
- end
33
-
34
- # Usage:
35
- # index('uid')
36
- # index(uid: 'uid')
37
- # index(name: 'name') => WARNING: the name of an index is not guaranteed to be unique. This method will return the first occurrence. We recommend using the index uid instead.
38
- # index(uid: 'uid', name: 'name') => only the uid field will be taken into account.
39
- def index(identifier)
40
- uid = index_uid(identifier)
41
- raise IndexIdentifierError if uid.nil?
42
-
43
- index_object(uid)
44
- end
45
- alias get_index index
46
-
47
- private
48
-
49
- def index_object(uid)
50
- Index.new(uid, @base_url, @api_key)
51
- end
52
-
53
- def index_uid(identifier)
54
- if identifier.is_a?(Hash)
55
- identifier[:uid] || index_uid_from_name(identifier)
56
- else
57
- identifier
58
- end
59
- end
60
-
61
- def index_uid_from_name(identifier)
62
- index = indexes.find { |i| i['name'] == identifier[:name] }
63
- if index.nil?
64
- nil
65
- else
66
- index['uid']
67
- end
68
- end
69
- end
70
- end
71
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MeiliSearch
4
- class Client < HTTPRequest
5
- module Keys
6
- def keys
7
- http_get '/keys'
8
- end
9
-
10
- def key(key)
11
- http_get "/keys/#{key}"
12
- end
13
-
14
- def create_key(options = {})
15
- http_post '/keys', options
16
- end
17
-
18
- def update_key(key, options = {})
19
- http_put "/keys/#{key}", options
20
- end
21
-
22
- def delete_key(key)
23
- http_delete "/keys/#{key}"
24
- end
25
- end
26
- end
27
- 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,36 +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 schema
12
- http_get "/indexes/#{@uid}/schema"
13
- rescue HTTPError => e
14
- raise if e.body_message != 'missing index schema'
15
-
16
- nil
17
- end
18
- alias get_schema schema
19
-
20
- def update_name(new_index_name)
21
- http_put "/indexes/#{@uid}", name: new_index_name
22
- end
23
- alias update_index_name update_name
24
-
25
- def update_schema(new_schema)
26
- http_put "/indexes/#{@uid}/schema", new_schema
27
- end
28
- alias update_index_schema update_schema
29
-
30
- def delete
31
- http_delete "/indexes/#{@uid}"
32
- end
33
- alias delete_index delete
34
- end
35
- end
36
- end
@@ -1,52 +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)
19
- documents = [documents] if documents.is_a?(Hash)
20
- http_post "/indexes/#{@uid}/documents", documents
21
- end
22
- alias replace_documents add_documents
23
- alias add_or_replace_documents add_documents
24
-
25
- def update_documents(documents)
26
- documents = [documents] if documents.is_a?(Hash)
27
- http_put "/indexes/#{@uid}/documents", documents
28
- end
29
- alias add_or_update_documents update_documents
30
-
31
- def clear_documents
32
- http_delete "/indexes/#{@uid}/documents"
33
- end
34
- alias clear_all_documents clear_documents
35
-
36
- def delete_documents(documents_ids)
37
- if documents_ids.is_a?(Array)
38
- http_post "/indexes/#{@uid}/documents/delete", documents_ids
39
- else
40
- delete_document(documents_ids)
41
- end
42
- end
43
- alias delete_multiple_documents delete_documents
44
-
45
- def delete_document(document_id)
46
- encode_document = URI.encode_www_form_component(document_id)
47
- http_delete "/indexes/#{@uid}/documents/#{encode_document}"
48
- end
49
- alias delete_one_document delete_document
50
- end
51
- end
52
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MeiliSearch
4
- class Index < HTTPRequest
5
- module Search
6
- def search(query, options = {})
7
- http_get "/indexes/#{@uid}/search", { q: query }.merge(options)
8
- end
9
- end
10
- end
11
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MeiliSearch
4
- class Index < HTTPRequest
5
- module Settings
6
- def settings
7
- http_get "/indexes/#{@uid}/settings"
8
- end
9
- alias get_settings settings
10
-
11
- def add_or_replace_settings(options)
12
- http_post "/indexes/#{@uid}/settings", options
13
- end
14
- alias add_settings add_or_replace_settings
15
- alias replace_settings add_or_replace_settings
16
-
17
- def reset_all_settings
18
- body = {
19
- rankingOrder: nil,
20
- distinctField: nil,
21
- rankingRules: nil
22
- }
23
- http_post "/indexes/#{@uid}/settings", body
24
- end
25
- end
26
- end
27
- 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 "/stats/#{@uid}"
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,28 +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}/stop-words"
8
- end
9
- alias get_stop_words stop_words
10
-
11
- def add_stop_words(stop_words)
12
- if stop_words.is_a?(Array)
13
- http_patch "/indexes/#{@uid}/stop-words", stop_words
14
- else
15
- http_patch "/indexes/#{@uid}/stop-words", [stop_words]
16
- end
17
- end
18
-
19
- def delete_stop_words(stop_words)
20
- if stop_words.is_a?(Array)
21
- http_post "/indexes/#{@uid}/stop-words", stop_words
22
- else
23
- http_post "/indexes/#{@uid}/stop-words", [stop_words]
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MeiliSearch
4
- class Index < HTTPRequest
5
- module Synonyms
6
- def synonyms_of(synonym)
7
- encode_synonym = URI.encode_www_form_component(synonym)
8
- http_get "/indexes/#{@uid}/synonyms/#{encode_synonym}"
9
- end
10
- alias get_synonyms_of_one_sequence synonyms_of
11
- alias get_synonyms_of synonyms_of
12
-
13
- def all_synonyms
14
- http_get "/indexes/#{@uid}/synonyms"
15
- end
16
- alias get_all_synonyms all_synonyms
17
- alias get_all_sequences all_synonyms
18
-
19
- def add_synonyms(synonyms)
20
- http_post "/indexes/#{@uid}/synonyms", synonyms
21
- end
22
-
23
- def add_synonyms_one_way(input, synonyms)
24
- add_synonyms(input: input, synonyms: synonyms)
25
- end
26
-
27
- def add_synonyms_multi_way(synonyms)
28
- add_synonyms(synonyms: synonyms)
29
- end
30
-
31
- def update_synonym(synonym, new_synonyms)
32
- encode_synonym = URI.encode_www_form_component(synonym)
33
- http_put "/indexes/#{@uid}/synonyms/#{encode_synonym}", new_synonyms
34
- end
35
-
36
- def delete_synonym(synonym)
37
- encode_synonym = URI.encode_www_form_component(synonym)
38
- http_delete "/indexes/#{@uid}/synonyms/#{encode_synonym}"
39
- end
40
- alias delete_one_synonym delete_synonym
41
-
42
- def batch_write_synonyms(synonyms)
43
- http_post "/indexes/#{@uid}/synonyms/batch", synonyms
44
- end
45
-
46
- def clear_synonyms
47
- http_delete "/indexes/#{@uid}/synonyms"
48
- end
49
- alias clear_all_synonyms clear_synonyms
50
- end
51
- end
52
- 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