algoliasearch-rails 1.12.2 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff6182784c89b9f5b8b139e15939bcc3aab827d5
4
- data.tar.gz: f5d523d2c98723a91ade26e2a4945bdb41f81af7
3
+ metadata.gz: ba7c93249fd23c8c5d422db7273d3250c76d6e13
4
+ data.tar.gz: 37d32353f83ae66f722b13895c75d22783241b3b
5
5
  SHA512:
6
- metadata.gz: 82f1d265c3d176f03b0ec53902dcc7a4ad22eb6f5b3b9811c17d07060638820ef3dccdddd2051df13f44df78bbcbac845fafbaaab9beb0bc1b4f771fc23442ed
7
- data.tar.gz: 9217e898e4933f731bec9dc54841791bd45be21ef3d0a4fa7b65d46301a3392395237a930be7ec049f23c321f15905f8181dd34921d5876404be796249989048
6
+ metadata.gz: 8ee2a2189fba6910b8d0ddfbc422c6aa81fe5e1366efe8e130cbb1986fac59223d30d3894199c70e77ef79b54aa325dd021c5d7b51d727350265f7ef6b311fdc
7
+ data.tar.gz: 5a72387eca06e26c0623e6cefa27f616d85966d0605dc68746932dfa1bf0014b72c9e0e9b86f05c80b41171e8ca74be506be4897c2082b466fc7df5c68ec1dfe
data/.travis.yml CHANGED
@@ -10,6 +10,7 @@ rvm:
10
10
  - 2.2
11
11
  - jruby
12
12
  - rbx-2
13
+ install: bundle update
13
14
  env:
14
15
  global:
15
16
  - secure: kD+PX8ZNg+AAzyr6WYs1vp9teAkzMfEoYkIMI0hrRN0ml9ccJVsJR1pIGpaIwyCa5PmFtCZ1Xi2vFb4XzTTeaZoHHS/ll9LwuQH6mwvdgj3n6TmNRdq3b/oGRHBX4Z0HMobqaftuzY/V8iTpVk92jwIY8NPj00k055b2jrKqhdw=
data/ChangeLog CHANGED
@@ -1,5 +1,10 @@
1
1
  CHANGELOG
2
2
 
3
+ 2015-06-21 1.13.0
4
+
5
+ * Ability to use a background queue to handle all automatic indexing operations
6
+ * Fix a bug avoiding the gem to remove records when using the Sequel ORM
7
+
3
8
  2015-05-28 1.12.2
4
9
 
5
10
  * Add a new `raise_on_failure` option, controlling whereas exceptions are raised while trying to reach Algolia's API.
data/Gemfile CHANGED
@@ -6,7 +6,14 @@ gem 'rubysl', '~> 2.0', :platform => :rbx
6
6
 
7
7
  group :test do
8
8
  gem 'rspec', '>= 2.5.0', '< 3.0'
9
- gem 'rails', '>= 3.2.0', '< 4.0'
9
+ if defined?(RUBY_VERSION) && RUBY_VERSION == "1.8.7"
10
+ gem 'rails', '>= 3.2.0', '< 4.0'
11
+ gem 'i18n', '< 0.7'
12
+ gem 'highline', '< 1.7'
13
+ gem 'addressable', '< 2.4.0'
14
+ else
15
+ gem 'rails', '>= 3.2.0'
16
+ end
10
17
  gem 'sqlite3', :platform => [:rbx, :ruby]
11
18
  gem 'jdbc-sqlite3', :platform => :jruby
12
19
  gem 'activerecord-jdbc-adapter', :platform => :jruby
