algoliasearch 1.5.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -6
- data/ChangeLog +3 -0
- data/lib/algolia/client.rb +297 -93
- data/lib/algolia/index.rb +111 -109
- data/lib/algolia/version.rb +1 -1
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 511e4c42adb37f4b590e19d4db50e168207206cf
|
4
|
+
data.tar.gz: 26b545014c375f33eb5cb5ecee8b1f2c9a2dfa8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd5b41f2dd31727913a7cf6d043aa6d95d7736258a6996a3ebdb16efbef6176b0c24f554b1406258c933c6a62abb8b45a8c8db1ed5a78c69e74e2dc3bf92da43
|
7
|
+
data.tar.gz: 185d83cf55c8a9778a15e17d1e5dece6ad317c973f7b1e912d4dcc22dbcead51e510d7045add8b2f6bb69ccefd72412965472fe4acc15c72defff99f415b076d
|
data/.travis.yml
CHANGED
data/ChangeLog
CHANGED
data/lib/algolia/client.rb
CHANGED
@@ -19,6 +19,8 @@ module Algolia
|
|
19
19
|
DEFAULT_SEARCH_TIMEOUT = 5
|
20
20
|
|
21
21
|
def initialize(data = {})
|
22
|
+
raise ArgumentError.new("No APPLICATION_ID provided, please set :application_id") if data[:application_id].nil?
|
23
|
+
|
22
24
|
@ssl = data[:ssl].nil? ? true : data[:ssl]
|
23
25
|
@ssl_version = data[:ssl_version].nil? ? nil : data[:ssl_version]
|
24
26
|
@application_id = data[:application_id]
|
@@ -38,6 +40,278 @@ module Algolia
|
|
38
40
|
}
|
39
41
|
end
|
40
42
|
|
43
|
+
#
|
44
|
+
# Initialize a new index
|
45
|
+
#
|
46
|
+
def init_index(name)
|
47
|
+
Index.new(name, self)
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Allow to set custom headers
|
52
|
+
#
|
53
|
+
def set_extra_header(key, value)
|
54
|
+
headers[key] = value
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# Allow to use IP rate limit when you have a proxy between end-user and Algolia.
|
59
|
+
# This option will set the X-Forwarded-For HTTP header with the client IP and the X-Forwarded-API-Key with the API Key having rate limits.
|
60
|
+
# @param admin_api_key the admin API Key you can find in your dashboard
|
61
|
+
# @param end_user_ip the end user IP (you can use both IPV4 or IPV6 syntax)
|
62
|
+
# @param rate_limit_api_key the API key on which you have a rate limit
|
63
|
+
#
|
64
|
+
def enable_rate_limit_forward(admin_api_key, end_user_ip, rate_limit_api_key)
|
65
|
+
headers[Protocol::HEADER_API_KEY] = admin_api_key
|
66
|
+
headers[Protocol::HEADER_FORWARDED_IP] = end_user_ip
|
67
|
+
headers[Protocol::HEADER_FORWARDED_API_KEY] = rate_limit_api_key
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# Disable IP rate limit enabled with enableRateLimitForward() function
|
72
|
+
#
|
73
|
+
def disable_rate_limit_forward
|
74
|
+
headers[Protocol::HEADER_API_KEY] = Algolia.client.api_key
|
75
|
+
headers.delete(Protocol::HEADER_FORWARDED_IP)
|
76
|
+
headers.delete(Protocol::HEADER_FORWARDED_API_KEY)
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# Convenience method thats wraps enable_rate_limit_forward/disable_rate_limit_forward
|
81
|
+
#
|
82
|
+
def with_rate_limits(end_user_ip, rate_limit_api_key, &block)
|
83
|
+
enable_rate_limit_forward(Algolia.client.api_key, end_user_ip, rate_limit_api_key)
|
84
|
+
begin
|
85
|
+
yield
|
86
|
+
ensure
|
87
|
+
disable_rate_limit_forward
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# This method allows to query multiple indexes with one API call
|
93
|
+
#
|
94
|
+
# @param queries the array of hash representing the query and associated index name
|
95
|
+
# @param index_name_key the name of the key used to fetch the index_name (:index_name by default)
|
96
|
+
# @param strategy define the strategy applied on the sequential searches (none by default)
|
97
|
+
#
|
98
|
+
def multiple_queries(queries, index_name_key = :index_name, strategy = "none")
|
99
|
+
requests = {
|
100
|
+
:requests => queries.map do |query|
|
101
|
+
indexName = query.delete(index_name_key) || query.delete(index_name_key.to_s)
|
102
|
+
encoded_params = Hash[query.map { |k,v| [k.to_s, v.is_a?(Array) ? v.to_json : v] }]
|
103
|
+
{ :indexName => indexName, :params => Protocol.to_query(encoded_params) }
|
104
|
+
end
|
105
|
+
}
|
106
|
+
post(Protocol.multiple_queries_uri(strategy), requests.to_json, :search)
|
107
|
+
end
|
108
|
+
|
109
|
+
#
|
110
|
+
# List all existing indexes
|
111
|
+
# return an Answer object with answer in the form
|
112
|
+
# {"items": [{ "name": "contacts", "createdAt": "2013-01-18T15:33:13.556Z"},
|
113
|
+
# {"name": "notes", "createdAt": "2013-01-18T15:33:13.556Z"}]}
|
114
|
+
#
|
115
|
+
def list_indexes
|
116
|
+
get(Protocol.indexes_uri, :read)
|
117
|
+
end
|
118
|
+
|
119
|
+
#
|
120
|
+
# Move an existing index.
|
121
|
+
# @param src_index the name of index to copy.
|
122
|
+
# @param dst_index the new index name that will contains a copy of srcIndexName (destination will be overriten if it already exist).
|
123
|
+
#
|
124
|
+
def move_index(src_index, dst_index)
|
125
|
+
request = {"operation" => "move", "destination" => dst_index};
|
126
|
+
post(Protocol.index_operation_uri(src_index), request.to_json)
|
127
|
+
end
|
128
|
+
|
129
|
+
#
|
130
|
+
# Move an existing index and wait until the move has been processed
|
131
|
+
# @param src_index the name of index to copy.
|
132
|
+
# @param dst_index the new index name that will contains a copy of srcIndexName (destination will be overriten if it already exist).
|
133
|
+
#
|
134
|
+
def move_index!(src_index, dst_index)
|
135
|
+
res = Algolia.move_index(src_index, dst_index)
|
136
|
+
init_index(dst_index).wait_task(res['taskID'])
|
137
|
+
res
|
138
|
+
end
|
139
|
+
|
140
|
+
#
|
141
|
+
# Copy an existing index.
|
142
|
+
# @param src_index the name of index to copy.
|
143
|
+
# @param dst_index the new index name that will contains a copy of srcIndexName (destination will be overriten if it already exist).
|
144
|
+
#
|
145
|
+
def copy_index(src_index, dst_index)
|
146
|
+
request = {"operation" => "copy", "destination" => dst_index};
|
147
|
+
Algolia.client.post(Protocol.index_operation_uri(src_index), request.to_json)
|
148
|
+
end
|
149
|
+
|
150
|
+
#
|
151
|
+
# Copy an existing index and wait until the copy has been processed.
|
152
|
+
# @param src_index the name of index to copy.
|
153
|
+
# @param dst_index the new index name that will contains a copy of srcIndexName (destination will be overriten if it already exist).
|
154
|
+
#
|
155
|
+
def copy_index!(src_index, dst_index)
|
156
|
+
res = Algolia.copy_index(src_index, dst_index)
|
157
|
+
init_index(dst_index).wait_task(res['taskID'])
|
158
|
+
res
|
159
|
+
end
|
160
|
+
|
161
|
+
# Delete an index
|
162
|
+
#
|
163
|
+
def delete_index(name)
|
164
|
+
init_index(name).delete
|
165
|
+
end
|
166
|
+
|
167
|
+
# Delete an index and wait until the deletion has been processed.
|
168
|
+
#
|
169
|
+
def delete_index!(name)
|
170
|
+
init_index(name).delete!
|
171
|
+
end
|
172
|
+
|
173
|
+
#
|
174
|
+
# Return last logs entries.
|
175
|
+
#
|
176
|
+
# @param offset Specify the first entry to retrieve (0-based, 0 is the most recent log entry).
|
177
|
+
# @param length Specify the maximum number of entries to retrieve starting at offset. Maximum allowed value: 1000.
|
178
|
+
#
|
179
|
+
def get_logs(offset = 0, length = 10, type = "all")
|
180
|
+
if (type.is_a?(true.class))
|
181
|
+
if (type)
|
182
|
+
type = "error"
|
183
|
+
else
|
184
|
+
type = "all"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
get(Protocol.logs(offset, length, type))
|
188
|
+
end
|
189
|
+
|
190
|
+
# List all existing user keys with their associated ACLs
|
191
|
+
def list_user_keys
|
192
|
+
get(Protocol.keys_uri, :read)
|
193
|
+
end
|
194
|
+
|
195
|
+
# Get ACL of a user key
|
196
|
+
def get_user_key(key)
|
197
|
+
get(Protocol.key_uri(key), :read)
|
198
|
+
end
|
199
|
+
|
200
|
+
#
|
201
|
+
# Create a new user key
|
202
|
+
#
|
203
|
+
# @param obj can be two different parameters:
|
204
|
+
# The list of parameters for this key. Defined by a NSDictionary that
|
205
|
+
# can contains the following values:
|
206
|
+
# - acl: array of string
|
207
|
+
# - indices: array of string
|
208
|
+
# - validity: int
|
209
|
+
# - referers: array of string
|
210
|
+
# - description: string
|
211
|
+
# - maxHitsPerQuery: integer
|
212
|
+
# - queryParameters: string
|
213
|
+
# - maxQueriesPerIPPerHour: integer
|
214
|
+
# Or the list of ACL for this key. Defined by an array of NSString that
|
215
|
+
# can contains the following values:
|
216
|
+
# - search: allow to search (https and http)
|
217
|
+
# - addObject: allows to add/update an object in the index (https only)
|
218
|
+
# - deleteObject : allows to delete an existing object (https only)
|
219
|
+
# - deleteIndex : allows to delete index content (https only)
|
220
|
+
# - settings : allows to get index settings (https only)
|
221
|
+
# - editSettings : allows to change index settings (https only)
|
222
|
+
# @param validity the number of seconds after which the key will be automatically removed (0 means no time limit for this key)
|
223
|
+
# @param maxQueriesPerIPPerHour the maximum number of API calls allowed from an IP address per hour (0 means unlimited)
|
224
|
+
# @param maxHitsPerQuery the maximum number of hits this API key can retrieve in one call (0 means unlimited)
|
225
|
+
# @param indexes the optional list of targeted indexes
|
226
|
+
#
|
227
|
+
def add_user_key(obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0, indexes = nil)
|
228
|
+
if obj.instance_of? Array
|
229
|
+
params = {
|
230
|
+
:acl => obj
|
231
|
+
}
|
232
|
+
else
|
233
|
+
params = obj
|
234
|
+
end
|
235
|
+
if validity != 0
|
236
|
+
params["validity"] = validity.to_i
|
237
|
+
end
|
238
|
+
if maxQueriesPerIPPerHour != 0
|
239
|
+
params["maxQueriesPerIPPerHour"] = maxQueriesPerIPPerHour.to_i
|
240
|
+
end
|
241
|
+
if maxHitsPerQuery != 0
|
242
|
+
params["maxHitsPerQuery"] = maxHitsPerQuery.to_i
|
243
|
+
end
|
244
|
+
params[:indexes] = indexes if indexes
|
245
|
+
post(Protocol.keys_uri, params.to_json)
|
246
|
+
end
|
247
|
+
|
248
|
+
#
|
249
|
+
# Update a user key
|
250
|
+
#
|
251
|
+
# @param obj can be two different parameters:
|
252
|
+
# The list of parameters for this key. Defined by a NSDictionary that
|
253
|
+
# can contains the following values:
|
254
|
+
# - acl: array of string
|
255
|
+
# - indices: array of string
|
256
|
+
# - validity: int
|
257
|
+
# - referers: array of string
|
258
|
+
# - description: string
|
259
|
+
# - maxHitsPerQuery: integer
|
260
|
+
# - queryParameters: string
|
261
|
+
# - maxQueriesPerIPPerHour: integer
|
262
|
+
# Or the list of ACL for this key. Defined by an array of NSString that
|
263
|
+
# can contains the following values:
|
264
|
+
# - search: allow to search (https and http)
|
265
|
+
# - addObject: allows to add/update an object in the index (https only)
|
266
|
+
# - deleteObject : allows to delete an existing object (https only)
|
267
|
+
# - deleteIndex : allows to delete index content (https only)
|
268
|
+
# - settings : allows to get index settings (https only)
|
269
|
+
# - editSettings : allows to change index settings (https only)
|
270
|
+
# @param validity the number of seconds after which the key will be automatically removed (0 means no time limit for this key)
|
271
|
+
# @param maxQueriesPerIPPerHour the maximum number of API calls allowed from an IP address per hour (0 means unlimited)
|
272
|
+
# @param maxHitsPerQuery the maximum number of hits this API key can retrieve in one call (0 means unlimited)
|
273
|
+
# @param indexes the optional list of targeted indexes
|
274
|
+
#
|
275
|
+
def update_user_key(key, obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0, indexes = nil)
|
276
|
+
if obj.instance_of? Array
|
277
|
+
params = {
|
278
|
+
:acl => obj
|
279
|
+
}
|
280
|
+
else
|
281
|
+
params = obj
|
282
|
+
end
|
283
|
+
if validity != 0
|
284
|
+
params["validity"] = validity.to_i
|
285
|
+
end
|
286
|
+
if maxQueriesPerIPPerHour != 0
|
287
|
+
params["maxQueriesPerIPPerHour"] = maxQueriesPerIPPerHour.to_i
|
288
|
+
end
|
289
|
+
if maxHitsPerQuery != 0
|
290
|
+
params["maxHitsPerQuery"] = maxHitsPerQuery.to_i
|
291
|
+
end
|
292
|
+
params[:indexes] = indexes if indexes
|
293
|
+
put(Protocol.key_uri(key), params.to_json)
|
294
|
+
end
|
295
|
+
|
296
|
+
|
297
|
+
# Delete an existing user key
|
298
|
+
def delete_user_key(key)
|
299
|
+
delete(Protocol.key_uri(key))
|
300
|
+
end
|
301
|
+
|
302
|
+
# Send a batch request targeting multiple indices
|
303
|
+
def batch(requests)
|
304
|
+
post(Protocol.batch_uri, {"requests" => requests}.to_json, :batch)
|
305
|
+
end
|
306
|
+
|
307
|
+
# Send a batch request targeting multiple indices and wait the end of the indexing
|
308
|
+
def batch!(requests)
|
309
|
+
res = batch(requests)
|
310
|
+
res['taskID'].each do |index, taskID|
|
311
|
+
init_index(index).wait_task(taskID)
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
41
315
|
# Perform an HTTP request for the given uri and method
|
42
316
|
# with common basic response handling. Will raise a
|
43
317
|
# AlgoliaProtocolError if the response has an error status code,
|
@@ -101,7 +375,7 @@ module Algolia
|
|
101
375
|
def thread_local_hosts(read, connect_timeout, send_timeout, receive_timeout)
|
102
376
|
thread_local_var = read ? :algolia_search_hosts : :algolia_hosts
|
103
377
|
Thread.current[thread_local_var] ||= {}
|
104
|
-
Thread.current[thread_local_var]["#{connect_timeout}-#{send_timeout}-#{receive_timeout}"] ||= (read ? search_hosts : hosts).map do |host|
|
378
|
+
Thread.current[thread_local_var]["#{self.hash}:#{connect_timeout}-#{send_timeout}-#{receive_timeout}"] ||= (read ? search_hosts : hosts).map do |host|
|
105
379
|
client = HTTPClient.new
|
106
380
|
client.ssl_config.ssl_version = @ssl_version if @ssl && @ssl_version
|
107
381
|
hinfo = {
|
@@ -117,7 +391,6 @@ module Algolia
|
|
117
391
|
end
|
118
392
|
end
|
119
393
|
|
120
|
-
private
|
121
394
|
def perform_request(session, url, method, data)
|
122
395
|
response = case method
|
123
396
|
when :GET
|
@@ -153,8 +426,6 @@ module Algolia
|
|
153
426
|
defaulted = { :application_id => application_id, :api_key => api_key }
|
154
427
|
defaulted.merge!(options)
|
155
428
|
|
156
|
-
raise ArgumentError.new("No APPLICATION_ID provided, please set :application_id") if defaulted[:application_id].nil?
|
157
|
-
|
158
429
|
@@client = Client.new(defaulted)
|
159
430
|
end
|
160
431
|
|
@@ -162,7 +433,7 @@ module Algolia
|
|
162
433
|
# Allow to set custom headers
|
163
434
|
#
|
164
435
|
def Algolia.set_extra_header(key, value)
|
165
|
-
Algolia.client.
|
436
|
+
Algolia.client.set_extra_header(key, value)
|
166
437
|
end
|
167
438
|
|
168
439
|
#
|
@@ -173,30 +444,21 @@ module Algolia
|
|
173
444
|
# @param rate_limit_api_key the API key on which you have a rate limit
|
174
445
|
#
|
175
446
|
def Algolia.enable_rate_limit_forward(admin_api_key, end_user_ip, rate_limit_api_key)
|
176
|
-
Algolia.client.
|
177
|
-
Algolia.client.headers[Protocol::HEADER_FORWARDED_IP] = end_user_ip
|
178
|
-
Algolia.client.headers[Protocol::HEADER_FORWARDED_API_KEY] = rate_limit_api_key
|
447
|
+
Algolia.client.enable_rate_limit_forward(admin_api_key, end_user_ip, rate_limit_api_key)
|
179
448
|
end
|
180
449
|
|
181
450
|
#
|
182
451
|
# Disable IP rate limit enabled with enableRateLimitForward() function
|
183
452
|
#
|
184
453
|
def Algolia.disable_rate_limit_forward
|
185
|
-
Algolia.client.
|
186
|
-
Algolia.client.headers.delete(Protocol::HEADER_FORWARDED_IP)
|
187
|
-
Algolia.client.headers.delete(Protocol::HEADER_FORWARDED_API_KEY)
|
454
|
+
Algolia.client.disable_rate_limit_forward
|
188
455
|
end
|
189
456
|
|
190
457
|
#
|
191
458
|
# Convenience method thats wraps enable_rate_limit_forward/disable_rate_limit_forward
|
192
459
|
#
|
193
460
|
def Algolia.with_rate_limits(end_user_ip, rate_limit_api_key, &block)
|
194
|
-
Algolia.
|
195
|
-
begin
|
196
|
-
yield
|
197
|
-
ensure
|
198
|
-
Algolia.disable_rate_limit_forward
|
199
|
-
end
|
461
|
+
Algolia.client.with_rate_limits(end_user_ip, rate_limit_api_key, &block)
|
200
462
|
end
|
201
463
|
|
202
464
|
#
|
@@ -223,14 +485,7 @@ module Algolia
|
|
223
485
|
# @param strategy define the strategy applied on the sequential searches (none by default)
|
224
486
|
#
|
225
487
|
def Algolia.multiple_queries(queries, index_name_key = :index_name, strategy = "none")
|
226
|
-
|
227
|
-
:requests => queries.map do |query|
|
228
|
-
indexName = query.delete(index_name_key) || query.delete(index_name_key.to_s)
|
229
|
-
encoded_params = Hash[query.map { |k,v| [k.to_s, v.is_a?(Array) ? v.to_json : v] }]
|
230
|
-
{ :indexName => indexName, :params => Protocol.to_query(encoded_params) }
|
231
|
-
end
|
232
|
-
}
|
233
|
-
Algolia.client.post(Protocol.multiple_queries_uri(strategy), requests.to_json, :search)
|
488
|
+
Algolia.client.multiple_queries(queries, index_name_key, strategy)
|
234
489
|
end
|
235
490
|
|
236
491
|
#
|
@@ -240,7 +495,7 @@ module Algolia
|
|
240
495
|
# {"name": "notes", "createdAt": "2013-01-18T15:33:13.556Z"}]}
|
241
496
|
#
|
242
497
|
def Algolia.list_indexes
|
243
|
-
|
498
|
+
Algolia.client.list_indexes
|
244
499
|
end
|
245
500
|
|
246
501
|
#
|
@@ -249,8 +504,7 @@ module Algolia
|
|
249
504
|
# @param dst_index the new index name that will contains a copy of srcIndexName (destination will be overriten if it already exist).
|
250
505
|
#
|
251
506
|
def Algolia.move_index(src_index, dst_index)
|
252
|
-
|
253
|
-
Algolia.client.post(Protocol.index_operation_uri(src_index), request.to_json)
|
507
|
+
Algolia.client.move_index(src_index, dst_index)
|
254
508
|
end
|
255
509
|
|
256
510
|
#
|
@@ -259,9 +513,7 @@ module Algolia
|
|
259
513
|
# @param dst_index the new index name that will contains a copy of srcIndexName (destination will be overriten if it already exist).
|
260
514
|
#
|
261
515
|
def Algolia.move_index!(src_index, dst_index)
|
262
|
-
|
263
|
-
Index.new(dst_index).wait_task(res['taskID'])
|
264
|
-
res
|
516
|
+
Algolia.client.move_index!(src_index, dst_index)
|
265
517
|
end
|
266
518
|
|
267
519
|
#
|
@@ -270,8 +522,7 @@ module Algolia
|
|
270
522
|
# @param dst_index the new index name that will contains a copy of srcIndexName (destination will be overriten if it already exist).
|
271
523
|
#
|
272
524
|
def Algolia.copy_index(src_index, dst_index)
|
273
|
-
|
274
|
-
Algolia.client.post(Protocol.index_operation_uri(src_index), request.to_json)
|
525
|
+
Algolia.client.copy_index(src_index, dst_index)
|
275
526
|
end
|
276
527
|
|
277
528
|
#
|
@@ -280,21 +531,19 @@ module Algolia
|
|
280
531
|
# @param dst_index the new index name that will contains a copy of srcIndexName (destination will be overriten if it already exist).
|
281
532
|
#
|
282
533
|
def Algolia.copy_index!(src_index, dst_index)
|
283
|
-
|
284
|
-
Index.new(dst_index).wait_task(res['taskID'])
|
285
|
-
res
|
534
|
+
Algolia.client.copy_index!(src_index, dst_index)
|
286
535
|
end
|
287
536
|
|
288
537
|
# Delete an index
|
289
538
|
#
|
290
|
-
def delete_index(name)
|
291
|
-
|
539
|
+
def Algolia.delete_index(name)
|
540
|
+
Algolia.client.delete_index(name)
|
292
541
|
end
|
293
542
|
|
294
543
|
# Delete an index and wait until the deletion has been processed.
|
295
544
|
#
|
296
|
-
def delete_index!(name)
|
297
|
-
|
545
|
+
def Algolia.delete_index!(name)
|
546
|
+
Algolia.client.delete_index!(name)
|
298
547
|
end
|
299
548
|
|
300
549
|
#
|
@@ -304,24 +553,17 @@ module Algolia
|
|
304
553
|
# @param length Specify the maximum number of entries to retrieve starting at offset. Maximum allowed value: 1000.
|
305
554
|
#
|
306
555
|
def Algolia.get_logs(offset = 0, length = 10, type = "all")
|
307
|
-
|
308
|
-
if (type)
|
309
|
-
type = "error"
|
310
|
-
else
|
311
|
-
type = "all"
|
312
|
-
end
|
313
|
-
end
|
314
|
-
Algolia.client.get(Protocol.logs(offset, length, type))
|
556
|
+
Algolia.client.get_logs(offset, length, type)
|
315
557
|
end
|
316
558
|
|
317
559
|
# List all existing user keys with their associated ACLs
|
318
560
|
def Algolia.list_user_keys
|
319
|
-
|
561
|
+
Algolia.client.list_user_keys
|
320
562
|
end
|
321
563
|
|
322
564
|
# Get ACL of a user key
|
323
565
|
def Algolia.get_user_key(key)
|
324
|
-
|
566
|
+
Algolia.client.get_user_key(key)
|
325
567
|
end
|
326
568
|
|
327
569
|
#
|
@@ -352,24 +594,7 @@ module Algolia
|
|
352
594
|
# @param indexes the optional list of targeted indexes
|
353
595
|
#
|
354
596
|
def Algolia.add_user_key(obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0, indexes = nil)
|
355
|
-
|
356
|
-
params = {
|
357
|
-
:acl => obj
|
358
|
-
}
|
359
|
-
else
|
360
|
-
params = obj
|
361
|
-
end
|
362
|
-
if validity != 0
|
363
|
-
params["validity"] = validity.to_i
|
364
|
-
end
|
365
|
-
if maxQueriesPerIPPerHour != 0
|
366
|
-
params["maxQueriesPerIPPerHour"] = maxQueriesPerIPPerHour.to_i
|
367
|
-
end
|
368
|
-
if maxHitsPerQuery != 0
|
369
|
-
params["maxHitsPerQuery"] = maxHitsPerQuery.to_i
|
370
|
-
end
|
371
|
-
params[:indexes] = indexes if indexes
|
372
|
-
Algolia.client.post(Protocol.keys_uri, params.to_json)
|
597
|
+
Algolia.client.add_user_key(obj, validity, maxQueriesPerIPPerHour, maxHitsPerQuery, indexes)
|
373
598
|
end
|
374
599
|
|
375
600
|
#
|
@@ -400,43 +625,22 @@ module Algolia
|
|
400
625
|
# @param indexes the optional list of targeted indexes
|
401
626
|
#
|
402
627
|
def Algolia.update_user_key(key, obj, validity = 0, maxQueriesPerIPPerHour = 0, maxHitsPerQuery = 0, indexes = nil)
|
403
|
-
|
404
|
-
params = {
|
405
|
-
:acl => obj
|
406
|
-
}
|
407
|
-
else
|
408
|
-
params = obj
|
409
|
-
end
|
410
|
-
if validity != 0
|
411
|
-
params["validity"] = validity.to_i
|
412
|
-
end
|
413
|
-
if maxQueriesPerIPPerHour != 0
|
414
|
-
params["maxQueriesPerIPPerHour"] = maxQueriesPerIPPerHour.to_i
|
415
|
-
end
|
416
|
-
if maxHitsPerQuery != 0
|
417
|
-
params["maxHitsPerQuery"] = maxHitsPerQuery.to_i
|
418
|
-
end
|
419
|
-
params[:indexes] = indexes if indexes
|
420
|
-
Algolia.client.put(Protocol.key_uri(key), params.to_json)
|
628
|
+
Algolia.client.update_user_key(key, obj, validity, maxQueriesPerIPPerHour, maxHitsPerQuery, indexes)
|
421
629
|
end
|
422
630
|
|
423
|
-
|
424
631
|
# Delete an existing user key
|
425
632
|
def Algolia.delete_user_key(key)
|
426
|
-
Algolia.client.
|
633
|
+
Algolia.client.delete_user_key(key)
|
427
634
|
end
|
428
635
|
|
429
636
|
# Send a batch request targeting multiple indices
|
430
637
|
def Algolia.batch(requests)
|
431
|
-
Algolia.client.
|
638
|
+
Algolia.client.batch(requests)
|
432
639
|
end
|
433
640
|
|
434
641
|
# Send a batch request targeting multiple indices and wait the end of the indexing
|
435
642
|
def Algolia.batch!(requests)
|
436
|
-
|
437
|
-
res['taskID'].each { |index, taskID|
|
438
|
-
Algolia::Index.new(index).wait_task(taskID)
|
439
|
-
}
|
643
|
+
Algolia.client.batch!(requests)
|
440
644
|
end
|
441
645
|
|
442
646
|
# Used mostly for testing. Lets you delete the api key global vars.
|
data/lib/algolia/index.rb
CHANGED
@@ -2,19 +2,20 @@ require 'algolia/client'
|
|
2
2
|
require 'algolia/error'
|
3
3
|
|
4
4
|
module Algolia
|
5
|
-
|
5
|
+
|
6
6
|
class Index
|
7
|
-
attr_accessor :name
|
8
|
-
|
9
|
-
def initialize(name)
|
7
|
+
attr_accessor :name, :client
|
8
|
+
|
9
|
+
def initialize(name, client = nil)
|
10
10
|
self.name = name
|
11
|
+
self.client = client || Algolia.client
|
11
12
|
end
|
12
|
-
|
13
|
+
|
13
14
|
# Delete an index
|
14
15
|
#
|
15
16
|
# return an hash of the form { "deletedAt" => "2013-01-18T15:33:13.556Z", "taskID" => "42" }
|
16
17
|
def delete
|
17
|
-
|
18
|
+
client.delete(Protocol.index_uri(name))
|
18
19
|
end
|
19
20
|
alias_method :delete_index, :delete
|
20
21
|
|
@@ -29,25 +30,25 @@ module Algolia
|
|
29
30
|
alias_method :delete_index!, :delete!
|
30
31
|
|
31
32
|
# Add an object in this index
|
32
|
-
#
|
33
|
-
# @param obj the object to add to the index.
|
33
|
+
#
|
34
|
+
# @param obj the object to add to the index.
|
34
35
|
# The object is represented by an associative array
|
35
|
-
# @param objectID (optional) an objectID you want to attribute to this object
|
36
|
+
# @param objectID (optional) an objectID you want to attribute to this object
|
36
37
|
# (if the attribute already exist the old object will be overridden)
|
37
38
|
def add_object(obj, objectID = nil)
|
38
39
|
check_object obj
|
39
40
|
if objectID.nil? || objectID.to_s.empty?
|
40
|
-
|
41
|
+
client.post(Protocol.index_uri(name), obj.to_json)
|
41
42
|
else
|
42
|
-
|
43
|
+
client.put(Protocol.object_uri(name, objectID), obj.to_json)
|
43
44
|
end
|
44
45
|
end
|
45
|
-
|
46
|
+
|
46
47
|
# Add an object in this index and wait end of indexing
|
47
|
-
#
|
48
|
+
#
|
48
49
|
# @param obj the object to add to the index.
|
49
50
|
# The object is represented by an associative array
|
50
|
-
# @param objectID (optional) an objectID you want to attribute to this object
|
51
|
+
# @param objectID (optional) an objectID you want to attribute to this object
|
51
52
|
# (if the attribute already exist the old object will be overridden)
|
52
53
|
def add_object!(obj, objectID = nil)
|
53
54
|
res = add_object(obj, objectID)
|
@@ -56,16 +57,16 @@ module Algolia
|
|
56
57
|
end
|
57
58
|
|
58
59
|
# Add several objects in this index
|
59
|
-
#
|
60
|
-
# @param objs the array of objects to add inside the index.
|
60
|
+
#
|
61
|
+
# @param objs the array of objects to add inside the index.
|
61
62
|
# Each object is represented by an associative array
|
62
63
|
def add_objects(objs)
|
63
64
|
batch build_batch('addObject', objs, false)
|
64
65
|
end
|
65
|
-
|
66
|
+
|
66
67
|
# Add several objects in this index and wait end of indexing
|
67
|
-
#
|
68
|
-
# @param objs the array of objects to add inside the index.
|
68
|
+
#
|
69
|
+
# @param objs the array of objects to add inside the index.
|
69
70
|
# Each object is represented by an associative array
|
70
71
|
def add_objects!(obj)
|
71
72
|
res = add_objects(obj)
|
@@ -82,65 +83,66 @@ module Algolia
|
|
82
83
|
# - hitsPerPage: (integer) Pagination parameter used to select the number of hits per page. Defaults to 20.
|
83
84
|
# - attributesToRetrieve: a string that contains the list of object attributes you want to retrieve (let you minimize the answer size).
|
84
85
|
# Attributes are separated with a comma (for example "name,address").
|
85
|
-
# You can also use a string array encoding (for example ["name","address"]).
|
86
|
+
# You can also use a string array encoding (for example ["name","address"]).
|
86
87
|
# By default, all attributes are retrieved. You can also use '*' to retrieve all values when an attributesToRetrieve setting is specified for your index.
|
87
|
-
# - attributesToHighlight: a string that contains the list of attributes you want to highlight according to the query.
|
88
|
-
# Attributes are separated by a comma. You can also use a string array encoding (for example ["name","address"]).
|
89
|
-
# If an attribute has no match for the query, the raw value is returned. By default all indexed text attributes are highlighted.
|
90
|
-
# You can use `*` if you want to highlight all textual attributes. Numerical attributes are not highlighted.
|
88
|
+
# - attributesToHighlight: a string that contains the list of attributes you want to highlight according to the query.
|
89
|
+
# Attributes are separated by a comma. You can also use a string array encoding (for example ["name","address"]).
|
90
|
+
# If an attribute has no match for the query, the raw value is returned. By default all indexed text attributes are highlighted.
|
91
|
+
# You can use `*` if you want to highlight all textual attributes. Numerical attributes are not highlighted.
|
91
92
|
# A matchLevel is returned for each highlighted attribute and can contain:
|
92
93
|
# - full: if all the query terms were found in the attribute,
|
93
94
|
# - partial: if only some of the query terms were found,
|
94
95
|
# - none: if none of the query terms were found.
|
95
|
-
# - attributesToSnippet: a string that contains the list of attributes to snippet alongside the number of words to return (syntax is `attributeName:nbWords`).
|
96
|
+
# - attributesToSnippet: a string that contains the list of attributes to snippet alongside the number of words to return (syntax is `attributeName:nbWords`).
|
96
97
|
# Attributes are separated by a comma (Example: attributesToSnippet=name:10,content:10).
|
97
98
|
# You can also use a string array encoding (Example: attributesToSnippet: ["name:10","content:10"]). By default no snippet is computed.
|
98
99
|
# - minWordSizefor1Typo: the minimum number of characters in a query word to accept one typo in this word. Defaults to 3.
|
99
100
|
# - minWordSizefor2Typos: the minimum number of characters in a query word to accept two typos in this word. Defaults to 7.
|
100
101
|
# - getRankingInfo: if set to 1, the result hits will contain ranking information in _rankingInfo attribute.
|
101
102
|
# - aroundLatLng: search for entries around a given latitude/longitude (specified as two floats separated by a comma).
|
102
|
-
# For example aroundLatLng=47.316669,5.016670).
|
103
|
+
# For example aroundLatLng=47.316669,5.016670).
|
103
104
|
# You can specify the maximum distance in meters with the aroundRadius parameter (in meters) and the precision for ranking with aroundPrecision
|
104
105
|
# (for example if you set aroundPrecision=100, two objects that are distant of less than 100m will be considered as identical for "geo" ranking parameter).
|
105
106
|
# At indexing, you should specify geoloc of an object with the _geoloc attribute (in the form {"_geoloc":{"lat":48.853409, "lng":2.348800}})
|
106
107
|
# - insideBoundingBox: search entries inside a given area defined by the two extreme points of a rectangle (defined by 4 floats: p1Lat,p1Lng,p2Lat,p2Lng).
|
107
108
|
# For example insideBoundingBox=47.3165,4.9665,47.3424,5.0201).
|
108
109
|
# At indexing, you should specify geoloc of an object with the _geoloc attribute (in the form {"_geoloc":{"lat":48.853409, "lng":2.348800}})
|
109
|
-
# - numericFilters: a string that contains the list of numeric filters you want to apply separated by a comma.
|
110
|
-
# The syntax of one filter is `attributeName` followed by `operand` followed by `value`. Supported operands are `<`, `<=`, `=`, `>` and `>=`.
|
111
|
-
# You can have multiple conditions on one attribute like for example numericFilters=price>100,price<1000.
|
110
|
+
# - numericFilters: a string that contains the list of numeric filters you want to apply separated by a comma.
|
111
|
+
# The syntax of one filter is `attributeName` followed by `operand` followed by `value`. Supported operands are `<`, `<=`, `=`, `>` and `>=`.
|
112
|
+
# You can have multiple conditions on one attribute like for example numericFilters=price>100,price<1000.
|
112
113
|
# You can also use a string array encoding (for example numericFilters: ["price>100","price<1000"]).
|
113
|
-
# - tagFilters: filter the query by a set of tags. You can AND tags by separating them by commas.
|
114
|
+
# - tagFilters: filter the query by a set of tags. You can AND tags by separating them by commas.
|
114
115
|
# To OR tags, you must add parentheses. For example, tags=tag1,(tag2,tag3) means tag1 AND (tag2 OR tag3).
|
115
116
|
# You can also use a string array encoding, for example tagFilters: ["tag1",["tag2","tag3"]] means tag1 AND (tag2 OR tag3).
|
116
|
-
# At indexing, tags should be added in the _tags** attribute of objects (for example {"_tags":["tag1","tag2"]}).
|
117
|
-
# - facetFilters: filter the query by a list of facets.
|
118
|
-
# Facets are separated by commas and each facet is encoded as `attributeName:value`.
|
119
|
-
# For example: `facetFilters=category:Book,author:John%20Doe`.
|
117
|
+
# At indexing, tags should be added in the _tags** attribute of objects (for example {"_tags":["tag1","tag2"]}).
|
118
|
+
# - facetFilters: filter the query by a list of facets.
|
119
|
+
# Facets are separated by commas and each facet is encoded as `attributeName:value`.
|
120
|
+
# For example: `facetFilters=category:Book,author:John%20Doe`.
|
120
121
|
# You can also use a string array encoding (for example `["category:Book","author:John%20Doe"]`).
|
121
|
-
# - facets: List of object attributes that you want to use for faceting.
|
122
|
-
# Attributes are separated with a comma (for example `"category,author"` ).
|
122
|
+
# - facets: List of object attributes that you want to use for faceting.
|
123
|
+
# Attributes are separated with a comma (for example `"category,author"` ).
|
123
124
|
# You can also use a JSON string array encoding (for example ["category","author"]).
|
124
|
-
# Only attributes that have been added in **attributesForFaceting** index setting can be used in this parameter.
|
125
|
+
# Only attributes that have been added in **attributesForFaceting** index setting can be used in this parameter.
|
125
126
|
# You can also use `*` to perform faceting on all attributes specified in **attributesForFaceting**.
|
126
127
|
# - queryType: select how the query words are interpreted, it can be one of the following value:
|
127
128
|
# - prefixAll: all query words are interpreted as prefixes,
|
128
129
|
# - prefixLast: only the last word is interpreted as a prefix (default behavior),
|
129
130
|
# - prefixNone: no query word is interpreted as a prefix. This option is not recommended.
|
130
|
-
# - optionalWords: a string that contains the list of words that should be considered as optional when found in the query.
|
131
|
+
# - optionalWords: a string that contains the list of words that should be considered as optional when found in the query.
|
131
132
|
# The list of words is comma separated.
|
132
|
-
# - distinct: If set to 1, enable the distinct feature (disabled by default) if the attributeForDistinct index setting is set.
|
133
|
-
# This feature is similar to the SQL "distinct" keyword: when enabled in a query with the distinct=1 parameter,
|
134
|
-
# all hits containing a duplicate value for the attributeForDistinct attribute are removed from results.
|
135
|
-
# For example, if the chosen attribute is show_name and several hits have the same value for show_name, then only the best
|
133
|
+
# - distinct: If set to 1, enable the distinct feature (disabled by default) if the attributeForDistinct index setting is set.
|
134
|
+
# This feature is similar to the SQL "distinct" keyword: when enabled in a query with the distinct=1 parameter,
|
135
|
+
# all hits containing a duplicate value for the attributeForDistinct attribute are removed from results.
|
136
|
+
# For example, if the chosen attribute is show_name and several hits have the same value for show_name, then only the best
|
136
137
|
# one is kept and others are removed.
|
137
138
|
def search(query, params = {})
|
138
139
|
encoded_params = Hash[params.map { |k,v| [k.to_s, v.is_a?(Array) ? v.to_json : v] }]
|
139
|
-
|
140
|
+
client.get(Protocol.search_uri(name, query, encoded_params), :search)
|
140
141
|
end
|
141
142
|
|
142
143
|
class IndexBrowser
|
143
|
-
def initialize(name, params)
|
144
|
+
def initialize(client, name, params)
|
145
|
+
@client = client
|
144
146
|
@name = name
|
145
147
|
@params = params
|
146
148
|
@cursor = params[:cursor] || params['cursor'] || nil
|
@@ -148,7 +150,7 @@ module Algolia
|
|
148
150
|
|
149
151
|
def browse(&block)
|
150
152
|
loop do
|
151
|
-
answer =
|
153
|
+
answer = @client.get(Protocol.browse_uri(@name, @params.merge({ :cursor => @cursor })), :read)
|
152
154
|
answer['hits'].each do |hit|
|
153
155
|
if block.arity == 2
|
154
156
|
yield hit, @cursor
|
@@ -185,11 +187,11 @@ module Algolia
|
|
185
187
|
else
|
186
188
|
params[:hitsPerPage] = hitsPerPage unless hitsPerPage.nil?
|
187
189
|
end
|
188
|
-
IndexBrowser.new(name, params).browse(&block)
|
190
|
+
IndexBrowser.new(client, name, params).browse(&block)
|
189
191
|
else
|
190
192
|
page ||= 0
|
191
193
|
hitsPerPage ||= 1000
|
192
|
-
|
194
|
+
client.get(Protocol.browse_uri(name, {:page => page, :hitsPerPage => hitsPerPage}), :read)
|
193
195
|
end
|
194
196
|
end
|
195
197
|
|
@@ -197,20 +199,20 @@ module Algolia
|
|
197
199
|
# Browse a single page from a specific cursor
|
198
200
|
#
|
199
201
|
def browse_from(cursor, hitsPerPage = 1000)
|
200
|
-
|
202
|
+
client.get(Protocol.browse_uri(name, { :cursor => cursor, :hitsPerPage => hitsPerPage }), :read)
|
201
203
|
end
|
202
204
|
|
203
205
|
#
|
204
206
|
# Get an object from this index
|
205
|
-
#
|
207
|
+
#
|
206
208
|
# @param objectID the unique identifier of the object to retrieve
|
207
209
|
# @param attributesToRetrieve (optional) if set, contains the list of attributes to retrieve as a string separated by ","
|
208
210
|
#
|
209
211
|
def get_object(objectID, attributesToRetrieve = nil)
|
210
212
|
if attributesToRetrieve.nil?
|
211
|
-
|
213
|
+
client.get(Protocol.object_uri(name, objectID, nil), :read)
|
212
214
|
else
|
213
|
-
|
215
|
+
client.get(Protocol.object_uri(name, objectID, {:attributes => attributesToRetrieve}), :read)
|
214
216
|
end
|
215
217
|
end
|
216
218
|
|
@@ -220,18 +222,18 @@ module Algolia
|
|
220
222
|
# @param objectIDs the array of unique identifier of the objects to retrieve
|
221
223
|
#
|
222
224
|
def get_objects(objectIDs)
|
223
|
-
|
225
|
+
client.post(Protocol.objects_uri, { :requests => objectIDs.map { |objectID| { :indexName => name, :objectID => objectID } } }.to_json, :read)['results']
|
224
226
|
end
|
225
227
|
|
226
|
-
# Wait the publication of a task on the server.
|
228
|
+
# Wait the publication of a task on the server.
|
227
229
|
# All server task are asynchronous and you can check with this method that the task is published.
|
228
230
|
#
|
229
231
|
# @param taskID the id of the task returned by server
|
230
232
|
# @param timeBeforeRetry the time in milliseconds before retry (default = 100ms)
|
231
|
-
#
|
233
|
+
#
|
232
234
|
def wait_task(taskID, timeBeforeRetry = 100)
|
233
235
|
loop do
|
234
|
-
status =
|
236
|
+
status = client.get(Protocol.task_uri(name, taskID), :read)["status"]
|
235
237
|
if status == "published"
|
236
238
|
return
|
237
239
|
end
|
@@ -240,19 +242,19 @@ module Algolia
|
|
240
242
|
end
|
241
243
|
|
242
244
|
# Override the content of an object
|
243
|
-
#
|
245
|
+
#
|
244
246
|
# @param obj the object to save
|
245
247
|
# @param objectID the associated objectID, if nil 'obj' must contain an 'objectID' key
|
246
248
|
#
|
247
249
|
def save_object(obj, objectID = nil)
|
248
|
-
|
250
|
+
client.put(Protocol.object_uri(name, get_objectID(obj, objectID)), obj.to_json)
|
249
251
|
end
|
250
252
|
|
251
253
|
# Override the content of object and wait end of indexing
|
252
|
-
#
|
254
|
+
#
|
253
255
|
# @param obj the object to save
|
254
256
|
# @param objectID the associated objectID, if nil 'obj' must contain an 'objectID' key
|
255
|
-
#
|
257
|
+
#
|
256
258
|
def save_object!(obj, objectID = nil)
|
257
259
|
res = save_object(obj, objectID)
|
258
260
|
wait_task(res["taskID"])
|
@@ -260,7 +262,7 @@ module Algolia
|
|
260
262
|
end
|
261
263
|
|
262
264
|
# Override the content of several objects
|
263
|
-
#
|
265
|
+
#
|
264
266
|
# @param objs the array of objects to save, each object must contain an 'objectID' key
|
265
267
|
#
|
266
268
|
def save_objects(objs)
|
@@ -268,9 +270,9 @@ module Algolia
|
|
268
270
|
end
|
269
271
|
|
270
272
|
# Override the content of several objects and wait end of indexing
|
271
|
-
#
|
273
|
+
#
|
272
274
|
# @param objs the array of objects to save, each object must contain an objectID attribute
|
273
|
-
#
|
275
|
+
#
|
274
276
|
def save_objects!(objs)
|
275
277
|
res = save_objects(objs)
|
276
278
|
wait_task(res["taskID"])
|
@@ -279,18 +281,18 @@ module Algolia
|
|
279
281
|
|
280
282
|
#
|
281
283
|
# Update partially an object (only update attributes passed in argument)
|
282
|
-
#
|
284
|
+
#
|
283
285
|
# @param obj the object attributes to override
|
284
286
|
# @param objectID the associated objectID, if nil 'obj' must contain an 'objectID' key
|
285
287
|
# @param create_if_not_exits a boolean, if true creates the object if this one doesn't exist
|
286
288
|
#
|
287
289
|
def partial_update_object(obj, objectID = nil, create_if_not_exits = true)
|
288
|
-
|
290
|
+
client.post(Protocol.partial_object_uri(name, get_objectID(obj, objectID), create_if_not_exits), obj.to_json)
|
289
291
|
end
|
290
|
-
|
292
|
+
|
291
293
|
#
|
292
294
|
# Partially Override the content of several objects
|
293
|
-
#
|
295
|
+
#
|
294
296
|
# @param objs an array of objects to update (each object must contains a objectID attribute)
|
295
297
|
# @param create_if_not_exits a boolean, if true create the objects if they don't exist
|
296
298
|
#
|
@@ -304,7 +306,7 @@ module Algolia
|
|
304
306
|
|
305
307
|
#
|
306
308
|
# Partially Override the content of several objects and wait end of indexing
|
307
|
-
#
|
309
|
+
#
|
308
310
|
# @param objs an array of objects to update (each object must contains a objectID attribute)
|
309
311
|
# @param create_if_not_exits a boolean, if true create the objects if they don't exist
|
310
312
|
#
|
@@ -316,7 +318,7 @@ module Algolia
|
|
316
318
|
|
317
319
|
#
|
318
320
|
# Update partially an object (only update attributes passed in argument) and wait indexing
|
319
|
-
#
|
321
|
+
#
|
320
322
|
# @param obj the attributes to override
|
321
323
|
# @param objectID the associated objectID, if nil 'obj' must contain an 'objectID' key
|
322
324
|
# @param create_if_not_exits a boolean, if true creates the object if this one doesn't exist
|
@@ -326,19 +328,19 @@ module Algolia
|
|
326
328
|
wait_task(res["taskID"])
|
327
329
|
return res
|
328
330
|
end
|
329
|
-
|
331
|
+
|
332
|
+
#
|
333
|
+
# Delete an object from the index
|
330
334
|
#
|
331
|
-
# Delete an object from the index
|
332
|
-
#
|
333
335
|
# @param objectID the unique identifier of object to delete
|
334
336
|
#
|
335
337
|
def delete_object(objectID)
|
336
|
-
|
338
|
+
client.delete(Protocol.object_uri(name, objectID))
|
337
339
|
end
|
338
|
-
|
340
|
+
|
339
341
|
#
|
340
342
|
# Delete an object from the index and wait end of indexing
|
341
|
-
#
|
343
|
+
#
|
342
344
|
# @param objectID the unique identifier of object to delete
|
343
345
|
#
|
344
346
|
def delete_object!(objectID)
|
@@ -349,7 +351,7 @@ module Algolia
|
|
349
351
|
|
350
352
|
#
|
351
353
|
# Delete several objects
|
352
|
-
#
|
354
|
+
#
|
353
355
|
# @param objs an array of objectIDs
|
354
356
|
#
|
355
357
|
def delete_objects(objs)
|
@@ -359,7 +361,7 @@ module Algolia
|
|
359
361
|
|
360
362
|
#
|
361
363
|
# Delete several objects and wait end of indexing
|
362
|
-
#
|
364
|
+
#
|
363
365
|
# @param objs an array of objectIDs
|
364
366
|
#
|
365
367
|
def delete_objects!(objs)
|
@@ -392,13 +394,13 @@ module Algolia
|
|
392
394
|
|
393
395
|
#
|
394
396
|
# Delete the index content
|
395
|
-
#
|
397
|
+
#
|
396
398
|
#
|
397
399
|
def clear
|
398
|
-
|
400
|
+
client.post(Protocol.clear_uri(name))
|
399
401
|
end
|
400
402
|
alias_method :clear_index, :clear
|
401
|
-
|
403
|
+
|
402
404
|
#
|
403
405
|
# Delete the index content and wait end of indexing
|
404
406
|
#
|
@@ -408,50 +410,50 @@ module Algolia
|
|
408
410
|
return res
|
409
411
|
end
|
410
412
|
alias_method :clear_index!, :clear!
|
411
|
-
|
413
|
+
|
412
414
|
#
|
413
415
|
# Set settings for this index
|
414
|
-
#
|
416
|
+
#
|
415
417
|
# @param settigns the settings object that can contains :
|
416
418
|
# - minWordSizefor1Typo: (integer) the minimum number of characters to accept one typo (default = 3).
|
417
419
|
# - minWordSizefor2Typos: (integer) the minimum number of characters to accept two typos (default = 7).
|
418
420
|
# - hitsPerPage: (integer) the number of hits per page (default = 10).
|
419
|
-
# - attributesToRetrieve: (array of strings) default list of attributes to retrieve in objects.
|
421
|
+
# - attributesToRetrieve: (array of strings) default list of attributes to retrieve in objects.
|
420
422
|
# If set to null, all attributes are retrieved.
|
421
|
-
# - attributesToHighlight: (array of strings) default list of attributes to highlight.
|
423
|
+
# - attributesToHighlight: (array of strings) default list of attributes to highlight.
|
422
424
|
# If set to null, all indexed attributes are highlighted.
|
423
425
|
# - attributesToSnippet**: (array of strings) default list of attributes to snippet alongside the number of words to return (syntax is attributeName:nbWords).
|
424
426
|
# By default no snippet is computed. If set to null, no snippet is computed.
|
425
427
|
# - attributesToIndex: (array of strings) the list of fields you want to index.
|
426
428
|
# If set to null, all textual and numerical attributes of your objects are indexed, but you should update it to get optimal results.
|
427
429
|
# This parameter has two important uses:
|
428
|
-
# - Limit the attributes to index: For example if you store a binary image in base64, you want to store it and be able to
|
430
|
+
# - Limit the attributes to index: For example if you store a binary image in base64, you want to store it and be able to
|
429
431
|
# retrieve it but you don't want to search in the base64 string.
|
430
|
-
# - Control part of the ranking*: (see the ranking parameter for full explanation) Matches in attributes at the beginning of
|
431
|
-
# the list will be considered more important than matches in attributes further down the list.
|
432
|
-
# In one attribute, matching text at the beginning of the attribute will be considered more important than text after, you can disable
|
432
|
+
# - Control part of the ranking*: (see the ranking parameter for full explanation) Matches in attributes at the beginning of
|
433
|
+
# the list will be considered more important than matches in attributes further down the list.
|
434
|
+
# In one attribute, matching text at the beginning of the attribute will be considered more important than text after, you can disable
|
433
435
|
# this behavior if you add your attribute inside `unordered(AttributeName)`, for example attributesToIndex: ["title", "unordered(text)"].
|
434
|
-
# - attributesForFaceting: (array of strings) The list of fields you want to use for faceting.
|
436
|
+
# - attributesForFaceting: (array of strings) The list of fields you want to use for faceting.
|
435
437
|
# All strings in the attribute selected for faceting are extracted and added as a facet. If set to null, no attribute is used for faceting.
|
436
|
-
# - attributeForDistinct: (string) The attribute name used for the Distinct feature. This feature is similar to the SQL "distinct" keyword: when enabled
|
437
|
-
# in query with the distinct=1 parameter, all hits containing a duplicate value for this attribute are removed from results.
|
438
|
+
# - attributeForDistinct: (string) The attribute name used for the Distinct feature. This feature is similar to the SQL "distinct" keyword: when enabled
|
439
|
+
# in query with the distinct=1 parameter, all hits containing a duplicate value for this attribute are removed from results.
|
438
440
|
# For example, if the chosen attribute is show_name and several hits have the same value for show_name, then only the best one is kept and others are removed.
|
439
441
|
# - ranking: (array of strings) controls the way results are sorted.
|
440
|
-
# We have six available criteria:
|
442
|
+
# We have six available criteria:
|
441
443
|
# - typo: sort according to number of typos,
|
442
444
|
# - geo: sort according to decreassing distance when performing a geo-location based search,
|
443
445
|
# - proximity: sort according to the proximity of query words in hits,
|
444
446
|
# - attribute: sort according to the order of attributes defined by attributesToIndex,
|
445
|
-
# - exact:
|
446
|
-
# - if the user query contains one word: sort objects having an attribute that is exactly the query word before others.
|
447
|
-
# For example if you search for the "V" TV show, you want to find it with the "V" query and avoid to have all popular TV
|
447
|
+
# - exact:
|
448
|
+
# - if the user query contains one word: sort objects having an attribute that is exactly the query word before others.
|
449
|
+
# For example if you search for the "V" TV show, you want to find it with the "V" query and avoid to have all popular TV
|
448
450
|
# show starting by the v letter before it.
|
449
451
|
# - if the user query contains multiple words: sort according to the number of words that matched exactly (and not as a prefix).
|
450
452
|
# - custom: sort according to a user defined formula set in **customRanking** attribute.
|
451
453
|
# The standard order is ["typo", "geo", "proximity", "attribute", "exact", "custom"]
|
452
454
|
# - customRanking: (array of strings) lets you specify part of the ranking.
|
453
455
|
# The syntax of this condition is an array of strings containing attributes prefixed by asc (ascending order) or desc (descending order) operator.
|
454
|
-
# For example `"customRanking" => ["desc(population)", "asc(name)"]`
|
456
|
+
# For example `"customRanking" => ["desc(population)", "asc(name)"]`
|
455
457
|
# - queryType: Select how the query words are interpreted, it can be one of the following value:
|
456
458
|
# - prefixAll: all query words are interpreted as prefixes,
|
457
459
|
# - prefixLast: only the last word is interpreted as a prefix (default behavior),
|
@@ -461,24 +463,24 @@ module Algolia
|
|
461
463
|
# - optionalWords: (array of strings) Specify a list of words that should be considered as optional when found in the query.
|
462
464
|
#
|
463
465
|
def set_settings(new_settings)
|
464
|
-
|
466
|
+
client.put(Protocol.settings_uri(name), new_settings.to_json)
|
465
467
|
end
|
466
|
-
|
468
|
+
|
467
469
|
# Get settings of this index
|
468
470
|
def get_settings
|
469
|
-
|
470
|
-
end
|
471
|
+
client.get(Protocol.settings_uri(name), :read)
|
472
|
+
end
|
471
473
|
|
472
474
|
# List all existing user keys with their associated ACLs
|
473
475
|
def list_user_keys
|
474
|
-
|
476
|
+
client.get(Protocol.index_keys_uri(name), :read)
|
475
477
|
end
|
476
|
-
|
478
|
+
|
477
479
|
# Get ACL of a user key
|
478
480
|
def get_user_key(key)
|
479
|
-
|
481
|
+
client.get(Protocol.index_key_uri(name, key), :read)
|
480
482
|
end
|
481
|
-
|
483
|
+
|
482
484
|
#
|
483
485
|
# Create a new user key
|
484
486
|
#
|
@@ -521,7 +523,7 @@ module Algolia
|
|
521
523
|
if maxHitsPerQuery != 0
|
522
524
|
params["maxHitsPerQuery"] = maxHitsPerQuery.to_i
|
523
525
|
end
|
524
|
-
|
526
|
+
client.post(Protocol.index_keys_uri(name), params.to_json)
|
525
527
|
end
|
526
528
|
|
527
529
|
#
|
@@ -566,18 +568,18 @@ module Algolia
|
|
566
568
|
if maxHitsPerQuery != 0
|
567
569
|
params["maxHitsPerQuery"] = maxHitsPerQuery.to_i
|
568
570
|
end
|
569
|
-
|
571
|
+
client.put(Protocol.index_key_uri(name, key), params.to_json)
|
570
572
|
end
|
571
573
|
|
572
|
-
|
574
|
+
|
573
575
|
# Delete an existing user key
|
574
576
|
def delete_user_key(key)
|
575
|
-
|
577
|
+
client.delete(Protocol.index_key_uri(name, key))
|
576
578
|
end
|
577
579
|
|
578
580
|
# Send a batch request
|
579
581
|
def batch(request)
|
580
|
-
|
582
|
+
client.post(Protocol.batch_uri(name), request.to_json, :batch)
|
581
583
|
end
|
582
584
|
|
583
585
|
# Send a batch request and wait the end of the indexing
|
@@ -648,7 +650,7 @@ module Algolia
|
|
648
650
|
:analytics => false
|
649
651
|
})
|
650
652
|
end
|
651
|
-
answers =
|
653
|
+
answers = client.multiple_queries(queries)
|
652
654
|
|
653
655
|
# aggregate answers
|
654
656
|
## first answer stores the hits + regular facets
|
data/lib/algolia/version.rb
CHANGED
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: algoliasearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Algolia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.5.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.5.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: travis
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rdoc
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description: A simple Ruby client for the algolia.com REST API
|
@@ -89,8 +89,8 @@ extra_rdoc_files:
|
|
89
89
|
- LICENSE.txt
|
90
90
|
- README.md
|
91
91
|
files:
|
92
|
-
- .rspec
|
93
|
-
- .travis.yml
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
94
|
- ChangeLog
|
95
95
|
- Gemfile
|
96
96
|
- Gemfile.lock
|
@@ -121,17 +121,17 @@ require_paths:
|
|
121
121
|
- lib
|
122
122
|
required_ruby_version: !ruby/object:Gem::Requirement
|
123
123
|
requirements:
|
124
|
-
- -
|
124
|
+
- - ">="
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '0'
|
127
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
133
|
rubyforge_project:
|
134
|
-
rubygems_version: 2.
|
134
|
+
rubygems_version: 2.2.2
|
135
135
|
signing_key:
|
136
136
|
specification_version: 4
|
137
137
|
summary: A simple Ruby client for the algolia.com REST API
|