searchkick 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +18 -11
- data/lib/searchkick/model.rb +6 -2
- data/lib/searchkick/version.rb +1 -1
- data/test/index_test.rb +13 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74cd357aadff8dc7f80b5db94f74dde7940abcd8
|
4
|
+
data.tar.gz: ae9c5f086a639fbb18e0848a862231f188ee7624
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22c8007b1672a5ca1d6def91d812509f50fc795b0744817f8af52feaa024c569b6f993f41b138f47c2aa5d42a7709faa2e6a51f1ff3a5005ff0c8e084ae1a4e9
|
7
|
+
data.tar.gz: ce18c6e5766bfc8a203c1a6ebe77f9d717b7a88c6ce361858ad15fa3049a4722cb5dcc23bc41f0e3d3be9e12f34a47d70a6783b458b2fe9701cb5d673376711f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -657,25 +657,18 @@ class Product < ActiveRecord::Base
|
|
657
657
|
end
|
658
658
|
```
|
659
659
|
|
660
|
-
|
660
|
+
Asynchronous reindexing
|
661
661
|
|
662
662
|
```ruby
|
663
663
|
class Product < ActiveRecord::Base
|
664
664
|
searchkick callbacks: false
|
665
665
|
|
666
666
|
# add the callbacks manually
|
667
|
-
after_save :reindex, if: proc{|model| model.name_changed? } # use your own condition
|
668
|
-
after_destroy :reindex
|
669
|
-
end
|
670
|
-
```
|
671
667
|
|
672
|
-
|
668
|
+
# ActiveRecord - one callback
|
669
|
+
after_commit :reindex_async
|
673
670
|
|
674
|
-
|
675
|
-
class Product < ActiveRecord::Base
|
676
|
-
searchkick callbacks: false
|
677
|
-
|
678
|
-
# add the callbacks manually
|
671
|
+
# Mongoid - two callbacks
|
679
672
|
after_save :reindex_async
|
680
673
|
after_destroy :reindex_async
|
681
674
|
|
@@ -686,6 +679,20 @@ class Product < ActiveRecord::Base
|
|
686
679
|
end
|
687
680
|
```
|
688
681
|
|
682
|
+
Reindex conditionally
|
683
|
+
|
684
|
+
**Note:** With ActiveRecord, use this feature with caution - [transaction rollbacks can cause data inconstencies](https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-model/README.md#custom-callbacks)
|
685
|
+
|
686
|
+
```ruby
|
687
|
+
class Product < ActiveRecord::Base
|
688
|
+
searchkick callbacks: false
|
689
|
+
|
690
|
+
# add the callbacks manually
|
691
|
+
after_save :reindex, if: proc{|model| model.name_changed? } # use your own condition
|
692
|
+
after_destroy :reindex
|
693
|
+
end
|
694
|
+
```
|
695
|
+
|
689
696
|
Reindex all models (Rails only)
|
690
697
|
|
691
698
|
```sh
|
data/lib/searchkick/model.rb
CHANGED
@@ -19,8 +19,12 @@ module Searchkick
|
|
19
19
|
extend Searchkick::Reindex
|
20
20
|
include Searchkick::Similar
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
if respond_to?(:after_commit)
|
23
|
+
after_commit :reindex, if: proc{ self.class.search_callbacks? }
|
24
|
+
else
|
25
|
+
after_save :reindex, if: proc{ self.class.search_callbacks? }
|
26
|
+
after_destroy :reindex, if: proc{ self.class.search_callbacks? }
|
27
|
+
end
|
24
28
|
|
25
29
|
def self.enable_search_callbacks
|
26
30
|
class_variable_set :@@searchkick_callbacks, true
|
data/lib/searchkick/version.rb
CHANGED
data/test/index_test.rb
CHANGED
@@ -32,4 +32,17 @@ class TestIndex < Minitest::Unit::TestCase
|
|
32
32
|
assert_equal ["Dollar Tree"], Store.search(query: {match: {name: "Dollar Tree"}}).map(&:name)
|
33
33
|
end
|
34
34
|
|
35
|
+
if defined?(ActiveRecord)
|
36
|
+
|
37
|
+
def test_transaction
|
38
|
+
Product.transaction do
|
39
|
+
store_names ["Product A"]
|
40
|
+
raise ActiveRecord::Rollback
|
41
|
+
end
|
42
|
+
|
43
|
+
assert_search "product", []
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
35
48
|
end
|