data/Gemfile.lock CHANGED
@@ -2,95 +2,108 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  ZenTest (4.11.0)
5
- actionmailer (3.2.19)
6
- actionpack (= 3.2.19)
7
- mail (~> 2.5.4)
8
- actionpack (3.2.19)
9
- activemodel (= 3.2.19)
10
- activesupport (= 3.2.19)
11
- builder (~> 3.0.0)
5
+ actionmailer (4.2.1)
6
+ actionpack (= 4.2.1)
7
+ actionview (= 4.2.1)
8
+ activejob (= 4.2.1)
9
+ mail (~> 2.5, >= 2.5.4)
10
+ rails-dom-testing (~> 1.0, >= 1.0.5)
11
+ actionpack (4.2.1)
12
+ actionview (= 4.2.1)
13
+ activesupport (= 4.2.1)
14
+ rack (~> 1.6)
15
+ rack-test (~> 0.6.2)
16
+ rails-dom-testing (~> 1.0, >= 1.0.5)
17
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
18
+ actionview (4.2.1)
19
+ activesupport (= 4.2.1)
20
+ builder (~> 3.1)
12
21
  erubis (~> 2.7.0)
13
- journey (~> 1.0.4)
14
- rack (~> 1.4.5)
15
- rack-cache (~> 1.2)
16
- rack-test (~> 0.6.1)
17
- sprockets (~> 2.2.1)
18
- activemodel (3.2.19)
19
- activesupport (= 3.2.19)
20
- builder (~> 3.0.0)
21
- activerecord (3.2.19)
22
- activemodel (= 3.2.19)
23
- activesupport (= 3.2.19)
24
- arel (~> 3.0.2)
25
- tzinfo (~> 0.3.29)
26
- activerecord-jdbc-adapter (1.3.10)
22
+ rails-dom-testing (~> 1.0, >= 1.0.5)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
24
+ activejob (4.2.1)
25
+ activesupport (= 4.2.1)
26
+ globalid (>= 0.3.0)
27
+ activemodel (4.2.1)
28
+ activesupport (= 4.2.1)
29
+ builder (~> 3.1)
30
+ activerecord (4.2.1)
31
+ activemodel (= 4.2.1)
32
+ activesupport (= 4.2.1)
33
+ arel (~> 6.0)
34
+ activerecord-jdbc-adapter (1.3.16)
27
35
  activerecord (>= 2.2)
28
- activerecord-jdbcsqlite3-adapter (1.3.10)
29
- activerecord-jdbc-adapter (~> 1.3.10)
30
- jdbc-sqlite3 (~> 3.7.2)
31
- activeresource (3.2.19)
32
- activemodel (= 3.2.19)
33
- activesupport (= 3.2.19)
34
- activesupport (3.2.19)
35
- i18n (~> 0.6, >= 0.6.4)
36
- multi_json (~> 1.0)
37
- addressable (2.3.6)
36
+ activerecord-jdbcsqlite3-adapter (1.3.16)
37
+ activerecord-jdbc-adapter (~> 1.3.16)
38
+ jdbc-sqlite3 (>= 3.7.2, < 3.9)
39
+ activesupport (4.2.1)
40
+ i18n (~> 0.7)
41
+ json (~> 1.7, >= 1.7.7)
42
+ minitest (~> 5.1)
43
+ thread_safe (~> 0.3, >= 0.3.4)
44
+ tzinfo (~> 1.1)
45
+ addressable (2.3.8)
38
46
  algoliasearch (1.2.14)
39
47
  httpclient (~> 2.4)
40
48
  json (>= 1.5.1)
41
- arel (3.0.3)
49
+ arel (6.0.0)
42
50
  autotest (4.4.6)
43
51
  ZenTest (>= 4.4.1)
44
52
  autotest-fsevent (0.2.10)
45
53
  sys-uname
46
54
  autotest-growl (0.2.16)
47
- backports (3.6.3)
48
- builder (3.0.4)
55
+ backports (3.6.4)
56
+ builder (3.2.2)
49
57
  coderay (1.1.0)
50
58
  diff-lcs (1.2.5)
51
59
  erubis (2.7.0)
52
- ethon (0.7.1)
60
+ ethon (0.7.3)
53
61
  ffi (>= 1.3.0)
54
- faraday (0.9.0)
62
+ faraday (0.9.1)
55
63
  multipart-post (>= 1.2, < 3)
56
64
  faraday_middleware (0.9.1)
57
65
  faraday (>= 0.7.4, < 0.10)
58
- ffi (1.9.6)
59
- ffi (1.9.6-java)
66
+ ffi (1.9.8)
67
+ ffi (1.9.8-java)
60
68
  ffi2-generators (0.1.1)
