mongoid-xapian 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -7
- data/VERSION +1 -1
- data/lib/mongoid-xapian.rb +21 -3
- data/lib/mongoid-xapian/tasks.rb +13 -7
- data/lib/mongoid-xapian/trail.rb +9 -7
- data/spec/mongoid-xapian_spec.rb +1 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
1
|
+
# mongoid-xapian
|
2
2
|
|
3
3
|
Xapian for mongoid
|
4
4
|
|
5
|
-
|
5
|
+
## Usage
|
6
6
|
|
7
7
|
Include MongoidXapian in your model and define what fields need to be
|
8
8
|
indexed.
|
@@ -15,16 +15,21 @@ indexed.
|
|
15
15
|
end
|
16
16
|
|
17
17
|
now you have to run `MongoidXapian.index!` to index the changes into
|
18
|
-
xapian.
|
19
|
-
|
18
|
+
xapian. if you have a background job processor like delayed job you can
|
19
|
+
do something like:
|
20
20
|
|
21
|
-
|
21
|
+
MongoidXapian.delay.index!
|
22
|
+
|
23
|
+
A rake task called `xapian:index` is also provided so you can setup a
|
24
|
+
cron task to run it periodically.
|
25
|
+
|
26
|
+
Once you configure your model and index the changes you can perform searches using:
|
22
27
|
|
23
28
|
YourModel.search(query)
|
24
29
|
|
25
30
|
|
26
31
|
|
27
|
-
|
32
|
+
## Contributing to mongoid-xapian
|
28
33
|
|
29
34
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
30
35
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
@@ -34,7 +39,7 @@ once you configure your model and index it you can search it using:
|
|
34
39
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
35
40
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
36
41
|
|
37
|
-
|
42
|
+
## Copyright
|
38
43
|
|
39
44
|
Copyright (c) 2012 David A. Cuadrado. See LICENSE.txt for
|
40
45
|
further details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/mongoid-xapian.rb
CHANGED
@@ -17,6 +17,8 @@ module MongoidXapian
|
|
17
17
|
attr_accessor :xapian_options, :xapian_fields
|
18
18
|
end
|
19
19
|
|
20
|
+
MongoidXapian.indexable_models << self.to_s
|
21
|
+
|
20
22
|
field :xapian_id, :type => Integer
|
21
23
|
|
22
24
|
after_create do |doc|
|
@@ -26,9 +28,20 @@ module MongoidXapian
|
|
26
28
|
end
|
27
29
|
|
28
30
|
after_update do |doc|
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
needs_indexing = false
|
32
|
+
# see if at least one changed field is indexable
|
33
|
+
doc.changes.each do |key, value|
|
34
|
+
if doc.class.xapian_fields.include?(key.to_sym)
|
35
|
+
needs_indexing = true
|
36
|
+
break
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
if needs_indexing
|
41
|
+
MongoidXapian::Trail.create(:action => :update,
|
42
|
+
:doc_type => doc.class.to_s,
|
43
|
+
:doc_id => doc.id)
|
44
|
+
end
|
32
45
|
end
|
33
46
|
|
34
47
|
after_destroy do |doc|
|
@@ -57,6 +70,11 @@ module MongoidXapian
|
|
57
70
|
MongoidXapian::Trail.index_all!
|
58
71
|
end
|
59
72
|
|
73
|
+
# List of indexable models
|
74
|
+
def self.indexable_models
|
75
|
+
@indexable_models ||= Set.new
|
76
|
+
end
|
77
|
+
|
60
78
|
module ClassMethods
|
61
79
|
def fti(*args)
|
62
80
|
# make sure id is not in the list
|
data/lib/mongoid-xapian/tasks.rb
CHANGED
@@ -8,14 +8,20 @@ namespace :xapian do
|
|
8
8
|
MongoidXapian::Trail.index_all!
|
9
9
|
end
|
10
10
|
|
11
|
-
desc "Reindex all documents in the given model
|
11
|
+
desc "Reindex all documents in the given model"
|
12
12
|
task :reindex do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
MongoidXapian.indexable_models.each do |mod|
|
14
|
+
model_class = mod.constantize rescue nil
|
15
|
+
if model_class
|
16
|
+
puts ">> Indexing #{model_class}..."
|
17
|
+
|
18
|
+
model_class.all.each do |doc|
|
19
|
+
MongoidXapian::Trail.create!(:action => :update,
|
20
|
+
:doc_id => doc.id,
|
21
|
+
:doc_type => doc.class.to_s)
|
22
|
+
MongoidXapian::Trail.index_all!
|
23
|
+
end
|
24
|
+
end
|
19
25
|
end
|
20
26
|
end
|
21
27
|
end
|
data/lib/mongoid-xapian/trail.rb
CHANGED
@@ -56,13 +56,15 @@ module MongoidXapian
|
|
56
56
|
|
57
57
|
def update_document
|
58
58
|
with_xapian_database do |db|
|
59
|
-
if indexable.
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
59
|
+
if indexable.present?
|
60
|
+
if indexable.xapian_id.to_i > 0
|
61
|
+
xapian_doc = XapianFu::XapianDoc.new(indexable.to_xapian.merge(:id => indexable.xapian_id), :xapian_db => db)
|
62
|
+
xapian_doc.save
|
63
|
+
else
|
64
|
+
xapian_doc = db.add_doc(indexable.to_xapian)
|
65
|
+
indexable.set(:xapian_id, xapian_doc.id)
|
66
|
+
indexable.xapian_id = xapian_doc.id
|
67
|
+
end
|
66
68
|
end
|
67
69
|
end
|
68
70
|
end
|
data/spec/mongoid-xapian_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-xapian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -211,7 +211,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
211
211
|
version: '0'
|
212
212
|
segments:
|
213
213
|
- 0
|
214
|
-
hash:
|
214
|
+
hash: -758691094896525050
|
215
215
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
216
216
|
none: false
|
217
217
|
requirements:
|