mongoid-xapian 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +68 -0
- data/LICENSE.txt +20 -0
- data/README.md +41 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/lib/mongoid-xapian.rb +102 -0
- data/lib/mongoid-xapian/indexer.rb +55 -0
- data/lib/mongoid-xapian/tasks.rb +21 -0
- data/lib/mongoid-xapian/trail.rb +79 -0
- data/mongoid-xapian.gemspec +83 -0
- data/spec/models/blog_post.rb +11 -0
- data/spec/mongoid-xapian_spec.rb +64 -0
- data/spec/mongoid.yml +19 -0
- data/spec/spec_helper.rb +18 -0
- metadata +227 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem 'mongoid'
|
7
|
+
gem 'xapian-ruby'
|
8
|
+
gem 'xapian-fu'
|
9
|
+
|
10
|
+
# Add dependencies to develop your gem here.
|
11
|
+
# Include everything needed to run rake, tests, features, etc.
|
12
|
+
group :development do
|
13
|
+
gem "pry"
|
14
|
+
gem "rspec", "~> 2.8.0"
|
15
|
+
gem "yard", "~> 0.7"
|
16
|
+
gem "rdoc", "~> 3.12"
|
17
|
+
gem "bundler"
|
18
|
+
gem "jeweler", "~> 1.8.4"
|
19
|
+
gem "simplecov", ">= 0"
|
20
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.2.7)
|
5
|
+
activesupport (= 3.2.7)
|
6
|
+
builder (~> 3.0.0)
|
7
|
+
activesupport (3.2.7)
|
8
|
+
i18n (~> 0.6)
|
9
|
+
multi_json (~> 1.0)
|
10
|
+
builder (3.0.0)
|
11
|
+
coderay (1.0.7)
|
12
|
+
diff-lcs (1.1.3)
|
13
|
+
git (1.2.5)
|
14
|
+
i18n (0.6.0)
|
15
|
+
jeweler (1.8.4)
|
16
|
+
bundler (~> 1.0)
|
17
|
+
git (>= 1.2.5)
|
18
|
+
rake
|
19
|
+
rdoc
|
20
|
+
json (1.7.4)
|
21
|
+
method_source (0.8)
|
22
|
+
mongoid (3.0.3)
|
23
|
+
activemodel (~> 3.1)
|
24
|
+
moped (~> 1.1)
|
25
|
+
origin (~> 1.0)
|
26
|
+
tzinfo (~> 0.3.22)
|
27
|
+
moped (1.2.0)
|
28
|
+
multi_json (1.3.6)
|
29
|
+
origin (1.0.4)
|
30
|
+
pry (0.9.10)
|
31
|
+
coderay (~> 1.0.5)
|
32
|
+
method_source (~> 0.8)
|
33
|
+
slop (~> 3.3.1)
|
34
|
+
rake (0.9.2.2)
|
35
|
+
rdoc (3.12)
|
36
|
+
json (~> 1.4)
|
37
|
+
rspec (2.8.0)
|
38
|
+
rspec-core (~> 2.8.0)
|
39
|
+
rspec-expectations (~> 2.8.0)
|
40
|
+
rspec-mocks (~> 2.8.0)
|
41
|
+
rspec-core (2.8.0)
|
42
|
+
rspec-expectations (2.8.0)
|
43
|
+
diff-lcs (~> 1.1.2)
|
44
|
+
rspec-mocks (2.8.0)
|
45
|
+
simplecov (0.6.4)
|
46
|
+
multi_json (~> 1.0)
|
47
|
+
simplecov-html (~> 0.5.3)
|
48
|
+
simplecov-html (0.5.3)
|
49
|
+
slop (3.3.2)
|
50
|
+
tzinfo (0.3.33)
|
51
|
+
xapian-fu (1.5.0)
|
52
|
+
xapian-ruby (1.2.12)
|
53
|
+
yard (0.8.2.1)
|
54
|
+
|
55
|
+
PLATFORMS
|
56
|
+
ruby
|
57
|
+
|
58
|
+
DEPENDENCIES
|
59
|
+
bundler
|
60
|
+
jeweler (~> 1.8.4)
|
61
|
+
mongoid
|
62
|
+
pry
|
63
|
+
rdoc (~> 3.12)
|
64
|
+
rspec (~> 2.8.0)
|
65
|
+
simplecov
|
66
|
+
xapian-fu
|
67
|
+
xapian-ruby
|
68
|
+
yard (~> 0.7)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 David A. Cuadrado
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
= mongoid-xapian
|
2
|
+
|
3
|
+
Xapian for mongoid
|
4
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
Include MongoidXapian in your model and define what fields need to be
|
8
|
+
indexed.
|
9
|
+
|
10
|
+
class YourModel
|
11
|
+
include Mongoid::Document
|
12
|
+
include MongoidXapian
|
13
|
+
|
14
|
+
fti :title, :body
|
15
|
+
end
|
16
|
+
|
17
|
+
now you have to run `MongoidXapian.index!` to index the changes into
|
18
|
+
xapian.
|
19
|
+
A rake task called `xapian:index` is also provided.
|
20
|
+
|
21
|
+
once you configure your model and index it you can search it using:
|
22
|
+
|
23
|
+
YourModel.search(query)
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
== Contributing to mongoid-xapian
|
28
|
+
|
29
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
30
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
31
|
+
* Fork the project.
|
32
|
+
* Start a feature/bugfix branch.
|
33
|
+
* Commit and push until you are happy with your contribution.
|
34
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
35
|
+
* 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
|
+
|
37
|
+
== Copyright
|
38
|
+
|
39
|
+
Copyright (c) 2012 David A. Cuadrado. See LICENSE.txt for
|
40
|
+
further details.
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "mongoid-xapian"
|
18
|
+
gem.homepage = "http://github.com/dcu/mongoid-xapian"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{FTS for mongoid using xapian}
|
21
|
+
gem.description = %Q{Full text search for mongoid using xapian}
|
22
|
+
gem.email = "krawek@gmail.com"
|
23
|
+
gem.authors = ["David A. Cuadrado"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'yard'
|
42
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
3
|
+
$:.unshift File.expand_path(File.dirname(__FILE__))
|
4
|
+
|
5
|
+
require 'mongoid'
|
6
|
+
require 'xapian-fu'
|
7
|
+
|
8
|
+
require 'mongoid-xapian/trail'
|
9
|
+
require 'mongoid-xapian/indexer'
|
10
|
+
require 'mongoid-xapian/tasks'
|
11
|
+
|
12
|
+
module MongoidXapian
|
13
|
+
extend ActiveSupport::Concern
|
14
|
+
|
15
|
+
included do
|
16
|
+
class << self
|
17
|
+
attr_accessor :xapian_options, :xapian_fields
|
18
|
+
end
|
19
|
+
|
20
|
+
field :xapian_id, :type => Integer
|
21
|
+
|
22
|
+
after_create do |doc|
|
23
|
+
MongoidXapian::Trail.create(:action => :create,
|
24
|
+
:doc_type => doc.class.to_s,
|
25
|
+
:doc_id => doc.id)
|
26
|
+
end
|
27
|
+
|
28
|
+
after_update do |doc|
|
29
|
+
MongoidXapian::Trail.create(:action => :update,
|
30
|
+
:doc_type => doc.class.to_s,
|
31
|
+
:doc_id => doc.id)
|
32
|
+
end
|
33
|
+
|
34
|
+
after_destroy do |doc|
|
35
|
+
MongoidXapian::Trail.create(:action => :destroy,
|
36
|
+
:doc_type => doc.class.to_s,
|
37
|
+
:doc_id => doc.xapian_id)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def xapian_indexer
|
42
|
+
MongoidXapian::Indexer.new(self)
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_xapian
|
46
|
+
fields = {:_id => self._id}
|
47
|
+
self.class.xapian_fields.each do |field|
|
48
|
+
fields[field] = self.send(field)
|
49
|
+
end
|
50
|
+
|
51
|
+
fields
|
52
|
+
end
|
53
|
+
|
54
|
+
# Usage: MongoidXapian.index_all!
|
55
|
+
# short cut for MongoidXapian::Trail.index_all!
|
56
|
+
def self.index!
|
57
|
+
MongoidXapian::Trail.index_all!
|
58
|
+
end
|
59
|
+
|
60
|
+
module ClassMethods
|
61
|
+
def fti(*args)
|
62
|
+
# make sure id is not in the list
|
63
|
+
args.delete(:id)
|
64
|
+
|
65
|
+
# index mongodb' id
|
66
|
+
args << :_id
|
67
|
+
|
68
|
+
@xapian_options = args.extract_options!
|
69
|
+
@xapian_fields = args
|
70
|
+
end
|
71
|
+
|
72
|
+
def xapian_db(language = "en")
|
73
|
+
@xapian_databases ||= {}
|
74
|
+
|
75
|
+
@xapian_databases[language] ||= XapianFu::XapianDb.new({
|
76
|
+
:dir => self.xapian_db_path(language),
|
77
|
+
:create => true,
|
78
|
+
:store => @xapian_fields
|
79
|
+
})
|
80
|
+
end
|
81
|
+
|
82
|
+
def search_db(language = "en")
|
83
|
+
XapianFu::XapianDb.new({
|
84
|
+
:dir => self.xapian_db_path(language),
|
85
|
+
:create => false,
|
86
|
+
:store => @xapian_fields
|
87
|
+
})
|
88
|
+
end
|
89
|
+
|
90
|
+
def xapian_db_path(language = "en")
|
91
|
+
"#{Bundler.root}/xapian/#{self.to_s.underscore}.#{language}.db"
|
92
|
+
end
|
93
|
+
|
94
|
+
def search(pattern, language = "en")
|
95
|
+
ids = search_db(language).search(pattern).map do |result|
|
96
|
+
result.values[:_id]
|
97
|
+
end
|
98
|
+
|
99
|
+
self.where(:_id.in => ids)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module MongoidXapian
|
2
|
+
module Indexer
|
3
|
+
def self.add(doc)
|
4
|
+
on_db(doc) do
|
5
|
+
xapian_doc = documents.add(doc.to_xapian)
|
6
|
+
doc.set(:xapian_id, xapian_doc.id)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.update(doc)
|
11
|
+
if doc.xapian_id
|
12
|
+
on_db(doc) do
|
13
|
+
xapian_doc = XapianFu::XapianDoc.new(doc.to_xapian.merge(:id => doc.xapian_id), :xapian_db => self)
|
14
|
+
xapian_doc.save
|
15
|
+
end
|
16
|
+
else
|
17
|
+
add(doc)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.remove(doc)
|
22
|
+
if doc.xapian_id
|
23
|
+
on_db(doc) do
|
24
|
+
documents.delete(doc.xapian_id)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def self.on_db(doc, &block)
|
31
|
+
10.times do
|
32
|
+
begin
|
33
|
+
doc.class.xapian_db.instance_exec(&block)
|
34
|
+
break
|
35
|
+
rescue IOError
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Thread.start do
|
40
|
+
ok = false
|
41
|
+
10.times do
|
42
|
+
begin
|
43
|
+
doc.class.xapian_db.flush
|
44
|
+
ok = true
|
45
|
+
break
|
46
|
+
rescue IOError
|
47
|
+
end
|
48
|
+
sleep 0.1
|
49
|
+
end
|
50
|
+
|
51
|
+
puts "CANNOT UNLOCK DB" if !ok
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
namespace :xapian do
|
5
|
+
desc "Index all pending documents"
|
6
|
+
task :index do
|
7
|
+
puts "Indexing #{MongoidXapian::Trail.count} changes..."
|
8
|
+
MongoidXapian::Trail.index_all!
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Reindex all documents in the given model. pass MODEL=ModelName to this task"
|
12
|
+
task :reindex do
|
13
|
+
model = ENV['MODEL'].constantize
|
14
|
+
model.all.each do |doc|
|
15
|
+
MongoidXapian::Trail.create!(:action => :update,
|
16
|
+
:doc_id => doc.id,
|
17
|
+
:doc_type => doc.class.to_s)
|
18
|
+
MongoidXapian::Trail.index_all!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module MongoidXapian
|
2
|
+
class Trail
|
3
|
+
include Mongoid::Document
|
4
|
+
include Mongoid::Timestamps
|
5
|
+
|
6
|
+
field :action, :type => String
|
7
|
+
field :doc_id, :type => String
|
8
|
+
field :doc_type, :type => String
|
9
|
+
field :language, :type => String, :default => 'en'
|
10
|
+
|
11
|
+
def index!
|
12
|
+
self.send(:"#{action}_document")
|
13
|
+
self.delete
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.index_all!
|
17
|
+
FileUtils.mkpath("#{Bundler.root}/xapian")
|
18
|
+
while self.count != 0
|
19
|
+
# get the documents in group of 100 so the cursor doesn't expire.
|
20
|
+
self.order_by(:created_at.asc).limit(100).each do |trail|
|
21
|
+
begin
|
22
|
+
trail.index!
|
23
|
+
rescue Exception => e
|
24
|
+
puts "[mongoid-xapit] Something went wrong while indexing document #{trail.doc_type} #{trail.doc_id}: #{e.to_s} (#{e.class})"
|
25
|
+
puts "#{e.backtrace[0,10].join("\n\t")}"
|
26
|
+
trail.delete
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def indexable
|
33
|
+
@indexable ||= indexable_class.where(:_id => self.doc_id).first
|
34
|
+
end
|
35
|
+
|
36
|
+
def indexable_class
|
37
|
+
self.doc_type.constantize
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
def with_xapian_database(&block)
|
42
|
+
return if indexable_class.nil?
|
43
|
+
|
44
|
+
xapian_db = indexable_class.xapian_db(self.language)
|
45
|
+
block.call(xapian_db)
|
46
|
+
xapian_db.flush
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_document
|
50
|
+
with_xapian_database do |db|
|
51
|
+
xapian_doc = db.add_doc(indexable.to_xapian)
|
52
|
+
indexable.set(:xapian_id, xapian_doc.id)
|
53
|
+
indexable.xapian_id = xapian_doc.id
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def update_document
|
58
|
+
with_xapian_database do |db|
|
59
|
+
if indexable.xapian_id.to_i > 0
|
60
|
+
xapian_doc = XapianFu::XapianDoc.new(indexable.to_xapian.merge(:id => indexable.xapian_id), :xapian_db => db)
|
61
|
+
xapian_doc.save
|
62
|
+
else
|
63
|
+
xapian_doc = db.add_doc(indexable.to_xapian)
|
64
|
+
indexable.set(:xapian_id, xapian_doc.id)
|
65
|
+
indexable.xapian_id = xapian_doc.id
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def destroy_document
|
71
|
+
with_xapian_database do |db|
|
72
|
+
if self.doc_id.to_i > 0
|
73
|
+
db.documents.delete(self.doc_id)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "mongoid-xapian"
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["David A. Cuadrado"]
|
12
|
+
s.date = "2012-08-05"
|
13
|
+
s.description = "Full text search for mongoid using xapian"
|
14
|
+
s.email = "krawek@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/mongoid-xapian.rb",
|
29
|
+
"lib/mongoid-xapian/indexer.rb",
|
30
|
+
"lib/mongoid-xapian/tasks.rb",
|
31
|
+
"lib/mongoid-xapian/trail.rb",
|
32
|
+
"mongoid-xapian.gemspec",
|
33
|
+
"spec/models/blog_post.rb",
|
34
|
+
"spec/mongoid-xapian_spec.rb",
|
35
|
+
"spec/mongoid.yml",
|
36
|
+
"spec/spec_helper.rb"
|
37
|
+
]
|
38
|
+
s.homepage = "http://github.com/dcu/mongoid-xapian"
|
39
|
+
s.licenses = ["MIT"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = "1.8.24"
|
42
|
+
s.summary = "FTS for mongoid using xapian"
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<mongoid>, [">= 0"])
|
49
|
+
s.add_runtime_dependency(%q<xapian-ruby>, [">= 0"])
|
50
|
+
s.add_runtime_dependency(%q<xapian-fu>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<pry>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
53
|
+
s.add_development_dependency(%q<yard>, ["~> 0.7"])
|
54
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
55
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
57
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<mongoid>, [">= 0"])
|
60
|
+
s.add_dependency(%q<xapian-ruby>, [">= 0"])
|
61
|
+
s.add_dependency(%q<xapian-fu>, [">= 0"])
|
62
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
63
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
64
|
+
s.add_dependency(%q<yard>, ["~> 0.7"])
|
65
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
66
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
67
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
68
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
69
|
+
end
|
70
|
+
else
|
71
|
+
s.add_dependency(%q<mongoid>, [">= 0"])
|
72
|
+
s.add_dependency(%q<xapian-ruby>, [">= 0"])
|
73
|
+
s.add_dependency(%q<xapian-fu>, [">= 0"])
|
74
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
75
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
76
|
+
s.add_dependency(%q<yard>, ["~> 0.7"])
|
77
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
78
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
79
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
80
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "MongoidXapian" do
|
4
|
+
after(:all) do
|
5
|
+
BlogPost.destroy_all
|
6
|
+
MongoidXapian.index!
|
7
|
+
MongoidXapian::Trail.destroy_all
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "Indexing documents" do
|
11
|
+
it "should index the document" do
|
12
|
+
blogpost = BlogPost.create(:title => "this is the title", :body => "this is body")
|
13
|
+
MongoidXapian.index!
|
14
|
+
BlogPost.search("the title").size.should >= 1
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should work well concurrently" do
|
18
|
+
10.times do
|
19
|
+
Thread.start do
|
20
|
+
blogpost = BlogPost.create!(:title => "this is the title", :body => "this is body")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# wait until all docs are created
|
25
|
+
while BlogPost.count < 10
|
26
|
+
sleep 0.1
|
27
|
+
end
|
28
|
+
MongoidXapian.index!
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "Updating documents" do
|
33
|
+
before do
|
34
|
+
@blogpost = BlogPost.create(:title => "this is the title", :body => "this is body")
|
35
|
+
MongoidXapian.index!
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should update the index" do
|
39
|
+
rand_string = rand(100000)
|
40
|
+
@blogpost.title = "new title #{rand_string}"
|
41
|
+
@blogpost.save
|
42
|
+
MongoidXapian.index!
|
43
|
+
|
44
|
+
results = BlogPost.search(rand_string)
|
45
|
+
results.size.should >= 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "Destroying documents" do
|
50
|
+
before do
|
51
|
+
@blogpost = BlogPost.create(:title => "an unique title", :body => "this is body")
|
52
|
+
MongoidXapian.index!
|
53
|
+
@blogpost.reload
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should delete the record from xapian" do
|
57
|
+
BlogPost.search("unique").count.should == 1
|
58
|
+
@blogpost.destroy
|
59
|
+
MongoidXapian.index!
|
60
|
+
|
61
|
+
BlogPost.search("unique").count.should == 0
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/mongoid.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
test:
|
2
|
+
sessions:
|
3
|
+
default:
|
4
|
+
hosts:
|
5
|
+
- localhost:27017
|
6
|
+
database: mongoidext-test
|
7
|
+
options:
|
8
|
+
safe: true
|
9
|
+
options:
|
10
|
+
allow_dynamic_fields: false
|
11
|
+
identity_map_enabled: true
|
12
|
+
include_root_in_json: false
|
13
|
+
include_type_for_serialization: true
|
14
|
+
preload_models: false
|
15
|
+
scope_overwrite_exception: true
|
16
|
+
raise_not_found_error: false
|
17
|
+
skip_version_check: false
|
18
|
+
use_activesupport_time_zone: true
|
19
|
+
use_utc: true
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'mongoid-xapian'
|
5
|
+
require 'models/blog_post'
|
6
|
+
require 'pry'
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
Mongoid.load!("spec/mongoid.yml", "test")
|
11
|
+
|
12
|
+
# Requires supporting files with custom matchers and macros, etc,
|
13
|
+
# in ./support/ and its subdirectories.
|
14
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid-xapian
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- David A. Cuadrado
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mongoid
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: xapian-ruby
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: xapian-fu
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: pry
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.8.0
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 2.8.0
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: yard
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0.7'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0.7'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rdoc
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.12'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '3.12'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: bundler
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: jeweler
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ~>
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 1.8.4
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ~>
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: 1.8.4
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: simplecov
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
description: Full text search for mongoid using xapian
|
175
|
+
email: krawek@gmail.com
|
176
|
+
executables: []
|
177
|
+
extensions: []
|
178
|
+
extra_rdoc_files:
|
179
|
+
- LICENSE.txt
|
180
|
+
- README.md
|
181
|
+
files:
|
182
|
+
- .document
|
183
|
+
- .rspec
|
184
|
+
- Gemfile
|
185
|
+
- Gemfile.lock
|
186
|
+
- LICENSE.txt
|
187
|
+
- README.md
|
188
|
+
- Rakefile
|
189
|
+
- VERSION
|
190
|
+
- lib/mongoid-xapian.rb
|
191
|
+
- lib/mongoid-xapian/indexer.rb
|
192
|
+
- lib/mongoid-xapian/tasks.rb
|
193
|
+
- lib/mongoid-xapian/trail.rb
|
194
|
+
- mongoid-xapian.gemspec
|
195
|
+
- spec/models/blog_post.rb
|
196
|
+
- spec/mongoid-xapian_spec.rb
|
197
|
+
- spec/mongoid.yml
|
198
|
+
- spec/spec_helper.rb
|
199
|
+
homepage: http://github.com/dcu/mongoid-xapian
|
200
|
+
licenses:
|
201
|
+
- MIT
|
202
|
+
post_install_message:
|
203
|
+
rdoc_options: []
|
204
|
+
require_paths:
|
205
|
+
- lib
|
206
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
207
|
+
none: false
|
208
|
+
requirements:
|
209
|
+
- - ! '>='
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
version: '0'
|
212
|
+
segments:
|
213
|
+
- 0
|
214
|
+
hash: -1310551950771285356
|
215
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
216
|
+
none: false
|
217
|
+
requirements:
|
218
|
+
- - ! '>='
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
version: '0'
|
221
|
+
requirements: []
|
222
|
+
rubyforge_project:
|
223
|
+
rubygems_version: 1.8.24
|
224
|
+
signing_key:
|
225
|
+
specification_version: 3
|
226
|
+
summary: FTS for mongoid using xapian
|
227
|
+
test_files: []
|