meilisearch 0.1.0 → 0.8.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 +4 -4
- data/lib/meilisearch.rb +1 -0
- data/lib/meilisearch/client.rb +2 -72
- data/lib/meilisearch/client/health.rb +5 -5
- data/lib/meilisearch/client/indexes.rb +54 -14
- data/lib/meilisearch/client/keys.rb +9 -9
- data/lib/meilisearch/client/stats.rb +7 -23
- data/lib/meilisearch/error.rb +29 -1
- data/lib/meilisearch/http_request.rb +78 -0
- data/lib/meilisearch/index.rb +42 -0
- data/lib/meilisearch/index/base.rb +36 -0
- data/lib/meilisearch/index/documents.rb +52 -0
- data/lib/meilisearch/index/search.rb +11 -0
- data/lib/meilisearch/index/settings.rb +27 -0
- data/lib/meilisearch/index/stats.rb +27 -0
- data/lib/meilisearch/index/stop_words.rb +28 -0
- data/lib/meilisearch/index/synonyms.rb +52 -0
- data/lib/meilisearch/index/updates.rb +15 -0
- data/lib/meilisearch/version.rb +1 -1
- metadata +15 -10
- data/lib/meilisearch/client/documents.rb +0 -41
- data/lib/meilisearch/client/objects.rb +0 -37
- data/lib/meilisearch/client/prepare.rb +0 -11
- data/lib/meilisearch/client/search.rb +0 -11
- data/lib/meilisearch/dataset.rb +0 -76
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 25dd43cb7f3a566eac6eb6b9cc195bf10fbb29a98b1b6b85efcfac3e5e068edd
|
|
4
|
+
data.tar.gz: 73631da64c2a50f196e459f5696fa0a2d2d4075778dba5dca5777bce99098d7e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4f2747c0d558e2cf31b6c169735f38a243ddfeac2a86b932b2e32c3ea47335350a045b10645c5e42687bd0e8dce8b0656d42ae51f1286dabdc403f5e4762ad3e
|
|
7
|
+
data.tar.gz: 9c78a7b30755ce6da5a81153108d52dd63203a251358d2b6a8d7811bce329b812970b77dacbbf9f9b42183229ef14c3a72e6bb37e7f828269c129b410066164b
|
data/lib/meilisearch.rb
CHANGED
data/lib/meilisearch/client.rb
CHANGED
|
@@ -1,86 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require '
|
|
4
|
-
|
|
5
|
-
require 'meilisearch/error'
|
|
3
|
+
require 'meilisearch/http_request'
|
|
6
4
|
require 'meilisearch/client/keys'
|
|
7
5
|
require 'meilisearch/client/stats'
|
|
8
6
|
require 'meilisearch/client/health'
|
|
9
7
|
require 'meilisearch/client/indexes'
|
|
10
|
-
require 'meilisearch/client/documents'
|
|
11
|
-
require 'meilisearch/client/prepare'
|
|
12
|
-
require 'meilisearch/client/search'
|
|
13
8
|
|
|
14
9
|
module MeiliSearch
|
|
15
|
-
class Client
|
|
16
|
-
include HTTParty
|
|
17
|
-
|
|
10
|
+
class Client < HTTPRequest
|
|
18
11
|
include MeiliSearch::Client::Keys
|
|
19
12
|
include MeiliSearch::Client::Stats
|
|
20
13
|
include MeiliSearch::Client::Health
|
|
21
14
|
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
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def get(path = '', query = {})
|
|
35
|
-
response = self.class.get(
|
|
36
|
-
(@base_url + path),
|
|
37
|
-
query: query,
|
|
38
|
-
headers: @headers
|
|
39
|
-
)
|
|
40
|
-
validate(response)
|
|
41
|
-
end
|
|
42
|
-
|
|
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)
|
|
57
|
-
end
|
|
58
|
-
|
|
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)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def delete(path = '')
|
|
69
|
-
response = self.class.delete(
|
|
70
|
-
(@base_url + path),
|
|
71
|
-
headers: @headers
|
|
72
|
-
)
|
|
73
|
-
validate(response)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
private
|
|
77
|
-
|
|
78
|
-
def validate(response)
|
|
79
|
-
unless response.success?
|
|
80
|
-
raise ClientError, "#{response.code}: #{response.message}\n#{response.body}"
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
response.parsed_response
|
|
84
|
-
end
|
|
85
15
|
end
|
|
86
16
|
end
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module MeiliSearch
|
|
4
|
-
class Client
|
|
4
|
+
class Client < HTTPRequest
|
|
5
5
|
module Health
|
|
6
|
-
def
|
|
7
|
-
|
|
6
|
+
def healthy?
|
|
7
|
+
http_get '/health'
|
|
8
8
|
true
|
|
9
9
|
rescue StandardError
|
|
10
10
|
false
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def health
|
|
14
|
-
|
|
14
|
+
http_get '/health'
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def update_health(bool)
|
|
18
|
-
|
|
18
|
+
http_put '/health', health: bool
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
end
|
|
@@ -1,30 +1,70 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module MeiliSearch
|
|
4
|
-
class Client
|
|
4
|
+
class Client < HTTPRequest
|
|
5
5
|
module Indexes
|
|
6
6
|
def indexes
|
|
7
|
-
|
|
7
|
+
http_get '/indexes'
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
def
|
|
11
|
-
|
|
10
|
+
def show_index(index_uid)
|
|
11
|
+
index_object(index_uid).show
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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'])
|
|
20
28
|
end
|
|
21
29
|
|
|
22
|
-
def
|
|
23
|
-
|
|
30
|
+
def delete_index(index_uid)
|
|
31
|
+
index_object(index_uid).delete
|
|
24
32
|
end
|
|
25
33
|
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
28
68
|
end
|
|
29
69
|
end
|
|
30
70
|
end
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module MeiliSearch
|
|
4
|
-
class Client
|
|
4
|
+
class Client < HTTPRequest
|
|
5
5
|
module Keys
|
|
6
6
|
def keys
|
|
7
|
-
|
|
7
|
+
http_get '/keys'
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
def key(
|
|
11
|
-
|
|
10
|
+
def key(key)
|
|
11
|
+
http_get "/keys/#{key}"
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def create_key(options = {})
|
|
15
|
-
|
|
15
|
+
http_post '/keys', options
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
def update_key(
|
|
19
|
-
|
|
18
|
+
def update_key(key, options = {})
|
|
19
|
+
http_put "/keys/#{key}", options
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
def delete_key(
|
|
23
|
-
|
|
22
|
+
def delete_key(key)
|
|
23
|
+
http_delete "/keys/#{key}"
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -1,38 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module MeiliSearch
|
|
4
|
-
class Client
|
|
4
|
+
class Client < HTTPRequest
|
|
5
5
|
module Stats
|
|
6
6
|
def version
|
|
7
|
-
|
|
7
|
+
http_get '/version'
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def sysinfo
|
|
11
|
-
|
|
11
|
+
http_get '/sys-info'
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
def
|
|
15
|
-
|
|
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']
|
|
14
|
+
def pretty_sysinfo
|
|
15
|
+
http_get '/sys-info/pretty'
|
|
24
16
|
end
|
|
25
17
|
|
|
26
|
-
def
|
|
27
|
-
|
|
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']
|
|
18
|
+
def stats
|
|
19
|
+
http_get '/stats'
|
|
36
20
|
end
|
|
37
21
|
end
|
|
38
22
|
end
|
data/lib/meilisearch/error.rb
CHANGED
|
@@ -2,5 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
module MeiliSearch
|
|
4
4
|
class MeiliSearchError < StandardError; end
|
|
5
|
-
class
|
|
5
|
+
class IndexIdentifierError < MeiliSearchError; end
|
|
6
|
+
|
|
7
|
+
class HTTPError < MeiliSearchError
|
|
8
|
+
attr_reader :status
|
|
9
|
+
attr_reader :message
|
|
10
|
+
attr_reader :http_body
|
|
11
|
+
attr_reader :http_body_message
|
|
12
|
+
attr_reader :details
|
|
13
|
+
|
|
14
|
+
alias code status
|
|
15
|
+
alias body http_body
|
|
16
|
+
alias body_message http_body_message
|
|
17
|
+
|
|
18
|
+
def initialize(status, message, http_body, details = nil)
|
|
19
|
+
@status = status
|
|
20
|
+
unless http_body.nil? || http_body.empty?
|
|
21
|
+
@http_body = JSON.parse(http_body)
|
|
22
|
+
@http_body_message = @http_body['message']
|
|
23
|
+
end
|
|
24
|
+
@message = message.capitalize
|
|
25
|
+
@message = "#{@message} - #{@http_body_message.capitalize}" unless @http_body_message.nil?
|
|
26
|
+
@details = details
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def to_s
|
|
30
|
+
final_message = @details.nil? ? @message : "#{@message}. #{@details}"
|
|
31
|
+
"#{@status}: #{final_message}."
|
|
32
|
+
end
|
|
33
|
+
end
|
|
6
34
|
end
|
|
@@ -0,0 +1,78 @@
|
|
|
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 = {})
|
|
20
|
+
response = self.class.get(
|
|
21
|
+
@base_url + path,
|
|
22
|
+
query: query,
|
|
23
|
+
headers: @headers
|
|
24
|
+
)
|
|
25
|
+
validate(response)
|
|
26
|
+
end
|
|
27
|
+
|
|
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(
|
|
46
|
+
@base_url + path,
|
|
47
|
+
body: body.to_json,
|
|
48
|
+
headers: @headers
|
|
49
|
+
)
|
|
50
|
+
validate(response)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def http_patch(path = '', body = {})
|
|
54
|
+
response = self.class.patch(
|
|
55
|
+
@base_url + path,
|
|
56
|
+
body: body.to_json,
|
|
57
|
+
headers: @headers
|
|
58
|
+
)
|
|
59
|
+
validate(response)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def http_delete(path = '')
|
|
63
|
+
response = self.class.delete(
|
|
64
|
+
@base_url + path,
|
|
65
|
+
headers: @headers
|
|
66
|
+
)
|
|
67
|
+
validate(response)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
private
|
|
71
|
+
|
|
72
|
+
def validate(response)
|
|
73
|
+
raise HTTPError.new(response.code, response.message, response.body) unless response.success?
|
|
74
|
+
|
|
75
|
+
response.parsed_response
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
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'
|
|
12
|
+
|
|
13
|
+
module MeiliSearch
|
|
14
|
+
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
|
+
attr_reader :uid
|
|
25
|
+
|
|
26
|
+
def initialize(index_uid, url, api_key = nil)
|
|
27
|
+
@uid = index_uid
|
|
28
|
+
super(url, api_key)
|
|
29
|
+
end
|
|
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']
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
data/lib/meilisearch/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.8.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
|
+
date: 2019-12-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httparty
|
|
@@ -24,7 +24,7 @@ dependencies:
|
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: 0.17.1
|
|
27
|
-
description:
|
|
27
|
+
description: An easy-to-use ruby client for Meilisearch API. See https://github.com/meilisearch/MeiliSearch
|
|
28
28
|
email: bonjour@meilisearch.com
|
|
29
29
|
executables: []
|
|
30
30
|
extensions: []
|
|
@@ -32,18 +32,23 @@ extra_rdoc_files: []
|
|
|
32
32
|
files:
|
|
33
33
|
- lib/meilisearch.rb
|
|
34
34
|
- lib/meilisearch/client.rb
|
|
35
|
-
- lib/meilisearch/client/documents.rb
|
|
36
35
|
- lib/meilisearch/client/health.rb
|
|
37
36
|
- lib/meilisearch/client/indexes.rb
|
|
38
37
|
- lib/meilisearch/client/keys.rb
|
|
39
|
-
- lib/meilisearch/client/objects.rb
|
|
40
|
-
- lib/meilisearch/client/prepare.rb
|
|
41
|
-
- lib/meilisearch/client/search.rb
|
|
42
38
|
- lib/meilisearch/client/stats.rb
|
|
43
|
-
- lib/meilisearch/dataset.rb
|
|
44
39
|
- lib/meilisearch/error.rb
|
|
40
|
+
- lib/meilisearch/http_request.rb
|
|
41
|
+
- 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
|
|
45
50
|
- lib/meilisearch/version.rb
|
|
46
|
-
homepage: https://github.com/meilisearch/ruby
|
|
51
|
+
homepage: https://github.com/meilisearch/meilisearch-ruby
|
|
47
52
|
licenses:
|
|
48
53
|
- MIT
|
|
49
54
|
metadata: {}
|
|
@@ -65,5 +70,5 @@ requirements: []
|
|
|
65
70
|
rubygems_version: 3.0.3
|
|
66
71
|
signing_key:
|
|
67
72
|
specification_version: 4
|
|
68
|
-
summary:
|
|
73
|
+
summary: An easy-to-use ruby client for Meilisearch API
|
|
69
74
|
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,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
|
data/lib/meilisearch/dataset.rb
DELETED
|
@@ -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
|