meilisearch 0.8.1 → 0.9.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: 4b06c291f3bf2609f0044199d4c35418052ab7cddb3d41216b7ba908bbfe6f61
4
- data.tar.gz: 7fd8ddd39e24e14e5dcb39d3187df368f7cb88d5b46f4ce824e4b90d2670225a
3
+ metadata.gz: 99ae25bab6782e438028c54d10a2966072afb86200f4ac70133a438272be9c65
4
+ data.tar.gz: 13a067ebb2af22906feb52df27b1f4a572bc72bc5fe5cbfc3a95a8ae7262c26c
5
5
  SHA512:
6
- metadata.gz: 21248cb8c60cc8875e4280eb8223ad7e48483c9a97d552a4d4a08aa887da54039d6532fd7fe8981199b8d232a25439b8a009250e7f4fe76db0d3b81e8c043885
7
- data.tar.gz: 7d1ce9c9a6d956b5609aa0366435ed8d130b15e7e857aabf127263ce24f76ab5a80a9ee1d7af49153b5c7b21742dbec4ae827a33781c79a7db7e98984f5ead99
6
+ metadata.gz: 1e161040182a153380376f5e05a3485c7203408171413537d02a9effeb8f121661c21da6d26da7644c30f6a246628eace816107b0b58f76f2acfa6c75dbd2795
7
+ data.tar.gz: 28e13d37c04b1ac39424e60a9107215afe9379d3a56a7c10bdde5cdd183843f93b4c069c5fa5bc770e531f5cc528d3d6b8426a9de5f52f62376c68e697dcc78a
@@ -12,16 +12,14 @@ module MeiliSearch
12
12
  end
13
13
 
14
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: {...})
15
+ # create_index('indexUID')
16
+ # create_index(uid: 'indexUID')
17
+ # create_index(uid: 'indexUID', primaryKey: 'id')
20
18
  def create_index(attributes)
21
19
  body = if attributes.is_a?(Hash)
22
20
  attributes
23
21
  else
24
- { name: attributes }
22
+ { uid: attributes }
25
23
  end
26
24
  res = http_post '/indexes', body
27
25
  index_object(res['uid'])
@@ -32,13 +30,11 @@ module MeiliSearch
32
30
  end
33
31
 
34
32
  # 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?
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?
42
38
 
43
39
  index_object(uid)
44
40
  end
@@ -49,23 +45,6 @@ module MeiliSearch
49
45
  def index_object(uid)
50
46
  Index.new(uid, @base_url, @api_key)
51
47
  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
48
  end
70
49
  end
71
50
  end
@@ -6,22 +6,7 @@ module MeiliSearch
6
6
  def keys
7
7
  http_get '/keys'
8
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
9
+ alias get_keys keys
25
10
  end
26
11
  end
27
12
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module MeiliSearch
4
4
  class MeiliSearchError < StandardError; end
5
- class IndexIdentifierError < MeiliSearchError; end
5
+ class IndexUidError < MeiliSearchError; end
6
6
 
7
7
  class HTTPError < MeiliSearchError
8
8
  attr_reader :status
@@ -26,38 +26,38 @@ module MeiliSearch
26
26
  validate(response)
27
27
  end
28
28
 
29
- def http_post(path = '', body = nil)
30
- response = if body.nil?
31
- self.class.post(
32
- @base_url + path,
33
- headers: @headers,
34
- timeout: 1
35
- )
36
- else
37
- self.class.post(
38
- @base_url + path,
39
- body: body.to_json,
40
- headers: @headers,
41
- timeout: 1
42
- )
43
- end
29
+ def http_post(path = '', body = nil, params = nil)
30
+ body = body.to_json unless body.nil?
31
+ params = {
32
+ body: body,
33
+ query: params,
34
+ headers: @headers,
35
+ timeout: 1
36
+ }.compact
37
+ response = self.class.post(
38
+ @base_url + path,
39
+ params
40
+ )
44
41
  validate(response)
45
42
  end
46
43
 
47
- def http_put(path = '', body = {})
44
+ def http_put(path = '', body = nil, params = nil)
45
+ body = body.to_json unless body.nil?
48
46
  response = self.class.put(
49
47
  @base_url + path,
50
- body: body.to_json,
48
+ body: body,
49
+ query: params,
51
50
  headers: @headers,
52
51
  timeout: 1
53
52
  )
54
53
  validate(response)
55
54
  end
56
55
 
57
- def http_patch(path = '', body = {})
56
+ def http_patch(path = '', body = nil)
57
+ body = body.to_json unless body.nil?
58
58
  response = self.class.patch(
59
59
  @base_url + path,
60
- body: body.to_json,
60
+ body: body,
61
61
  headers: @headers,
62
62
  timeout: 1
63
63
  )
@@ -28,15 +28,9 @@ module MeiliSearch
28
28
  super(url, api_key)
29
29
  end
30
30
 
31
- def name
32
- index_name_from_uid
33
- end
34
- alias get_name name
35
-
36
- private
37
-
38
- def index_name_from_uid
39
- show['name']
31
+ def primary_key
32
+ show['primaryKey']
40
33
  end
34
+ alias get_primary_key primary_key
41
35
  end
42
36
  end
@@ -8,24 +8,10 @@ module MeiliSearch
8
8
  end
