xapor 0.1.4 → 0.1.5
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.
- data/VERSION +1 -1
- data/lib/xapor/model_integration.rb +18 -15
- data/xapor.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
@@ -12,13 +12,18 @@ module Xapor::XapianFuIntegration
|
|
12
12
|
|
13
13
|
module ClassMethods
|
14
14
|
def xapor
|
15
|
+
class << self
|
16
|
+
attr_accessor :xapor_config
|
17
|
+
attr_accessor :xapor_db
|
18
|
+
end
|
19
|
+
|
15
20
|
include XapianFu
|
16
21
|
|
17
|
-
def search(query)
|
22
|
+
def self.search(query)
|
18
23
|
xapor_db.search(query)
|
19
24
|
end
|
20
25
|
|
21
|
-
def reset_index
|
26
|
+
def self.reset_index
|
22
27
|
if @db
|
23
28
|
@db.flush
|
24
29
|
@db.ro.close
|
@@ -30,28 +35,26 @@ module Xapor::XapianFuIntegration
|
|
30
35
|
end
|
31
36
|
end
|
32
37
|
|
33
|
-
|
34
|
-
self.class.instance_variable_get(:@config)
|
35
|
-
end
|
36
|
-
|
37
|
-
def xapor_db
|
38
|
-
@db ||= XapianDb.new(xapor_config.xapian_fu_db.merge(:create => true))
|
39
|
-
end
|
40
|
-
|
41
|
-
@config = Xapor::Config.new
|
38
|
+
self.xapor_config = Xapor::Config.new
|
42
39
|
if block_given?
|
43
|
-
yield
|
40
|
+
yield self.xapor_config
|
44
41
|
end
|
42
|
+
self.xapor_db = ::XapianFu::XapianDb.new(self.xapor_config.xapian_fu_db.merge(:create => true))
|
45
43
|
|
46
|
-
|
47
|
-
|
44
|
+
eigenclass = class << self
|
45
|
+
self
|
48
46
|
end
|
47
|
+
self.xapor_config.search_fields.each do |field|
|
48
|
+
eigenclass.send(:define_method, :"search_by_#{field}") do |query|
|
49
|
+
self.search(query)
|
50
|
+
end
|
51
|
+
end
|
49
52
|
|
50
53
|
if defined? ActiveRecord && ancestors.includes(ActiveRecord::Base)
|
51
54
|
after_save :add_to_index
|
52
55
|
after_destroy :remove_from_index
|
53
56
|
#in-memory index, needs to be indexed on startup
|
54
|
-
all.each {|o| o.add_to_index} unless
|
57
|
+
all.each {|o| o.add_to_index} unless self.xapor_config.directory_config
|
55
58
|
end
|
56
59
|
end
|
57
60
|
end
|
data/xapor.gemspec
CHANGED