algolia 2.0.0.pre.alpha.3 → 2.0.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/.gitignore +1 -0
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +1 -1
- data/README.md +18 -10
- data/SECURITY.md +3 -0
- data/algolia.gemspec +9 -3
- data/lib/algolia.rb +1 -1
- data/lib/algolia/analytics_client.rb +1 -1
- data/lib/algolia/config/analytics_config.rb +2 -2
- data/lib/algolia/config/base_config.rb +43 -0
- data/lib/algolia/config/insights_config.rb +2 -2
- data/lib/algolia/config/recommendation_config.rb +2 -2
- data/lib/algolia/config/search_config.rb +2 -2
- data/lib/algolia/defaults.rb +2 -2
- data/lib/algolia/error.rb +1 -2
- data/lib/algolia/helpers.rb +3 -2
- data/lib/algolia/insights_client.rb +1 -1
- data/lib/algolia/iterators/object_iterator.rb +5 -4
- data/lib/algolia/iterators/paginator_iterator.rb +5 -3
- data/lib/algolia/recommendation_client.rb +1 -1
- data/lib/algolia/search_client.rb +1 -1
- data/lib/algolia/search_index.rb +37 -37
- data/lib/algolia/transport/transport.rb +4 -4
- data/lib/algolia/version.rb +1 -1
- data/sig/config/algolia_config.rbs +3 -3
- data/sig/config/analytics_config.rbs +1 -1
- data/sig/config/insights_config.rbs +1 -1
- data/sig/config/recommendation_config.rbs +1 -1
- data/sig/config/search_config.rbs +1 -1
- data/test/algolia/integration/analytics_client_test.rb +6 -6
- data/test/algolia/integration/insights_client_test.rb +11 -11
- data/test/algolia/integration/search_client_test.rb +20 -11
- data/test/algolia/unit/algolia_config_test.rb +16 -0
- data/test/algolia/unit/helpers_test.rb +18 -1
- data/test/algolia/unit/retry_strategy_test.rb +3 -3
- data/test/test_helper.rb +1 -1
- data/upgrade_guide.md +30 -22
- metadata +20 -14
- data/lib/algolia/config/algolia_config.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 555e432d41a84d3031f58dc7c74acf5297df48fe693fadf977c6b15547a82d6b
|
4
|
+
data.tar.gz: a3fbbc9ba6552b0b432a20e34cd5cf7a311f339c2df7f7a3c549ced84f409ba0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 757d57c2723f3f036bfb7faa38615fd751311e99b0a3f5e1b3c13087c53a9010af88c99a5412e31bb3e6d3cdb9201478d7100c71080b3fe948004170a870f875
|
7
|
+
data.tar.gz: ede51228b6bc2498b65434102f8b25b17d7db74ae74cd2b50a1ec7184f42692e4b24d94de8c621ec91a8192c924e71ac1067bfdde038a03936407f12147b6175
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -6,9 +6,9 @@
|
|
6
6
|
<h4 align="center">The perfect starting point to integrate <a href="https://algolia.com" target="_blank">Algolia</a> within your Ruby project</h4>
|
7
7
|
|
8
8
|
<p align="center">
|
9
|
-
<a href="https://circleci.com/gh/algolia/algoliasearch-client-ruby
|
10
|
-
<a href="https://rubygems.org/gems/
|
11
|
-
<a href="https://rubygems.org/gems/
|
9
|
+
<a href="https://circleci.com/gh/algolia/algoliasearch-client-ruby"><img src="https://circleci.com/gh/algolia/algoliasearch-client-ruby/tree/release%2Fv2.svg?style=shield" alt="CircleCI" /></a>
|
10
|
+
<a href="https://rubygems.org/gems/algolia"><img src="https://badge.fury.io/rb/algoliasearch.svg" alt="Gem Version"></a>
|
11
|
+
<a href="https://rubygems.org/gems/algolia"><img src="https://img.shields.io/badge/licence-MIT-blue.svg" alt="License"></a>
|
12
12
|
</p>
|
13
13
|
</p>
|
14
14
|
|
@@ -18,39 +18,47 @@
|
|
18
18
|
<a href="https://discourse.algolia.com" target="_blank">Community Forum</a> •
|
19
19
|
<a href="http://stackoverflow.com/questions/tagged/algolia" target="_blank">Stack Overflow</a> •
|
20
20
|
<a href="https://github.com/algolia/algoliasearch-client-ruby/issues" target="_blank">Report a bug</a> •
|
21
|
+
<a href="https://www.algolia.com/doc/api-client/troubleshooting/faq/ruby/" target="_blank">FAQ</a> •
|
21
22
|
<a href="https://www.algolia.com/support" target="_blank">Support</a>
|
22
23
|
</p>
|
23
24
|
|
24
25
|
## ✨ Features
|
25
26
|
|
26
27
|
- Thin & minimal low-level HTTP client to interact with Algolia's API
|
27
|
-
- Supports Ruby `^
|
28
|
+
- Supports Ruby `^2.2`.
|
28
29
|
|
29
30
|
## 💡 Getting Started
|
30
31
|
|
31
32
|
First, install Algolia Ruby API Client via the [RubyGems](https://rubygems.org/) package manager:
|
32
33
|
```bash
|
33
|
-
gem install
|
34
|
+
gem install algolia
|
34
35
|
```
|
35
36
|
|
36
37
|
Then, create objects on your index:
|
37
38
|
|
38
39
|
|
39
40
|
```ruby
|
40
|
-
Algolia.
|
41
|
-
|
42
|
-
index = Algolia::Index.new('your_index_name')
|
41
|
+
client = Algolia::Search::Client.create('YourApplicationID', 'YourAPIKey')
|
42
|
+
index = client.init_index('your_index_name')
|
43
43
|
|
44
|
-
index.save_objects([objectID:
|
44
|
+
index.save_objects([objectID: 1, name: 'Foo'])
|
45
45
|
```
|
46
46
|
|
47
47
|
Finally, you may begin searching a object using the `search` method:
|
48
48
|
```ruby
|
49
|
-
objects = index.search('
|
49
|
+
objects = index.search('Foo')
|
50
50
|
```
|
51
51
|
|
52
52
|
For full documentation, visit the **[Algolia Ruby API Client](https://www.algolia.com/doc/api-client/getting-started/install/ruby/)**.
|
53
53
|
|
54
|
+
## ❓ Troubleshooting
|
55
|
+
|
56
|
+
Encountering an issue? Before reaching out to support, we recommend heading to our [FAQ](https://www.algolia.com/doc/api-client/troubleshooting/faq/ruby/) where you will find answers for the most common issues and gotchas with the client.
|
57
|
+
|
58
|
+
## Upgrade from V1 to V2
|
59
|
+
|
60
|
+
If you were using the v1 and wish to update to v2, please follow our [Upgrade Guide](upgrade_guide.md)
|
61
|
+
|
54
62
|
## 📄 License
|
55
63
|
|
56
64
|
Algolia Ruby API Client is an open-sourced software licensed under the [MIT license](LICENSE.md).
|
data/SECURITY.md
ADDED
data/algolia.gemspec
CHANGED
@@ -12,9 +12,15 @@ Gem::Specification.new do |spec|
|
|
12
12
|
|
13
13
|
spec.date = Date.today
|
14
14
|
spec.licenses = ['MIT']
|
15
|
-
spec.summary = 'A simple Ruby client for the algolia.com REST API
|
16
|
-
spec.description = '
|
17
|
-
spec.homepage = 'https://github.com/algolia/algoliasearch-client-ruby
|
15
|
+
spec.summary = 'A simple Ruby client for the algolia.com REST API'
|
16
|
+
spec.description = 'A simple Ruby client for the algolia.com REST API'
|
17
|
+
spec.homepage = 'https://github.com/algolia/algoliasearch-client-ruby'
|
18
|
+
|
19
|
+
spec.metadata = {
|
20
|
+
'bug_tracker_uri' => 'https://github.com/algolia/algoliasearch-client-ruby/issues',
|
21
|
+
'documentation_uri' => 'https://www.algolia.com/doc/api-client/getting-started/install/ruby',
|
22
|
+
'source_code_uri' => 'https://github.com/algolia/algoliasearch-client-ruby'
|
23
|
+
}
|
18
24
|
|
19
25
|
# Specify which files should be added to the gem when it is released.
|
20
26
|
# The `git ls-files -z` loads the files in the RubyGem
|
data/lib/algolia.rb
CHANGED
@@ -3,7 +3,7 @@ require 'algolia/helpers'
|
|
3
3
|
require 'algolia/http/http_requester'
|
4
4
|
require 'algolia/defaults'
|
5
5
|
require 'algolia/user_agent'
|
6
|
-
require 'algolia/config/
|
6
|
+
require 'algolia/config/base_config'
|
7
7
|
require 'algolia/config/search_config'
|
8
8
|
require 'algolia/config/analytics_config'
|
9
9
|
require 'algolia/config/insights_config'
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Algolia
|
2
2
|
module Analytics
|
3
|
-
class Config <
|
3
|
+
class Config < BaseConfig
|
4
4
|
attr_accessor :region, :default_hosts
|
5
5
|
|
6
6
|
# Initialize a config
|
7
7
|
#
|
8
|
-
# @option options [String] :
|
8
|
+
# @option options [String] :application_id
|
9
9
|
# @option options [String] :api_key
|
10
10
|
# @option options [String] :region
|
11
11
|
#
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Algolia
|
4
|
+
class BaseConfig
|
5
|
+
attr_accessor :app_id, :api_key, :headers, :batch_size, :read_timeout, :write_timeout, :connect_timeout, :compression_type,
|
6
|
+
:symbolize_keys, :use_latest_settings
|
7
|
+
|
8
|
+
#
|
9
|
+
# @option options [String] :application_id
|
10
|
+
# @option options [String] :api_key
|
11
|
+
# @option options [Integer] :batch_size
|
12
|
+
# @option options [Integer] :read_timeout
|
13
|
+
# @option options [Integer] :write_timeout
|
14
|
+
# @option options [Integer] :connect_timeout
|
15
|
+
# @option options [Boolean] :symbolize_keys
|
16
|
+
#
|
17
|
+
def initialize(opts = {})
|
18
|
+
raise AlgoliaError, 'No Application ID provided, please set :application_id' unless opts.has_key?(:application_id)
|
19
|
+
raise AlgoliaError, 'No API key provided, please set :api_key' unless opts.has_key?(:api_key)
|
20
|
+
|
21
|
+
@app_id = opts[:application_id]
|
22
|
+
@api_key = opts[:api_key]
|
23
|
+
|
24
|
+
@headers = {
|
25
|
+
Defaults::HEADER_API_KEY => @api_key,
|
26
|
+
Defaults::HEADER_APP_ID => @app_id,
|
27
|
+
'Content-Type' => 'application/json; charset=utf-8',
|
28
|
+
'User-Agent' => UserAgent.value
|
29
|
+
}
|
30
|
+
|
31
|
+
@batch_size = opts[:batch_size] || Defaults::BATCH_SIZE
|
32
|
+
@read_timeout = opts[:read_timeout] || Defaults::READ_TIMEOUT
|
33
|
+
@write_timeout = opts[:write_timeout] || Defaults::WRITE_TIMEOUT
|
34
|
+
@connect_timeout = opts[:connect_timeout] || Defaults::CONNECT_TIMEOUT
|
35
|
+
@compression_type = opts[:compression_type] || Defaults::NONE_ENCODING
|
36
|
+
@symbolize_keys = opts.has_key?(:symbolize_keys) ? opts[:symbolize_keys] : true
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_extra_header(key, value)
|
40
|
+
@headers[key] = value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Algolia
|
2
2
|
module Insights
|
3
|
-
class Config <
|
3
|
+
class Config < BaseConfig
|
4
4
|
attr_accessor :region, :default_hosts
|
5
5
|
|
6
6
|
# Initialize a config
|
7
7
|
#
|
8
|
-
# @option options [String] :
|
8
|
+
# @option options [String] :application_id
|
9
9
|
# @option options [String] :api_key
|
10
10
|
# @option options [String] :region
|
11
11
|
#
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Algolia
|
2
2
|
module Recommendation
|
3
|
-
class Config <
|
3
|
+
class Config < BaseConfig
|
4
4
|
attr_accessor :region, :default_hosts
|
5
5
|
|
6
6
|
# Initialize a config
|
7
7
|
#
|
8
|
-
# @option options [String] :
|
8
|
+
# @option options [String] :application_id
|
9
9
|
# @option options [String] :api_key
|
10
10
|
# @option options [String] :region
|
11
11
|
#
|
@@ -5,13 +5,13 @@ require 'algolia/enums/call_type'
|
|
5
5
|
|
6
6
|
module Algolia
|
7
7
|
module Search
|
8
|
-
class Config <
|
8
|
+
class Config < BaseConfig
|
9
9
|
include CallType
|
10
10
|
attr_accessor :default_hosts
|
11
11
|
|
12
12
|
# Initialize a config
|
13
13
|
#
|
14
|
-
# @option options [String] :
|
14
|
+
# @option options [String] :application_id
|
15
15
|
# @option options [String] :api_key
|
16
16
|
# @option options [Hash] :custom_hosts
|
17
17
|
#
|
data/lib/algolia/defaults.rb
CHANGED
@@ -24,8 +24,8 @@ module Defaults
|
|
24
24
|
|
25
25
|
BATCH_SIZE = 1000
|
26
26
|
CONNECT_TIMEOUT = 2
|
27
|
-
READ_TIMEOUT =
|
28
|
-
WRITE_TIMEOUT =
|
27
|
+
READ_TIMEOUT = 5
|
28
|
+
WRITE_TIMEOUT = 30
|
29
29
|
USER_AGENT = "Algolia for Ruby (#{Algolia::VERSION}), Ruby (#{RUBY_VERSION})"
|
30
30
|
|
31
31
|
WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY = 100
|
data/lib/algolia/error.rb
CHANGED
data/lib/algolia/helpers.rb
CHANGED
@@ -52,7 +52,7 @@ module Helpers
|
|
52
52
|
|
53
53
|
# Support to convert old settings to their new names
|
54
54
|
#
|
55
|
-
def deserialize_settings(data)
|
55
|
+
def deserialize_settings(data, symbolize_keys)
|
56
56
|
settings = symbolize_hash(data)
|
57
57
|
keys = {
|
58
58
|
attributesToIndex: 'searchableAttributes',
|
@@ -62,7 +62,8 @@ module Helpers
|
|
62
62
|
|
63
63
|
keys.each do |deprecated_key, current_key|
|
64
64
|
if settings.has_key?(deprecated_key)
|
65
|
-
|
65
|
+
key = symbolize_keys ? current_key.to_sym : current_key.to_s
|
66
|
+
settings[key] = settings.delete(deprecated_key)
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
@@ -7,16 +7,17 @@ module Algolia
|
|
7
7
|
data = {}
|
8
8
|
|
9
9
|
if @response
|
10
|
-
|
11
|
-
|
10
|
+
parsed_response = symbolize_hash(@response)
|
11
|
+
if parsed_response[:hits].length
|
12
|
+
parsed_response[:hits].each do |hit|
|
12
13
|
yield hit
|
13
14
|
end
|
14
15
|
|
15
|
-
if
|
16
|
+
if parsed_response[:cursor].nil?
|
16
17
|
@response = nil
|
17
18
|
raise StopIteration
|
18
19
|
else
|
19
|
-
data[:cursor] =
|
20
|
+
data[:cursor] = parsed_response[:cursor]
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
@@ -16,13 +16,15 @@ module Algolia
|
|
16
16
|
def each
|
17
17
|
loop do
|
18
18
|
if @response
|
19
|
-
|
20
|
-
|
19
|
+
parsed_response = symbolize_hash(@response)
|
20
|
+
parsed_data = symbolize_hash(@data)
|
21
|
+
if parsed_response[:hits].length
|
22
|
+
parsed_response[:hits].each do |hit|
|
21
23
|
hit.delete(:_highlightResult)
|
22
24
|
yield hit
|
23
25
|
end
|
24
26
|
|
25
|
-
if
|
27
|
+
if parsed_response[:nbHits] < parsed_data[:hitsPerPage]
|
26
28
|
@response = nil
|
27
29
|
@data = {
|
28
30
|
hitsPerPage: 1000,
|
@@ -24,7 +24,7 @@ module Algolia
|
|
24
24
|
# @return self
|
25
25
|
#
|
26
26
|
def self.create(app_id, api_key)
|
27
|
-
config = Recommendation::Config.new(
|
27
|
+
config = Recommendation::Config.new(application_id: app_id, api_key: api_key)
|
28
28
|
create_with_config(config)
|
29
29
|
end
|
30
30
|
|
data/lib/algolia/search_index.rb
CHANGED
@@ -5,16 +5,16 @@ module Algolia
|
|
5
5
|
include CallType
|
6
6
|
include Helpers
|
7
7
|
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :name, :transporter, :config
|
9
9
|
|
10
10
|
# Initialize an index
|
11
11
|
#
|
12
|
-
# @param
|
12
|
+
# @param name [String] name of the index
|
13
13
|
# @param transporter [Object] transport object used for the connection
|
14
14
|
# @param config [Config] a Config object which contains your APP_ID and API_KEY
|
15
15
|
#
|
16
|
-
def initialize(
|
17
|
-
@
|
16
|
+
def initialize(name, transporter, config)
|
17
|
+
@name = name
|
18
18
|
@transporter = transporter
|
19
19
|
@config = config
|
20
20
|
end
|
@@ -47,7 +47,7 @@ module Algolia
|
|
47
47
|
# @param opts [Hash] contains extra parameters to send with your query
|
48
48
|
#
|
49
49
|
def get_task_status(task_id, opts = {})
|
50
|
-
res = @transporter.read(:GET, path_encode('/1/indexes/%s/task/%s', @
|
50
|
+
res = @transporter.read(:GET, path_encode('/1/indexes/%s/task/%s', @name, task_id), {}, opts)
|
51
51
|
get_option(res, 'status')
|
52
52
|
end
|
53
53
|
|
@@ -56,7 +56,7 @@ module Algolia
|
|
56
56
|
# @param opts [Hash] contains extra parameters to send with your query
|
57
57
|
#
|
58
58
|
def clear_objects(opts = {})
|
59
|
-
response = @transporter.write(:POST, path_encode('/1/indexes/%s/clear', @
|
59
|
+
response = @transporter.write(:POST, path_encode('/1/indexes/%s/clear', @name), {}, opts)
|
60
60
|
|
61
61
|
IndexingResponse.new(self, response)
|
62
62
|
end
|
@@ -75,7 +75,7 @@ module Algolia
|
|
75
75
|
# @param opts [Hash] contains extra parameters to send with your query
|
76
76
|
#
|
77
77
|
def delete(opts = {})
|
78
|
-
response = @transporter.write(:DELETE, path_encode('/1/indexes/%s', @
|
78
|
+
response = @transporter.write(:DELETE, path_encode('/1/indexes/%s', @name), opts)
|
79
79
|
|
80
80
|
IndexingResponse.new(self, response)
|
81
81
|
end
|
@@ -115,7 +115,7 @@ module Algolia
|
|
115
115
|
has_next_page = true
|
116
116
|
while has_next_page
|
117
117
|
request_options[:page] = page
|
118
|
-
res = search(query, request_options)
|
118
|
+
res = symbolize_hash(search(query, request_options))
|
119
119
|
|
120
120
|
res[:hits].each_with_index do |hit, i|
|
121
121
|
if callback.call(hit)
|
@@ -154,7 +154,7 @@ module Algolia
|
|
154
154
|
# @return [IndexingResponse]
|
155
155
|
#
|
156
156
|
def copy_to(name, opts = {})
|
157
|
-
response = @transporter.write(:POST, path_encode('/1/indexes/%s/operation', @
|
157
|
+
response = @transporter.write(:POST, path_encode('/1/indexes/%s/operation', @name), { operation: 'copy', destination: name }, opts)
|
158
158
|
|
159
159
|
IndexingResponse.new(self, response)
|
160
160
|
end
|
@@ -167,7 +167,7 @@ module Algolia
|
|
167
167
|
# @return [IndexingResponse]
|
168
168
|
#
|
169
169
|
def move_to(name, opts = {})
|
170
|
-
response = @transporter.write(:POST, path_encode('/1/indexes/%s/operation', @
|
170
|
+
response = @transporter.write(:POST, path_encode('/1/indexes/%s/operation', @name), { operation: 'move', destination: name }, opts)
|
171
171
|
|
172
172
|
IndexingResponse.new(self, response)
|
173
173
|
end
|
@@ -184,7 +184,7 @@ module Algolia
|
|
184
184
|
# @return [Hash]
|
185
185
|
#
|
186
186
|
def get_object(object_id, opts = {})
|
187
|
-
@transporter.read(:GET, path_encode('/1/indexes/%s/%s', @
|
187
|
+
@transporter.read(:GET, path_encode('/1/indexes/%s/%s', @name, object_id), {}, opts)
|
188
188
|
end
|
189
189
|
|
190
190
|
# Retrieve one or more objects in a single API call
|
@@ -201,7 +201,7 @@ module Algolia
|
|
201
201
|
|
202
202
|
requests = []
|
203
203
|
object_ids.each do |object_id|
|
204
|
-
request = { indexName: @
|
204
|
+
request = { indexName: @name, objectID: object_id.to_s }
|
205
205
|
|
206
206
|
if attributes_to_retrieve
|
207
207
|
request[:attributesToRetrieve] = attributes_to_retrieve
|
@@ -381,7 +381,7 @@ module Algolia
|
|
381
381
|
# @return [IndexingResponse]
|
382
382
|
#
|
383
383
|
def delete_by(filters, opts = {})
|
384
|
-
response = @transporter.write(:POST, path_encode('/1/indexes/%s/deleteByQuery', @
|
384
|
+
response = @transporter.write(:POST, path_encode('/1/indexes/%s/deleteByQuery', @name), filters, opts)
|
385
385
|
|
386
386
|
IndexingResponse.new(self, response)
|
387
387
|
end
|
@@ -436,7 +436,7 @@ module Algolia
|
|
436
436
|
# @return [Hash]
|
437
437
|
#
|
438
438
|
def get_rule(object_id, opts = {})
|
439
|
-
@transporter.read(:GET, path_encode('/1/indexes/%s/rules/%s', @
|
439
|
+
@transporter.read(:GET, path_encode('/1/indexes/%s/rules/%s', @name, object_id), {}, opts)
|
440
440
|
end
|
441
441
|
|
442
442
|
# Create or update a rule
|
@@ -500,7 +500,7 @@ module Algolia
|
|
500
500
|
get_object_id(rule)
|
501
501
|
end
|
502
502
|
|
503
|
-
response = @transporter.write(:POST, path_encode('/1/indexes/%s/rules/batch', @
|
503
|
+
response = @transporter.write(:POST, path_encode('/1/indexes/%s/rules/batch', @name) + handle_params({ forwardToReplicas: forward_to_replicas, clearExistingRules: clear_existing_rules }), rules, request_options)
|
504
504
|
|
505
505
|
IndexingResponse.new(self, response)
|
506
506
|
end
|
@@ -532,7 +532,7 @@ module Algolia
|
|
532
532
|
request_options.delete(:forwardToReplicas)
|
533
533
|
end
|
534
534
|
|
535
|
-
response = @transporter.write(:POST, path_encode('1/indexes/%s/rules/clear', @
|
535
|
+
response = @transporter.write(:POST, path_encode('1/indexes/%s/rules/clear', @name) + handle_params({ forwardToReplicas: forward_to_replicas }), '', request_options)
|
536
536
|
|
537
537
|
IndexingResponse.new(self, response)
|
538
538
|
end
|
@@ -566,7 +566,7 @@ module Algolia
|
|
566
566
|
|
567
567
|
response = @transporter.write(
|
568
568
|
:DELETE,
|
569
|
-
path_encode('1/indexes/%s/rules/%s', @
|
569
|
+
path_encode('1/indexes/%s/rules/%s', @name, object_id) + handle_params({ forwardToReplicas: forward_to_replicas }),
|
570
570
|
'',
|
571
571
|
request_options
|
572
572
|
)
|
@@ -598,7 +598,7 @@ module Algolia
|
|
598
598
|
# @return [Hash]
|
599
599
|
#
|
600
600
|
def get_synonym(object_id, opts = {})
|
601
|
-
@transporter.read(:GET, path_encode('/1/indexes/%s/synonyms/%s', @
|
601
|
+
@transporter.read(:GET, path_encode('/1/indexes/%s/synonyms/%s', @name, object_id), {}, opts)
|
602
602
|
end
|
603
603
|
|
604
604
|
# Create a new synonym object or update the existing synonym object with the given object ID
|
@@ -666,7 +666,7 @@ module Algolia
|
|
666
666
|
end
|
667
667
|
response = @transporter.write(
|
668
668
|
:POST,
|
669
|
-
path_encode('/1/indexes/%s/synonyms/batch', @
|
669
|
+
path_encode('/1/indexes/%s/synonyms/batch', @name) + handle_params({ forwardToReplicas: forward_to_replicas, replaceExistingSynonyms: replace_existing_synonyms }),
|
670
670
|
synonyms,
|
671
671
|
request_options
|
672
672
|
)
|
@@ -703,7 +703,7 @@ module Algolia
|
|
703
703
|
end
|
704
704
|
response = @transporter.write(
|
705
705
|
:POST,
|
706
|
-
path_encode('1/indexes/%s/synonyms/clear', @
|
706
|
+
path_encode('1/indexes/%s/synonyms/clear', @name) + handle_params({ forwardToReplicas: forward_to_replicas }),
|
707
707
|
'',
|
708
708
|
request_options
|
709
709
|
)
|
@@ -738,7 +738,7 @@ module Algolia
|
|
738
738
|
end
|
739
739
|
response = @transporter.write(
|
740
740
|
:DELETE,
|
741
|
-
path_encode('1/indexes/%s/synonyms/%s', @
|
741
|
+
path_encode('1/indexes/%s/synonyms/%s', @name, object_id) + handle_params({ forwardToReplicas: forward_to_replicas }),
|
742
742
|
'',
|
743
743
|
request_options
|
744
744
|
)
|
@@ -769,9 +769,9 @@ module Algolia
|
|
769
769
|
#
|
770
770
|
def browse_objects(opts = {}, &block)
|
771
771
|
if block_given?
|
772
|
-
ObjectIterator.new(@transporter, @
|
772
|
+
ObjectIterator.new(@transporter, @name, opts).each(&block)
|
773
773
|
else
|
774
|
-
ObjectIterator.new(@transporter, @
|
774
|
+
ObjectIterator.new(@transporter, @name, opts)
|
775
775
|
end
|
776
776
|
end
|
777
777
|
|
@@ -783,9 +783,9 @@ module Algolia
|
|
783
783
|
#
|
784
784
|
def browse_rules(opts = {}, &block)
|
785
785
|
if block_given?
|
786
|
-
RuleIterator.new(@transporter, @
|
786
|
+
RuleIterator.new(@transporter, @name, opts).each(&block)
|
787
787
|
else
|
788
|
-
RuleIterator.new(@transporter, @
|
788
|
+
RuleIterator.new(@transporter, @name, opts)
|
789
789
|
end
|
790
790
|
end
|
791
791
|
|
@@ -797,9 +797,9 @@ module Algolia
|
|
797
797
|
#
|
798
798
|
def browse_synonyms(opts = {}, &block)
|
799
799
|
if block_given?
|
800
|
-
SynonymIterator.new(@transporter, @
|
800
|
+
SynonymIterator.new(@transporter, @name, opts).each(&block)
|
801
801
|
else
|
802
|
-
SynonymIterator.new(@transporter, @
|
802
|
+
SynonymIterator.new(@transporter, @name, opts)
|
803
803
|
end
|
804
804
|
end
|
805
805
|
|
@@ -822,7 +822,7 @@ module Algolia
|
|
822
822
|
request_options.delete(:safe)
|
823
823
|
end
|
824
824
|
|
825
|
-
tmp_index_name = @
|
825
|
+
tmp_index_name = @name + '_tmp_' + rand(10000000).to_s
|
826
826
|
copy_to_response = copy_to(tmp_index_name, request_options.merge({ scope: %w(settings synonyms rules) }))
|
827
827
|
|
828
828
|
if safe
|
@@ -839,7 +839,7 @@ module Algolia
|
|
839
839
|
save_objects_response.wait
|
840
840
|
end
|
841
841
|
|
842
|
-
move_to_response = tmp_index.move_to(@
|
842
|
+
move_to_response = tmp_index.move_to(@name)
|
843
843
|
if safe
|
844
844
|
move_to_response.wait
|
845
845
|
end
|
@@ -924,7 +924,7 @@ module Algolia
|
|
924
924
|
# @return [Hash]
|
925
925
|
#
|
926
926
|
def search(query, opts = {})
|
927
|
-
@transporter.read(:POST, path_encode('/1/indexes/%s/query', @
|
927
|
+
@transporter.read(:POST, path_encode('/1/indexes/%s/query', @name), { 'query': query.to_s }, opts)
|
928
928
|
end
|
929
929
|
|
930
930
|
# Search for values of a given facet, optionally restricting the returned values to those contained
|
@@ -937,7 +937,7 @@ module Algolia
|
|
937
937
|
# @return [Hash]
|
938
938
|
#
|
939
939
|
def search_for_facet_values(facet_name, facet_query, opts = {})
|
940
|
-
@transporter.read(:POST, path_encode('/1/indexes/%s/facets/%s/query', @
|
940
|
+
@transporter.read(:POST, path_encode('/1/indexes/%s/facets/%s/query', @name, facet_name),
|
941
941
|
{ 'facetQuery': facet_query }, opts)
|
942
942
|
end
|
943
943
|
|
@@ -949,7 +949,7 @@ module Algolia
|
|
949
949
|
# @return [Hash]
|
950
950
|
#
|
951
951
|
def search_synonyms(query, opts = {})
|
952
|
-
@transporter.read(:POST, path_encode('/1/indexes/%s/synonyms/search', @
|
952
|
+
@transporter.read(:POST, path_encode('/1/indexes/%s/synonyms/search', @name), { query: query.to_s }, opts)
|
953
953
|
end
|
954
954
|
|
955
955
|
# Search or browse all rules, optionally filtering them by type
|
@@ -960,7 +960,7 @@ module Algolia
|
|
960
960
|
# @return [Hash]
|
961
961
|
#
|
962
962
|
def search_rules(query, opts = {})
|
963
|
-
@transporter.read(:POST, path_encode('/1/indexes/%s/rules/search', @
|
963
|
+
@transporter.read(:POST, path_encode('/1/indexes/%s/rules/search', @name), { query: query.to_s }, opts)
|
964
964
|
end
|
965
965
|
|
966
966
|
# # # # # # # # # # # # # # # # # # # # #
|
@@ -974,9 +974,9 @@ module Algolia
|
|
974
974
|
# @return [Hash]
|
975
975
|
#
|
976
976
|
def get_settings(opts = {})
|
977
|
-
response = @transporter.read(:GET, path_encode('/1/indexes/%s/settings', @
|
977
|
+
response = @transporter.read(:GET, path_encode('/1/indexes/%s/settings', @name) + handle_params({ getVersion: 2 }), {}, opts)
|
978
978
|
|
979
|
-
deserialize_settings(response)
|
979
|
+
deserialize_settings(response, @config.symbolize_keys)
|
980
980
|
end
|
981
981
|
|
982
982
|
# Update some index settings. Only specified settings are overridden
|
@@ -987,7 +987,7 @@ module Algolia
|
|
987
987
|
# @return [IndexingResponse]
|
988
988
|
#
|
989
989
|
def set_settings(settings, opts = {})
|
990
|
-
response = @transporter.write(:PUT, path_encode('/1/indexes/%s/settings', @
|
990
|
+
response = @transporter.write(:PUT, path_encode('/1/indexes/%s/settings', @name), settings, opts)
|
991
991
|
|
992
992
|
IndexingResponse.new(self, response)
|
993
993
|
end
|
@@ -1087,7 +1087,7 @@ module Algolia
|
|
1087
1087
|
end
|
1088
1088
|
|
1089
1089
|
def raw_batch(requests, opts)
|
1090
|
-
@transporter.write(:POST, path_encode('/1/indexes/%s/batch', @
|
1090
|
+
@transporter.write(:POST, path_encode('/1/indexes/%s/batch', @name), { requests: requests }, opts)
|
1091
1091
|
end
|
1092
1092
|
end
|
1093
1093
|
end
|