9
9
  alias show_index show
10
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
11
+ def update(body)
12
+ http_put "/indexes/#{@uid}", body
27
13
  end
28
- alias update_index_schema update_schema
14
+ alias update_index update
29
15
 
30
16
  def delete
31
17
  http_delete "/indexes/#{@uid}"
@@ -15,27 +15,22 @@ module MeiliSearch
15
15
  end
16
16
  alias get_documents documents
17
17
 
18
- def add_documents(documents)
18
+ def add_documents(documents, primary_key = nil)
19
19
  documents = [documents] if documents.is_a?(Hash)
20
- http_post "/indexes/#{@uid}/documents", documents
20
+ http_post "/indexes/#{@uid}/documents", documents, primaryKey: primary_key
21
21
  end
22
22
  alias replace_documents add_documents
23
23
  alias add_or_replace_documents add_documents
24
24
 
25
- def update_documents(documents)
25
+ def update_documents(documents, primary_key = nil)
26
26
  documents = [documents] if documents.is_a?(Hash)
27
- http_put "/indexes/#{@uid}/documents", documents
27
+ http_put "/indexes/#{@uid}/documents", documents, primaryKey: primary_key
28
28
  end
29
29
  alias add_or_update_documents update_documents
30
30
 
31
- def clear_documents
32
- http_delete "/indexes/#{@uid}/documents"
33
- end
34
- alias clear_all_documents clear_documents
35
-
36
31
  def delete_documents(documents_ids)
37
32
  if documents_ids.is_a?(Array)
38
- http_post "/indexes/#{@uid}/documents/delete", documents_ids
33
+ http_post "/indexes/#{@uid}/documents/delete-batch", documents_ids
39
34
  else
40
35
  delete_document(documents_ids)
41
36
  end
@@ -47,6 +42,10 @@ module MeiliSearch
47
42
  http_delete "/indexes/#{@uid}/documents/#{encode_document}"
48
43
  end
49
44
  alias delete_one_document delete_document
45
+
46
+ def delete_all_documents
47
+ http_delete "/indexes/#{@uid}/documents"
48
+ end
50
49
  end
51
50
  end
52
51
  end
@@ -3,24 +3,84 @@
3
3
  module MeiliSearch
4
4
  class Index < HTTPRequest
5
5
  module Settings
6
+ # General routes
6
7
  def settings
7
8
  http_get "/indexes/#{@uid}/settings"
8
9
  end
9
10
  alias get_settings settings
10
11
 
11
- def add_or_replace_settings(options)
12
- http_post "/indexes/#{@uid}/settings", options
12
+ def update_settings(settings)
13
+ http_post "/indexes/#{@uid}/settings", settings
13
14
  end
14
- alias add_settings add_or_replace_settings
15
- alias replace_settings add_or_replace_settings
16
15
 
17
- def reset_all_settings
18
- body = {
19
- rankingOrder: nil,
20
- distinctField: nil,
21
- rankingRules: nil
22
- }
23
- http_post "/indexes/#{@uid}/settings", body
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
24
84
  end
25
85
  end
26
86
  end
@@ -4,7 +4,7 @@ module MeiliSearch
4
4
  class Index < HTTPRequest
5
5
  module Stats
6
6
  def stats
7
- http_get "/stats/#{@uid}"
7
+ http_get "/indexes/#{@uid}/stats"
8
8
  end
9
9
 
10
10
  def number_of_documents
@@ -4,24 +4,17 @@ module MeiliSearch
4
4
  class Index < HTTPRequest
5
5
  module StopWords
6
6
  def stop_words
7
- http_get "/indexes/#{@uid}/stop-words"
7
+ http_get "/indexes/#{@uid}/settings/stop-words"
8
8
  end
9
9
  alias get_stop_words stop_words
10
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
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
17
14
  end
18
15
 
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
16
+ def reset_stop_words
17
+ http_delete "/indexes/#{@uid}/settings/stop-words"
25
18
  end
26
19
  end
27
20
  end
@@ -3,50 +3,18 @@
3
3
  module MeiliSearch
4
4
  class Index < HTTPRequest
5
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}"
6
+ def synonyms
7
+ http_get "/indexes/#{@uid}/settings/synonyms"
9
8
  end
10
- alias get_synonyms_of_one_sequence synonyms_of
11
- alias get_synonyms_of synonyms_of
9
+ alias get_synonyms synonyms
12
10
 
13
- def all_synonyms
14
- http_get "/indexes/#{@uid}/synonyms"
11
+ def update_synonyms(synonyms)
12
+ http_post "/indexes/#{@uid}/settings/synonyms", synonyms
15
13
  end
16
- alias get_all_synonyms all_synonyms
17
- alias get_all_sequences all_synonyms
18
14
 
19
- def add_synonyms(synonyms)
20
- http_post "/indexes/#{@uid}/synonyms", synonyms
15
+ def reset_synonyms
16
+ http_delete "/indexes/#{@uid}/settings/synonyms"
21
17
  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
18
  end
51
19
  end
52
20
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MeiliSearch
4
- VERSION = '0.8.1'
4
+ VERSION = '0.9.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.8.1
4
+ version: 0.9.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-04 00:00:00.000000000 Z
11
+ date: 2020-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty