algolia 2.0.0 → 2.3.2
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/.circleci/config.yml +11 -2
- data/.dockerignore +38 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +80 -1
- data/CONTRIBUTING.MD +184 -0
- data/DOCKER_README.MD +89 -0
- data/Dockerfile +7 -0
- data/README.md +4 -4
- data/SECURITY.md +1 -1
- data/algolia.gemspec +3 -1
- data/lib/algolia/analytics_client.rb +1 -1
- data/lib/algolia/config/personalization_config.rb +20 -0
- data/lib/algolia/config/recommend_config.rb +6 -0
- data/lib/algolia/config/recommendation_config.rb +2 -15
- data/lib/algolia/helpers.rb +51 -1
- data/lib/algolia/http/http_requester.rb +4 -4
- data/lib/algolia/insights_client.rb +1 -1
- data/lib/algolia/logger_helper.rb +1 -1
- data/lib/algolia/personalization_client.rb +60 -0
- data/lib/algolia/recommend_client.rb +134 -0
- data/lib/algolia/recommendation_client.rb +2 -55
- data/lib/algolia/responses/add_api_key_response.rb +1 -1
- data/lib/algolia/responses/delete_api_key_response.rb +1 -1
- data/lib/algolia/responses/dictionary_response.rb +33 -0
- data/lib/algolia/responses/restore_api_key_response.rb +1 -1
- data/lib/algolia/responses/update_api_key_response.rb +1 -1
- data/lib/algolia/search_client.rb +185 -8
- data/lib/algolia/search_index.rb +21 -56
- data/lib/algolia/transport/request_options.rb +1 -1
- data/lib/algolia/transport/transport.rb +11 -10
- data/lib/algolia/version.rb +1 -1
- data/lib/algolia.rb +5 -0
- data/renovate.json +5 -0
- data/test/algolia/integration/account_client_test.rb +2 -2
- data/test/algolia/integration/analytics_client_test.rb +6 -2
- data/test/algolia/integration/mocks/mock_requester.rb +13 -11
- data/test/algolia/integration/personalization_client_test.rb +30 -0
- data/test/algolia/integration/recommend_client_test.rb +70 -0
- data/test/algolia/integration/search_client_test.rb +108 -13
- data/test/algolia/integration/search_index_test.rb +31 -0
- data/test/algolia/unit/helpers_test.rb +4 -2
- data/test/test_helper.rb +32 -0
- metadata +45 -5
|
@@ -13,7 +13,7 @@ module Algolia
|
|
|
13
13
|
def initialize(insights_config, opts = {})
|
|
14
14
|
@config = insights_config
|
|
15
15
|
adapter = opts[:adapter] || Defaults::ADAPTER
|
|
16
|
-
logger = opts[:logger] || LoggerHelper.create
|
|
16
|
+
logger = opts[:logger] || LoggerHelper.create
|
|
17
17
|
requester = opts[:http_requester] || Defaults::REQUESTER_CLASS.new(adapter, logger)
|
|
18
18
|
@transporter = Transport::Transport.new(@config, requester)
|
|
19
19
|
end
|
|
@@ -5,7 +5,7 @@ module Algolia
|
|
|
5
5
|
# @param debug_file [nil|String] file used to output the logs
|
|
6
6
|
#
|
|
7
7
|
def self.create(debug_file = nil)
|
|
8
|
-
file = debug_file || File.new('debug.log')
|
|
8
|
+
file = debug_file || (ENV['ALGOLIA_DEBUG'] ? File.new('debug.log') : $stderr)
|
|
9
9
|
instance = ::Logger.new file
|
|
10
10
|
instance.progname = 'algolia'
|
|
11
11
|
instance
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module Algolia
|
|
2
|
+
module Personalization
|
|
3
|
+
class Client
|
|
4
|
+
# Initializes the Personalization client
|
|
5
|
+
#
|
|
6
|
+
# @param personalization_config [Personalization::Config] a Personalization::Config object which contains your APP_ID and API_KEY
|
|
7
|
+
# @option adapter [Object] adapter object used for the connection
|
|
8
|
+
# @option logger [Object]
|
|
9
|
+
# @option http_requester [Object] http_requester object used for the connection
|
|
10
|
+
#
|
|
11
|
+
def initialize(personalization_config, opts = {})
|
|
12
|
+
@config = personalization_config
|
|
13
|
+
adapter = opts[:adapter] || Defaults::ADAPTER
|
|
14
|
+
logger = opts[:logger] || LoggerHelper.create
|
|
15
|
+
requester = opts[:http_requester] || Defaults::REQUESTER_CLASS.new(adapter, logger)
|
|
16
|
+
@transporter = Transport::Transport.new(@config, requester)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Create a new client providing only app ID and API key
|
|
20
|
+
#
|
|
21
|
+
# @param app_id [String] Algolia application ID
|
|
22
|
+
# @param api_key [String] Algolia API key
|
|
23
|
+
#
|
|
24
|
+
# @return self
|
|
25
|
+
#
|
|
26
|
+
def self.create(app_id, api_key)
|
|
27
|
+
config = Personalization::Config.new(application_id: app_id, api_key: api_key)
|
|
28
|
+
create_with_config(config)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Create a new client providing only an Personalization::Config object
|
|
32
|
+
#
|
|
33
|
+
# @param config [Personalization::Config]
|
|
34
|
+
#
|
|
35
|
+
# @return self
|
|
36
|
+
#
|
|
37
|
+
def self.create_with_config(config)
|
|
38
|
+
new(config)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Set the personalization strategy.
|
|
42
|
+
#
|
|
43
|
+
# @param personalization_strategy [Hash] A strategy object.
|
|
44
|
+
#
|
|
45
|
+
# @return [Hash]
|
|
46
|
+
#
|
|
47
|
+
def set_personalization_strategy(personalization_strategy, opts = {})
|
|
48
|
+
@transporter.write(:POST, '1/strategies/personalization', personalization_strategy, opts)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Get the personalization strategy.
|
|
52
|
+
#
|
|
53
|
+
# @return [Hash]
|
|
54
|
+
#
|
|
55
|
+
def get_personalization_strategy(opts = {})
|
|
56
|
+
@transporter.read(:GET, '1/strategies/personalization', {}, opts)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
module Algolia
|
|
2
|
+
module Recommend
|
|
3
|
+
class Model
|
|
4
|
+
BOUGHT_TOGETHER = 'bought-together'
|
|
5
|
+
RELATED_PRODUCTS = 'related-products'
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class Client
|
|
9
|
+
include Helpers
|
|
10
|
+
|
|
11
|
+
# Initializes the Recommend client
|
|
12
|
+
#
|
|
13
|
+
# @param recommend_config [Recommend::Config] a Recommend::Config object which contains your APP_ID and API_KEY
|
|
14
|
+
# @option adapter [Object] adapter object used for the connection
|
|
15
|
+
# @option logger [Object]
|
|
16
|
+
# @option http_requester [Object] http_requester object used for the connection
|
|
17
|
+
#
|
|
18
|
+
def initialize(recommend_config, opts = {})
|
|
19
|
+
@config = recommend_config
|
|
20
|
+
adapter = opts[:adapter] || Defaults::ADAPTER
|
|
21
|
+
logger = opts[:logger] || LoggerHelper.create
|
|
22
|
+
requester = opts[:http_requester] || Defaults::REQUESTER_CLASS.new(adapter, logger)
|
|
23
|
+
@transporter = Transport::Transport.new(@config, requester)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Create a new client providing only app ID and API key
|
|
27
|
+
#
|
|
28
|
+
# @param app_id [String] Algolia application ID
|
|
29
|
+
# @param api_key [String] Algolia API key
|
|
30
|
+
#
|
|
31
|
+
# @return self
|
|
32
|
+
#
|
|
33
|
+
def self.create(app_id, api_key)
|
|
34
|
+
config = Recommend::Config.new(application_id: app_id, api_key: api_key)
|
|
35
|
+
create_with_config(config)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Create a new client providing only an Recommend::Config object
|
|
39
|
+
#
|
|
40
|
+
# @param config [Recommend::Config]
|
|
41
|
+
#
|
|
42
|
+
# @return self
|
|
43
|
+
#
|
|
44
|
+
def self.create_with_config(config)
|
|
45
|
+
new(config)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Get recommendation for the given queries
|
|
49
|
+
#
|
|
50
|
+
# @param requests [Array<Hash>] the queries to retrieve recommendations for
|
|
51
|
+
# @param opts [Hash] extra parameters to send with your request
|
|
52
|
+
#
|
|
53
|
+
# @return [Hash]
|
|
54
|
+
#
|
|
55
|
+
def get_recommendations(requests, opts = {})
|
|
56
|
+
@transporter.write(
|
|
57
|
+
:POST,
|
|
58
|
+
'/1/indexes/*/recommendations',
|
|
59
|
+
{ requests: format_recommendation_requests(symbolize_all(requests)) },
|
|
60
|
+
opts
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Get related products for the given requests
|
|
65
|
+
#
|
|
66
|
+
# @param requests [Array<Hash>] the requests to get related products for
|
|
67
|
+
# @param opts [Hash] extra parameters to send with your request
|
|
68
|
+
#
|
|
69
|
+
# @return [Hash]
|
|
70
|
+
#
|
|
71
|
+
def get_related_products(requests, opts = {})
|
|
72
|
+
get_recommendations(
|
|
73
|
+
set_request_models(symbolize_all(requests), Model::RELATED_PRODUCTS),
|
|
74
|
+
opts
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Get frequently bought together items for the given requests
|
|
79
|
+
#
|
|
80
|
+
# @param requests [Array<Hash>] the requests to get frequently bought together items for
|
|
81
|
+
# @param opts [Hash] extra parameters to send with your request
|
|
82
|
+
#
|
|
83
|
+
# @return [Hash]
|
|
84
|
+
#
|
|
85
|
+
def get_frequently_bought_together(requests, opts = {})
|
|
86
|
+
get_recommendations(
|
|
87
|
+
set_request_models(symbolize_all(requests), Model::BOUGHT_TOGETHER),
|
|
88
|
+
opts
|
|
89
|
+
)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
private
|
|
93
|
+
|
|
94
|
+
# Symbolize all hashes in an array
|
|
95
|
+
#
|
|
96
|
+
# @param hash_array [Array<Hash<String|Symbol, any>>] the hashes to symbolize
|
|
97
|
+
#
|
|
98
|
+
# @return [Array<Hash<Symbol, any>>]
|
|
99
|
+
#
|
|
100
|
+
def symbolize_all(hash_array)
|
|
101
|
+
hash_array.map { |q| symbolize_hash(q) }
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Format the recommendation requests
|
|
105
|
+
#
|
|
106
|
+
# @param requests [Array<Hash>] the requests to retrieve recommendations for
|
|
107
|
+
#
|
|
108
|
+
# @return [Array<Hash>]
|
|
109
|
+
#
|
|
110
|
+
def format_recommendation_requests(requests)
|
|
111
|
+
requests.map do |request|
|
|
112
|
+
request[:threshold] = 0 unless request[:threshold].is_a? Numeric
|
|
113
|
+
request.delete(:fallbackParameters) if request[:model] == Model::BOUGHT_TOGETHER
|
|
114
|
+
|
|
115
|
+
request
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# Force the requests to target a specific model
|
|
120
|
+
#
|
|
121
|
+
# @param requests [Array<Hash>] the requests to change
|
|
122
|
+
# @param model [String] the model to enforce
|
|
123
|
+
#
|
|
124
|
+
# @return [Array<Hash>]
|
|
125
|
+
#
|
|
126
|
+
def set_request_models(requests, model)
|
|
127
|
+
requests.map do |query|
|
|
128
|
+
query[:model] = model
|
|
129
|
+
query
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -1,60 +1,7 @@
|
|
|
1
1
|
module Algolia
|
|
2
2
|
module Recommendation
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
# @param recommendation_config [Recommendation::Config] a Recommendation::Config object which contains your APP_ID and API_KEY
|
|
7
|
-
# @option adapter [Object] adapter object used for the connection
|
|
8
|
-
# @option logger [Object]
|
|
9
|
-
# @option http_requester [Object] http_requester object used for the connection
|
|
10
|
-
#
|
|
11
|
-
def initialize(recommendation_config, opts = {})
|
|
12
|
-
@config = recommendation_config
|
|
13
|
-
adapter = opts[:adapter] || Defaults::ADAPTER
|
|
14
|
-
logger = opts[:logger] || LoggerHelper.create('debug.log')
|
|
15
|
-
requester = opts[:http_requester] || Defaults::REQUESTER_CLASS.new(adapter, logger)
|
|
16
|
-
@transporter = Transport::Transport.new(@config, requester)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# Create a new client providing only app ID and API key
|
|
20
|
-
#
|
|
21
|
-
# @param app_id [String] Algolia application ID
|
|
22
|
-
# @param api_key [String] Algolia API key
|
|
23
|
-
#
|
|
24
|
-
# @return self
|
|
25
|
-
#
|
|
26
|
-
def self.create(app_id, api_key)
|
|
27
|
-
config = Recommendation::Config.new(application_id: app_id, api_key: api_key)
|
|
28
|
-
create_with_config(config)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# Create a new client providing only an Recommendation::Config object
|
|
32
|
-
#
|
|
33
|
-
# @param config [Recommendation::Config]
|
|
34
|
-
#
|
|
35
|
-
# @return self
|
|
36
|
-
#
|
|
37
|
-
def self.create_with_config(config)
|
|
38
|
-
new(config)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# Set the personalization strategy.
|
|
42
|
-
#
|
|
43
|
-
# @param personalization_strategy [Hash] A strategy object.
|
|
44
|
-
#
|
|
45
|
-
# @return [Hash]
|
|
46
|
-
#
|
|
47
|
-
def set_personalization_strategy(personalization_strategy, opts = {})
|
|
48
|
-
@transporter.write(:POST, '1/strategies/personalization', personalization_strategy, opts)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# Get the personalization strategy.
|
|
52
|
-
#
|
|
53
|
-
# @return [Hash]
|
|
54
|
-
#
|
|
55
|
-
def get_personalization_strategy(opts = {})
|
|
56
|
-
@transporter.read(:GET, '1/strategies/personalization', {}, opts)
|
|
57
|
-
end
|
|
3
|
+
# <b>DEPRECATED:</b> Please use <tt>Algolia::Personalization::Client</tt> instead.
|
|
4
|
+
class Client < Algolia::Personalization::Client
|
|
58
5
|
end
|
|
59
6
|
end
|
|
60
7
|
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Algolia
|
|
2
|
+
class DictionaryResponse < BaseResponse
|
|
3
|
+
include CallType
|
|
4
|
+
|
|
5
|
+
attr_reader :raw_response
|
|
6
|
+
|
|
7
|
+
# @param client [Search::Client] Algolia Search Client used for verification
|
|
8
|
+
# @param response [Hash] Raw response from the client
|
|
9
|
+
#
|
|
10
|
+
def initialize(client, response)
|
|
11
|
+
@client = client
|
|
12
|
+
@raw_response = response
|
|
13
|
+
@done = false
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Wait for the task to complete
|
|
17
|
+
#
|
|
18
|
+
# @param opts [Hash] contains extra parameters to send with your query
|
|
19
|
+
#
|
|
20
|
+
def wait(_opts = {})
|
|
21
|
+
until @done
|
|
22
|
+
res = @client.custom_request({}, path_encode('/1/task/%s', @raw_response[:taskID]), :GET, READ)
|
|
23
|
+
status = get_option(res, 'status')
|
|
24
|
+
if status == 'published'
|
|
25
|
+
@done = true
|
|
26
|
+
end
|
|
27
|
+
sleep(Defaults::WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY / 1000)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
self
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -19,8 +19,8 @@ module Algolia
|
|
|
19
19
|
def initialize(search_config, opts = {})
|
|
20
20
|
@config = search_config
|
|
21
21
|
adapter = opts[:adapter] || Defaults::ADAPTER
|
|
22
|
-
logger
|
|
23
|
-
requester = opts[:http_requester] || Defaults::REQUESTER_CLASS.new(adapter, logger)
|
|
22
|
+
@logger = opts[:logger] || LoggerHelper.create
|
|
23
|
+
requester = opts[:http_requester] || Defaults::REQUESTER_CLASS.new(adapter, @logger)
|
|
24
24
|
@transporter = Transport::Transport.new(@config, requester)
|
|
25
25
|
end
|
|
26
26
|
|
|
@@ -80,7 +80,7 @@ module Algolia
|
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
# # # # # # # # # # # # # # # # # # # # #
|
|
83
|
-
#
|
|
83
|
+
# INDEX METHODS
|
|
84
84
|
# # # # # # # # # # # # # # # # # # # # #
|
|
85
85
|
|
|
86
86
|
# Initialize an index with a given name
|
|
@@ -90,11 +90,11 @@ module Algolia
|
|
|
90
90
|
# @return [Index] new Index instance
|
|
91
91
|
#
|
|
92
92
|
def init_index(index_name)
|
|
93
|
-
index_name.strip
|
|
94
|
-
if
|
|
93
|
+
stripped_index_name = index_name.strip
|
|
94
|
+
if stripped_index_name.empty?
|
|
95
95
|
raise AlgoliaError, 'Please provide a valid index name'
|
|
96
96
|
end
|
|
97
|
-
Index.new(
|
|
97
|
+
Index.new(stripped_index_name, @transporter, @config, @logger)
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
# List all indexes of the client
|
|
@@ -300,7 +300,7 @@ module Algolia
|
|
|
300
300
|
# @return [AddApiKeyResponse]
|
|
301
301
|
#
|
|
302
302
|
def add_api_key!(acl, opts = {})
|
|
303
|
-
response = add_api_key(acl)
|
|
303
|
+
response = add_api_key(acl, opts)
|
|
304
304
|
|
|
305
305
|
response.wait(opts)
|
|
306
306
|
end
|
|
@@ -478,8 +478,12 @@ module Algolia
|
|
|
478
478
|
# @return [Hash]
|
|
479
479
|
#
|
|
480
480
|
def multiple_queries(queries, opts = {})
|
|
481
|
+
queries.each do |q|
|
|
482
|
+
q[:params] = to_query_string(q[:params]) unless q[:params].nil? || q[:params].is_a?(String)
|
|
483
|
+
end
|
|
481
484
|
@transporter.read(:POST, '/1/indexes/*/queries', { requests: queries }, opts)
|
|
482
485
|
end
|
|
486
|
+
alias_method :search, :multiple_queries
|
|
483
487
|
|
|
484
488
|
# # # # # # # # # # # # # # # # # # # # #
|
|
485
489
|
# MCM METHODS
|
|
@@ -594,12 +598,185 @@ module Algolia
|
|
|
594
598
|
@transporter.read(:GET, '/1/clusters/mapping/pending' + handle_params({ getClusters: retrieve_mappings }), {}, request_options)
|
|
595
599
|
end
|
|
596
600
|
|
|
597
|
-
#
|
|
598
601
|
# Aliases the pending_mappings? method
|
|
599
602
|
#
|
|
600
603
|
alias_method :has_pending_mappings, :pending_mappings?
|
|
601
604
|
|
|
605
|
+
# # # # # # # # # # # # # # # # # # # # #
|
|
606
|
+
# CUSTOM DICTIONARIES METHODS
|
|
607
|
+
# # # # # # # # # # # # # # # # # # # # #
|
|
608
|
+
|
|
609
|
+
# Save entries for a given dictionary
|
|
610
|
+
#
|
|
611
|
+
# @param dictionary [String] dictionary name. Can be either 'stopwords', 'plurals' or 'compounds'
|
|
612
|
+
# @param dictionary_entries [Array<Hash>] array of dictionary entries
|
|
613
|
+
# @param opts [Hash] contains extra parameters to send with your query
|
|
614
|
+
#
|
|
615
|
+
# @return DictionaryResponse
|
|
616
|
+
#
|
|
617
|
+
def save_dictionary_entries(dictionary, dictionary_entries, opts = {})
|
|
618
|
+
response = @transporter.write(
|
|
619
|
+
:POST,
|
|
620
|
+
path_encode('/1/dictionaries/%s/batch', dictionary),
|
|
621
|
+
{ clearExistingDictionaryEntries: false, requests: chunk('addEntry', dictionary_entries) },
|
|
622
|
+
opts
|
|
623
|
+
)
|
|
624
|
+
|
|
625
|
+
DictionaryResponse.new(self, response)
|
|
626
|
+
end
|
|
627
|
+
|
|
628
|
+
# Save entries for a given dictionary and wait for the task to finish
|
|
629
|
+
#
|
|
630
|
+
# @param dictionary [String] dictionary name. Can be either 'stopwords', 'plurals' or 'compounds'
|
|
631
|
+
# @param dictionary_entries [Array<Hash>] array of dictionary entries
|
|
632
|
+
# @param opts [Hash] contains extra parameters to send with your query
|
|
633
|
+
#
|
|
634
|
+
def save_dictionary_entries!(dictionary, dictionary_entries, opts = {})
|
|
635
|
+
response = save_dictionary_entries(dictionary, dictionary_entries, opts)
|
|
636
|
+
|
|
637
|
+
response.wait(opts)
|
|
638
|
+
end
|
|
639
|
+
|
|
640
|
+
# Replace entries for a given dictionary
|
|
641
|
+
#
|
|
642
|
+
# @param dictionary [String] dictionary name. Can be either 'stopwords', 'plurals' or 'compounds'
|
|
643
|
+
# @param dictionary_entries [Array<Hash>] array of dictionary entries
|
|
644
|
+
# @param opts [Hash] contains extra parameters to send with your query
|
|
645
|
+
#
|
|
646
|
+
# @return DictionaryResponse
|
|
647
|
+
#
|
|
648
|
+
def replace_dictionary_entries(dictionary, dictionary_entries, opts = {})
|
|
649
|
+
response = @transporter.write(
|
|
650
|
+
:POST,
|
|
651
|
+
path_encode('/1/dictionaries/%s/batch', dictionary),
|
|
652
|
+
{ clearExistingDictionaryEntries: true, requests: chunk('addEntry', dictionary_entries) },
|
|
653
|
+
opts
|
|
654
|
+
)
|
|
655
|
+
|
|
656
|
+
DictionaryResponse.new(self, response)
|
|
657
|
+
end
|
|
658
|
+
|
|
659
|
+
# Replace entries for a given dictionary and wait for the task to finish
|
|
660
|
+
#
|
|
661
|
+
# @param dictionary [String] dictionary name. Can be either 'stopwords', 'plurals' or 'compounds'
|
|
662
|
+
# @param dictionary_entries [Array<Hash>] array of dictionary entries
|
|
663
|
+
# @param opts [Hash] contains extra parameters to send with your query
|
|
664
|
+
#
|
|
665
|
+
def replace_dictionary_entries!(dictionary, dictionary_entries, opts = {})
|
|
666
|
+
response = replace_dictionary_entries(dictionary, dictionary_entries, opts)
|
|
667
|
+
|
|
668
|
+
response.wait(opts)
|
|
669
|
+
end
|
|
670
|
+
|
|
671
|
+
# Delete entries for a given dictionary
|
|
672
|
+
#
|
|
673
|
+
# @param dictionary [String] dictionary name. Can be either 'stopwords', 'plurals' or 'compounds'
|
|
674
|
+
# @param object_ids [Array<Hash>] array of object ids
|
|
675
|
+
# @param opts [Hash] contains extra parameters to send with your query
|
|
676
|
+
#
|
|
677
|
+
# @return DictionaryResponse
|
|
678
|
+
#
|
|
679
|
+
def delete_dictionary_entries(dictionary, object_ids, opts = {})
|
|
680
|
+
request = object_ids.map do |object_id|
|
|
681
|
+
{ objectID: object_id }
|
|
682
|
+
end
|
|
683
|
+
response = @transporter.write(
|
|
684
|
+
:POST,
|
|
685
|
+
path_encode('/1/dictionaries/%s/batch', dictionary),
|
|
686
|
+
{ clearExistingDictionaryEntries: false, requests: chunk('deleteEntry', request) },
|
|
687
|
+
opts
|
|
688
|
+
)
|
|
689
|
+
|
|
690
|
+
DictionaryResponse.new(self, response)
|
|
691
|
+
end
|
|
692
|
+
|
|
693
|
+
# Delete entries for a given dictionary and wait for the task to finish
|
|
694
|
+
#
|
|
695
|
+
# @param dictionary [String] dictionary name. Can be either 'stopwords', 'plurals' or 'compounds'
|
|
696
|
+
# @param object_ids [Array<Hash>] array of object ids
|
|
697
|
+
# @param opts [Hash] contains extra parameters to send with your query
|
|
698
|
+
#
|
|
699
|
+
def delete_dictionary_entries!(dictionary, object_ids, opts = {})
|
|
700
|
+
response = delete_dictionary_entries(dictionary, object_ids, opts)
|
|
701
|
+
|
|
702
|
+
response.wait(opts)
|
|
703
|
+
end
|
|
704
|
+
|
|
705
|
+
# Clear all entries for a given dictionary
|
|
706
|
+
#
|
|
707
|
+
# @param dictionary [String] dictionary name. Can be either 'stopwords', 'plurals' or 'compounds'
|
|
708
|
+
# @param opts [Hash] contains extra parameters to send with your query
|
|
709
|
+
#
|
|
710
|
+
# @return DictionaryResponse
|
|
711
|
+
#
|
|
712
|
+
def clear_dictionary_entries(dictionary, opts = {})
|
|
713
|
+
replace_dictionary_entries(dictionary, [], opts)
|
|
714
|
+
end
|
|
715
|
+
|
|
716
|
+
# Clear all entries for a given dictionary and wait for the task to finish
|
|
717
|
+
#
|
|
718
|
+
# @param dictionary [String] dictionary name. Can be either 'stopwords', 'plurals' or 'compounds'
|
|
719
|
+
# @param opts [Hash] contains extra parameters to send with your query
|
|
720
|
+
#
|
|
721
|
+
def clear_dictionary_entries!(dictionary, opts = {})
|
|
722
|
+
response = replace_dictionary_entries(dictionary, [], opts)
|
|
723
|
+
|
|
724
|
+
response.wait(opts)
|
|
725
|
+
end
|
|
726
|
+
|
|
727
|
+
# Search entries for a given dictionary
|
|
728
|
+
#
|
|
729
|
+
# @param dictionary [String] dictionary name. Can be either 'stopwords', 'plurals' or 'compounds'
|
|
730
|
+
# @param query [String] query to send
|
|
731
|
+
# @param opts [Hash] contains extra parameters to send with your query
|
|
732
|
+
#
|
|
733
|
+
def search_dictionary_entries(dictionary, query, opts = {})
|
|
734
|
+
@transporter.read(
|
|
735
|
+
:POST,
|
|
736
|
+
path_encode('/1/dictionaries/%s/search', dictionary),
|
|
737
|
+
{ query: query },
|
|
738
|
+
opts
|
|
739
|
+
)
|
|
740
|
+
end
|
|
741
|
+
|
|
742
|
+
# Set settings for all the dictionaries
|
|
602
743
|
#
|
|
744
|
+
# @param dictionary_settings [Hash]
|
|
745
|
+
# @param opts [Hash] contains extra parameters to send with your query
|
|
746
|
+
#
|
|
747
|
+
# @return DictionaryResponse
|
|
748
|
+
#
|
|
749
|
+
def set_dictionary_settings(dictionary_settings, opts = {})
|
|
750
|
+
response = @transporter.write(:PUT, '/1/dictionaries/*/settings', dictionary_settings, opts)
|
|
751
|
+
|
|
752
|
+
DictionaryResponse.new(self, response)
|
|
753
|
+
end
|
|
754
|
+
|
|
755
|
+
# Set settings for all the dictionaries and wait for the task to finish
|
|
756
|
+
#
|
|
757
|
+
# @param dictionary_settings [Hash]
|
|
758
|
+
# @param opts [Hash] contains extra parameters to send with your query
|
|
759
|
+
#
|
|
760
|
+
# @return DictionaryResponse
|
|
761
|
+
#
|
|
762
|
+
def set_dictionary_settings!(dictionary_settings, opts = {})
|
|
763
|
+
response = set_dictionary_settings(dictionary_settings, opts)
|
|
764
|
+
|
|
765
|
+
response.wait(opts)
|
|
766
|
+
end
|
|
767
|
+
|
|
768
|
+
# Retrieve settings for all the dictionaries
|
|
769
|
+
#
|
|
770
|
+
# @param opts [Hash] contains extra parameters to send with your query
|
|
771
|
+
#
|
|
772
|
+
def get_dictionary_settings(opts = {})
|
|
773
|
+
@transporter.read(:GET, '/1/dictionaries/*/settings', {}, opts)
|
|
774
|
+
end
|
|
775
|
+
|
|
776
|
+
# # # # # # # # # # # # # # # # # # # # #
|
|
777
|
+
# MISC METHODS
|
|
778
|
+
# # # # # # # # # # # # # # # # # # # # #
|
|
779
|
+
|
|
603
780
|
# Method available to make custom requests to the API
|
|
604
781
|
#
|
|
605
782
|
def custom_request(data, uri, method, call_type, opts = {})
|