61
- gh (0.13.2)
69
+ gh (0.14.0)
62
70
  addressable
63
71
  backports
64
72
  faraday (~> 0.8)
65
73
  multi_json (~> 1.0)
66
74
  net-http-persistent (>= 2.7)
67
75
  net-http-pipeline
68
- highline (1.6.21)
69
- hike (1.2.3)
70
- httpclient (2.5.3.2)
71
- i18n (0.6.11)
72
- jdbc-sqlite3 (3.7.2.1)
73
- journey (1.0.4)
74
- json (1.8.1)
75
- json (1.8.1-java)
76
- kaminari (0.16.1)
76
+ globalid (0.3.5)
77
+ activesupport (>= 4.1.0)
78
+ highline (1.7.2)
79
+ httpclient (2.6.0.1)
80
+ i18n (0.7.0)
81
+ jdbc-sqlite3 (3.8.10.1)
82
+ json (1.8.3)
83
+ json (1.8.3-java)
84
+ kaminari (0.16.3)
77
85
  actionpack (>= 3.0.0)
78
86
  activesupport (>= 3.0.0)
79
- launchy (2.4.2)
87
+ launchy (2.4.3)
80
88
  addressable (~> 2.3)
81
- launchy (2.4.2-java)
89
+ launchy (2.4.3-java)
82
90
  addressable (~> 2.3)
83
91
  spoon (~> 0.0.1)
84
- mail (2.5.4)
85
- mime-types (~> 1.16)
86
- treetop (~> 1.4.8)
92
+ loofah (2.0.2)
93
+ nokogiri (>= 1.5.9)
94
+ mail (2.6.3)
95
+ mime-types (>= 1.16, < 3)
87
96
  method_source (0.8.2)
88
- mime-types (1.25.1)
89
- multi_json (1.10.1)
97
+ mime-types (2.6.1)
98
+ mini_portile (0.6.2)
99
+ minitest (5.7.0)
100
+ multi_json (1.11.0)
90
101
  multipart-post (2.0.0)
91
102
  net-http-persistent (2.9.4)
92
103
  net-http-pipeline (1.0.1)
93
- polyglot (0.3.5)
104
+ nokogiri (1.6.6.2)
105
+ mini_portile (~> 0.6.0)
106
+ nokogiri (1.6.6.2-java)
94
107
  pry (0.9.12.6)
95
108
  coderay (~> 1.0)
96
109
  method_source (~> 0.8)
@@ -100,33 +113,38 @@ GEM
100
113
  method_source (~> 0.8)
101
114
  slop (~> 3.4)
102
115
  spoon (~> 0.0)
103
- pusher-client (0.6.0)
116
+ pusher-client (0.6.2)
104
117
  json
105
118
  websocket (~> 1.0)
106
- rack (1.4.5)
107
- rack-cache (1.2)
108
- rack (>= 0.4)
109
- rack-ssl (1.3.4)
110
- rack
111
- rack-test (0.6.2)
119
+ rack (1.6.1)
120
+ rack-test (0.6.3)
112
121
  rack (>= 1.0)
113
- rails (3.2.19)
114
- actionmailer (= 3.2.19)
115
- actionpack (= 3.2.19)
116
- activerecord (= 3.2.19)
117
- activeresource (= 3.2.19)
118
- activesupport (= 3.2.19)
119
- bundler (~> 1.0)
120
- railties (= 3.2.19)
121
- railties (3.2.19)
122
- actionpack (= 3.2.19)
123
- activesupport (= 3.2.19)
124
- rack-ssl (~> 1.3.2)
122
+ rails (4.2.1)
123
+ actionmailer (= 4.2.1)
124
+ actionpack (= 4.2.1)
125
+ actionview (= 4.2.1)
126
+ activejob (= 4.2.1)
127
+ activemodel (= 4.2.1)
128
+ activerecord (= 4.2.1)
129
+ activesupport (= 4.2.1)
130
+ bundler (>= 1.3.0, < 2.0)
131
+ railties (= 4.2.1)
132
+ sprockets-rails
133
+ rails-deprecated_sanitizer (1.0.3)
134
+ activesupport (>= 4.2.0.alpha)
135
+ rails-dom-testing (1.0.6)
136
+ activesupport (>= 4.2.0.beta, < 5.0)
137
+ nokogiri (~> 1.6.0)
138
+ rails-deprecated_sanitizer (>= 1.0.1)
139
+ rails-html-sanitizer (1.0.2)
140
+ loofah (~> 2.0)
141
+ railties (4.2.1)
142
+ actionpack (= 4.2.1)
143
+ activesupport (= 4.2.1)
125
144
  rake (>= 0.8.7)
126
- rdoc (~> 3.4)
127
- thor (>= 0.14.6, < 2.0)
145
+ thor (>= 0.18.1, < 2.0)
128
146
  rake (10.1.1)
129
- rdoc (3.12.2)
147
+ rdoc (4.2.0)
130
148
  json (~> 1.4)
131
149
  redgreen (1.2.2)
132
150
  rspec (2.99.0)
@@ -136,8 +154,8 @@ GEM
136
154
  rspec-core (2.99.2)
137
155
  rspec-expectations (2.99.2)
138
156
  diff-lcs (>= 1.1.3, < 2.0)
139
- rspec-mocks (2.99.2)
140
- rubysl (2.0.15)
157
+ rspec-mocks (2.99.3)
158
+ rubysl (2.1.0)
141
159
  rubysl-abbrev (~> 2.0)
142
160
  rubysl-base64 (~> 2.0)
143
161
  rubysl-benchmark (~> 2.0)
@@ -171,7 +189,7 @@ GEM
171
189
  rubysl-io-nonblock (~> 2.0)
172
190
  rubysl-io-wait (~> 2.0)
173
191
  rubysl-ipaddr (~> 2.0)
174
- rubysl-irb (~> 2.0)
192
+ rubysl-irb (~> 2.1)
175
193
  rubysl-logger (~> 2.0)
176
194
  rubysl-mathn (~> 2.0)
177
195
  rubysl-matrix (~> 2.0)
@@ -200,7 +218,6 @@ GEM
200
218
  rubysl-pstore (~> 2.0)
201
219
  rubysl-pty (~> 2.0)
202
220
  rubysl-rational (~> 2.0)
203
- rubysl-readline (~> 2.0)
204
221
  rubysl-resolv (~> 2.0)
205
222
  rubysl-rexml (~> 2.0)
206
223
  rubysl-rinda (~> 2.0)
@@ -242,14 +259,14 @@ GEM
242
259
  rubysl-csv (2.0.2)
243
260
  rubysl-english (~> 2.0)
244
261
  rubysl-curses (2.0.1)
245
- rubysl-date (2.0.8)
262
+ rubysl-date (2.0.9)
246
263
  rubysl-delegate (2.0.1)
247
- rubysl-digest (2.0.3)
264
+ rubysl-digest (2.0.8)
248
265
  rubysl-drb (2.0.1)
249
266
  rubysl-e2mmap (2.0.0)
250
267
  rubysl-english (2.0.0)
251
268
  rubysl-enumerator (2.0.0)
252
- rubysl-erb (2.0.1)
269
+ rubysl-erb (2.0.2)
253
270
  rubysl-etc (2.0.3)
254
271
  ffi2-generators (~> 0.1)
255
272
  rubysl-expect (2.0.0)
@@ -267,12 +284,11 @@ GEM
267
284
  rubysl-io-nonblock (2.0.0)
268
285
  rubysl-io-wait (2.0.0)
269
286
  rubysl-ipaddr (2.0.0)
270
- rubysl-irb (2.0.4)
287
+ rubysl-irb (2.1.1)
271
288
  rubysl-e2mmap (~> 2.0)
272
289
  rubysl-mathn (~> 2.0)
273
- rubysl-readline (~> 2.0)
274
290
  rubysl-thread (~> 2.0)
275
- rubysl-logger (2.0.0)
291
+ rubysl-logger (2.1.0)
276
292
  rubysl-mathn (2.0.0)
277
293
  rubysl-matrix (2.1.0)
278
294
  rubysl-e2mmap (~> 2.0)
@@ -295,21 +311,20 @@ GEM
295
311
  rubysl-observer (2.0.0)
296
312
  rubysl-open-uri (2.0.0)
297
313
  rubysl-open3 (2.0.0)
298
- rubysl-openssl (2.1.0)
314
+ rubysl-openssl (2.3.0)
299
315
  rubysl-optparse (2.0.1)
300
316
  rubysl-shellwords (~> 2.0)
301
317
  rubysl-ostruct (2.0.4)
302
- rubysl-pathname (2.0.0)
318
+ rubysl-pathname (2.1.0)
303
319
  rubysl-prettyprint (2.0.3)
304
320
  rubysl-prime (2.0.1)
305
321
  rubysl-profile (2.0.0)
306
322
  rubysl-profiler (2.0.1)
307
323
  rubysl-pstore (2.0.0)
308
- rubysl-pty (2.0.2)
324
+ rubysl-pty (2.0.3)
309
325
  rubysl-rational (2.0.1)
310
- rubysl-readline (2.0.2)
311
- rubysl-resolv (2.1.0)
312
- rubysl-rexml (2.0.2)
326
+ rubysl-resolv (2.1.2)
327
+ rubysl-rexml (2.0.4)
313
328
  rubysl-rinda (2.0.1)
314
329
  rubysl-rss (2.0.0)
315
330
  rubysl-scanf (2.0.0)
@@ -321,10 +336,10 @@ GEM
321
336
  rubysl-stringio (2.0.0)
322
337
  rubysl-strscan (2.0.0)
323
338
  rubysl-sync (2.0.0)
324
- rubysl-syslog (2.0.1)
339
+ rubysl-syslog (2.1.0)
325
340
  ffi2-generators (~> 0.1)
326
341
  rubysl-tempfile (2.0.1)
327
- rubysl-thread (2.0.2)
342
+ rubysl-thread (2.0.3)
328
343
  rubysl-thwait (2.0.0)
329
344
  rubysl-time (2.0.3)
330
345
  rubysl-timeout (2.0.0)
@@ -337,23 +352,25 @@ GEM
337
352
  rubysl-weakref (2.0.0)
338
353
  rubysl-webrick (2.0.0)
339
354
  rubysl-xmlrpc (2.0.0)
340
- rubysl-yaml (2.0.4)
355
+ rubysl-yaml (2.1.0)
341
356
  rubysl-zlib (2.0.1)
342
- sequel (4.21.0)
357
+ sequel (4.23.0)
343
358
  slop (3.6.0)
344
359
  spoon (0.0.4)
345
360
  ffi
346
- sprockets (2.2.2)
347
- hike (~> 1.2)
348
- multi_json (~> 1.0)
361
+ sprockets (3.1.0)
349
362
  rack (~> 1.0)
350
- tilt (~> 1.1, != 1.3.0)
351
- sqlite3 (1.3.9)
363
+ sprockets-rails (2.3.1)
364
+ actionpack (>= 3.0)
365
+ activesupport (>= 3.0)
366
+ sprockets (>= 2.8, < 4.0)
367
+ sqlite3 (1.3.10)
352
368
  sys-uname (0.9.2)
353
369
  ffi (>= 1.0.0)
354
370
  thor (0.19.1)
355
- tilt (1.4.1)
356
- travis (1.7.2)
371
+ thread_safe (0.3.5)
372
+ thread_safe (0.3.5-java)
373
+ travis (1.7.7)
357
374
  addressable (~> 2.3)
358
375
  backports
359
376
  faraday (~> 0.9)
@@ -364,13 +381,11 @@ GEM
364
381
  pry (~> 0.9, < 0.10)
365
382
  pusher-client (~> 0.4)
366
383
  typhoeus (~> 0.6, >= 0.6.8)
367
- treetop (1.4.15)
368
- polyglot
369
- polyglot (>= 0.3.1)
370
- typhoeus (0.6.9)
384
+ typhoeus (0.7.1)
371
385
  ethon (>= 0.7.1)
372
- tzinfo (0.3.41)
373
- websocket (1.2.1)
386
+ tzinfo (1.2.2)
387
+ thread_safe (~> 0.1)
388
+ websocket (1.2.2)
374
389
  will_paginate (3.0.7)
375
390
 
376
391
  PLATFORMS
@@ -387,7 +402,7 @@ DEPENDENCIES
387
402
  jdbc-sqlite3
388
403
  json (>= 1.5.1)
389
404
  kaminari
390
- rails (>= 3.2.0, < 4.0)
405
+ rails (>= 3.2.0)
391
406
  rake (~> 10.1.0)
392
407
  rdoc
393
408
  redgreen
data/README.md CHANGED
@@ -201,6 +201,8 @@ class Contact < ActiveRecord::Base
201
201
  end
202
202
  ```
203
203
 
204
+ ##### Temporary disable auto-indexing
205
+
204
206
  You can temporary disable auto-indexing using the <code>without_auto_index</code> scope. This is often used for performance reason.
205
207
 
206
208
  ```ruby
@@ -211,6 +213,69 @@ end
211
213
  Contact.reindex! # will use batch operations
212
214
  ```
213
215
 
216
+ ##### Queues & background jobs
217
+
218
+ You can configure the auto-indexing & auto-removal process to use a queue to perform those operations in background. ActiveJob (Rails >=4.2) queues are used by default but you can define your own queuing mechanism:
219
+
220
+ ```ruby
221
+ class Contact < ActiveRecord::Base
222
+ include AlgoliaSearch
223
+
224
+ algoliasearch enqueue: true do # ActiveJob will be triggered using a `algoliasearch` queue
225
+ attribute :first_name, :last_name, :email
226
+ end
227
+ end
228
+ ```
229
+
230
+ ##### With Sidekiq
231
+
232
+ If you're using [Sidekiq](https://github.com/mperham/sidekiq):
233
+
234
+ ```ruby
235
+ class Contact < ActiveRecord::Base
236
+ include AlgoliaSearch
237
+
238
+ algoliasearch enqueue: :trigger_sidekiq_worker do
239
+ attribute :first_name, :last_name, :email
240
+ end
241
+
242
+ def self.trigger_sidekiq_worker(record, remove)
243
+ MySidekiqWorker.perform_async(record, remove)
244
+ end
245
+ end
246
+
247
+ class MySidekiqWorker
248
+ def perform(record, remove)
249
+ remove ? record.remove_from_index! : record.index!
250
+ end
251
+ end
252
+ ```
253
+
254
+ ##### With DelayedJob
255
+
256
+ If you're using [delayed_job](https://github.com/collectiveidea/delayed_job):
257
+
258
+ ```ruby
259
+ class Contact < ActiveRecord::Base
260
+ include AlgoliaSearch
261
+
262
+ algoliasearch enqueue: :trigger_delayed_job do
263
+ attribute :first_name, :last_name, :email
264
+ end
265
+
266
+ def self.trigger_delayed_job(record, remove)
267
+ if remove
268
+ record.delay.remove_from_index!
269
+ else
270
+ record.delay.index!
271
+ end
272
+ end
273
+ end
274
+
275
+ ```
276
+
277
+ ##### Synchronism & testing
278
+
214
279
  You can force indexing and removing to be synchronous (in that case the gem will call the `wait_task` method to ensure the operation has been taken into account once the method returns) by setting the following option: (this is **NOT** recommended, except for testing purpose)
215
280
 
216
281
  ```ruby
@@ -238,7 +303,6 @@ class Contact < ActiveRecord::Base
238
303
  end
