fulltext_searchable 0.1.0 → 0.1.1
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.
@@ -80,17 +80,8 @@ class FulltextIndex < ActiveRecord::Base
|
|
80
80
|
# 結果を取得し、インデックス元モデルの配列に変換。
|
81
81
|
#
|
82
82
|
def items(*args)
|
83
|
-
|
84
|
-
|
85
|
-
# ピリオドの前の文字列を参照テーブル名と誤認し、eager loadをjoinの方針に切り替えて
|
86
|
-
# polymorphic associationをjoinでeager loadできず例外を吐く。
|
87
|
-
# なのでrescueしてeager loadなしで再度クエリを試みておく。
|
88
|
-
select('`_id`, `item_type`, `item_id`').
|
89
|
-
includes(:item).all(*args).map{|i| i.item }
|
90
|
-
rescue ActiveRecord::EagerLoadPolymorphicError
|
91
|
-
# eager loadなしで試みる
|
92
|
-
select('`_id`, `item_type`, `item_id`').all(*args).map{|i| i.item }
|
93
|
-
end
|
83
|
+
select('`_id`, `item_type`, `item_id`').
|
84
|
+
preload(:item).all(*args).map{|i| i.item }.compact
|
94
85
|
end
|
95
86
|
##
|
96
87
|
# 特定レコードの更新をインデックスに非同期で反映する。
|
@@ -102,7 +93,7 @@ class FulltextIndex < ActiveRecord::Base
|
|
102
93
|
next unless record.item
|
103
94
|
record.text = record.item.fulltext_keywords
|
104
95
|
record.save
|
105
|
-
|
96
|
+
end
|
106
97
|
end
|
107
98
|
if FulltextSearchable::Engine.config.respond_to?(:async) &&
|
108
99
|
FulltextSearchable::Engine.config.async
|
@@ -75,9 +75,14 @@ describe FulltextIndex do
|
|
75
75
|
FulltextIndex.match('天気', :with => [@taro, @jiro], :model => [Blog, User]).items.count.should == 5
|
76
76
|
end
|
77
77
|
|
78
|
-
it "should
|
78
|
+
it "should not break with ActiveRecord's eager loading behavior" do
|
79
79
|
FulltextIndex.match('ab.').items.should_not raise_error ActiveRecord::EagerLoadPolymorphicError
|
80
80
|
end
|
81
|
+
|
82
|
+
it "should not contain nil in items" do
|
83
|
+
Blog.delete_all :id => @jiro.blogs.map(&:id)
|
84
|
+
FulltextIndex.match('天気').items.should_not include(nil)
|
85
|
+
end
|
81
86
|
end
|
82
87
|
|
83
88
|
context "optimization" do
|
data/spec/models/news_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fulltext_searchable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -296,12 +296,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
296
296
|
- - ! '>='
|
297
297
|
- !ruby/object:Gem::Version
|
298
298
|
version: '0'
|
299
|
+
segments:
|
300
|
+
- 0
|
301
|
+
hash: 2065254535944603589
|
299
302
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
300
303
|
none: false
|
301
304
|
requirements:
|
302
305
|
- - ! '>='
|
303
306
|
- !ruby/object:Gem::Version
|
304
307
|
version: '0'
|
308
|
+
segments:
|
309
|
+
- 0
|
310
|
+
hash: 2065254535944603589
|
305
311
|
requirements: []
|
306
312
|
rubyforge_project:
|
307
313
|
rubygems_version: 1.8.25
|