239
304
  ```
240
305
 
241
-
242
306
  #### Custom index name
243
307
 
244
308
  By default, the index name will be the class name, e.g. "Contact". You can customize the index name by using the `index_name` option:
@@ -462,10 +526,7 @@ class Item < ActiveRecord::Base
462
526
 
463
527
  # `title` is more important than `{story,comment}_text`, `{story,comment}_text` more than `url`, `url` more than `author`
464
528
  # btw, do not take into account position in most fields to avoid first word match boost
465
- attributesToIndex ['unordered(title)', 'unordered(story_text)', 'unordered(comment_text)', 'unordered(url)', 'author', 'created_at_i']
466
-
467
- # list of attributes to highlight
468
- attributesToHighlight ['title', 'story_text', 'comment_text', 'url', 'story_url', 'author', 'story_title']
529
+ attributesToIndex ['unordered(title)', 'unordered(story_text)', 'unordered(comment_text)', 'unordered(url)', 'author']
469
530
 
470
531
  # tags used for filtering
471
532
  tags do
@@ -475,10 +536,6 @@ class Item < ActiveRecord::Base
475
536
  # use associated number of HN points to sort results (last sort criteria)
476
537
  customRanking ['desc(points)', 'desc(num_comments)']
477
538
 
478
- # controls the way results are sorted sorting on the following 4 criteria (one after another)
479
- # I removed the 'exact' match critera (improve 1-words query relevance, doesn't fit HNSearch needs)
480
- ranking ['typo', 'proximity', 'attribute', 'custom']
481
-
482
539
  # google+, $1.5M raises, C#: we love you
483
540
  separatorsToIndex '+#$'
484
541
  end
@@ -803,6 +860,23 @@ Caveats
803
860
 
804
861
  This gem makes intensive use of Rails' callbacks to trigger the indexing tasks. If you're using methods bypassing ```after_validation```, ```before_save``` or ```after_save``` callbacks, it will not index your changes. For example: ```update_attribute``` doesn't perform validations checks, to perform validations when updating use ```update_attributes```.
805
862
 
863
+ Timeouts
864
+ ---------
865
+
866
+ You can configure a bunch of timeout threshold by setting the following options at initialization time:
867
+
868
+ ```ruby
869
+ AlgoliaSearch.configuration = {
870
+ application_id: 'YourApplicationID',
871
+ api_key: 'YourAPIKey'
872
+ connect_timeout: 2,
873
+ receive_timeout: 30,
874
+ send_timeout: 30,
875
+ batch_timeout: 120,
876
+ search_timeout: 5
877
+ }
878
+ ```
879
+
806
880
  Note on testing
807
881
  -----------------
808
882
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.12.2
1
+ 1.13.0
@@ -17,6 +17,12 @@ if defined? Rails
17
17
  end
18
18
  end
19
19
 
20
+ begin
21
+ require 'active_job'
22
+ rescue LoadError
23
+ # no queue support, fine
24
+ end
25
+
20
26
  require 'logger'
21
27
 
22
28
  module AlgoliaSearch
@@ -207,6 +213,17 @@ module AlgoliaSearch
207
213
  end
208
214
  end
209
215
 
216
+ # Default queueing system
217
+ if defined?(::ActiveJob::Base)
218
+ class AlgoliaJob < ::ActiveJob::Base
219
+ queue_as :algoliasearch
220
+
221
+ def perform(record, method)
222
+ record.send(method)
223
+ end
224
+ end
225
+ end
226
+
210
227
  # this class wraps an Algolia::Index object ensuring all raised exceptions
211
228
  # are correctly logged or thrown depending on the `raise_on_failure` option
212
229
  class SafeIndex
@@ -301,6 +318,20 @@ module AlgoliaSearch
301
318
  after_validation :algolia_mark_synchronous if respond_to?(:after_validation)
302
319
  end
303
320
  end
321
+ if options[:enqueue]
322
+ raise ArgumentError.new("Cannot use a enqueue if the `synchronous` option if set") if options[:synchronous]
323
+ algoliasearch_options[:enqueue] = if options[:enqueue] == true
324
+ Proc.new do |record, remove|
325
+ AlgoliaJob.perform_later(record, remove ? 'algolia_remove_from_index!' : 'algolia_index!')
326
+ end
327
+ elsif options[:enqueue].respond_to?(:call)
328
+ options[:enqueue]
329
+ elsif options[:enqueue].is_a?(Symbol)
330
+ Proc.new { |record, remove| self.send(options[:enqueue], record, remove) }
331
+ else
332
+ raise ArgumentError.new("Invalid `enqueue` option: #{options[:enqueue]}")
333
+ end
334
+ end
304
335
  unless options[:auto_index] == false
305
336
  if defined?(::Sequel) && self < Sequel::Model
306
337
  class_eval do
@@ -333,7 +364,19 @@ module AlgoliaSearch
333
364
  end
334
365
  end
335
366
  unless options[:auto_remove] == false
336
- after_destroy { |searchable| searchable.remove_from_index! } if respond_to?(:after_destroy)
367
+ if defined?(::Sequel) && self < Sequel::Model
368
+ class_eval do
369
+ copy_after_destroy = instance_method(:after_destroy)
370
+
371
+ define_method(:after_destroy) do |*args|
372
+ copy_after_destroy.bind(self).call
373
+ algolia_enqueue_remove_from_index!(algolia_synchronous?)
374
+ super(*args)
375
+ end
376
+ end
377
+ else
378
+ after_destroy { |searchable| searchable.algolia_enqueue_remove_from_index!(algolia_synchronous?) } if respond_to?(:after_destroy)
379
+ end
337
380
  end
338
381
  end
339
382
 
@@ -726,6 +769,22 @@ module AlgoliaSearch
726
769
  self.class.algolia_remove_from_index!(self, synchronous || algolia_synchronous?)
727
770
  end
728
771
 
772
+ def algolia_enqueue_remove_from_index!(synchronous)
773
+ if algoliasearch_options[:enqueue]
774
+ algoliasearch_options[:enqueue].call(self, true)
775
+ else
776
+ algolia_remove_from_index!(synchronous)
777
+ end
778
+ end
779
+
780
+ def algolia_enqueue_index!(synchronous)
781
+ if algoliasearch_options[:enqueue]
782
+ algoliasearch_options[:enqueue].call(self, false)
783
+ else
784
+ algolia_index!(synchronous)
785
+ end
786
+ end
787
+
729
788
  private
730
789
 
731
790
  def algolia_synchronous?
@@ -752,7 +811,7 @@ module AlgoliaSearch
752
811
 
753
812
  def algolia_perform_index_tasks
754
813
  return if !@algolia_auto_indexing || @algolia_must_reindex == false
755
- algolia_index!
814
+ algolia_enqueue_index!(algolia_synchronous?)
756
815
  remove_instance_variable(:@algolia_auto_indexing) if instance_variable_defined?(:@algolia_auto_indexing)
757
816
  remove_instance_variable(:@algolia_synchronous) if instance_variable_defined?(:@algolia_synchronous)
758
817
  remove_instance_variable(:@algolia_must_reindex) if instance_variable_defined?(:@algolia_must_reindex)
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algoliasearch-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.2
4
+ version: 1.13.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-05-28 00:00:00.000000000 Z
11
+ date: 2015-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.5.1
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: 1.5.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: algoliasearch
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.2.14
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.2.14
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: will_paginate
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.3.15
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: 2.3.15
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: kaminari
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: travis
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
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rdoc
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: AlgoliaSearch integration to your favorite ORM
@@ -117,9 +117,9 @@ extra_rdoc_files:
117
117
  - LICENSE
118
118
  - README.md
119
119
  files:
120
- - ".document"
121
- - ".rspec"
122
- - ".travis.yml"
120
+ - .document
121
+ - .rspec
122
+ - .travis.yml
123
123
  - ChangeLog
124
124
  - Gemfile
125
125
  - Gemfile.lock
@@ -172,17 +172,17 @@ require_paths:
172
172
  - lib
173
173
  required_ruby_version: !ruby/object:Gem::Requirement
174
174
  requirements:
175
- - - ">="
175
+ - - '>='
176
176
  - !ruby/object:Gem::Version
177
177
  version: '0'
178
178
  required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  requirements:
180
- - - ">="
180
+ - - '>='
181
181
  - !ruby/object:Gem::Version
182
182
  version: '0'
183
183
  requirements: []
184
184
  rubyforge_project:
185
- rubygems_version: 2.4.5
185
+ rubygems_version: 2.0.14
186
186
  signing_key:
187
187
  specification_version: 4
188
188
  summary: AlgoliaSearch integration to your favorite ORM