xapor 0.0.0
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/.document +5 -0
- data/.gitignore +24 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +59 -0
- data/VERSION +1 -0
- data/features/step_definitions/xapor_steps.rb +48 -0
- data/features/support/env.rb +4 -0
- data/features/xapor.feature +17 -0
- data/init.rb +1 -0
- data/lib/xapor/config.rb +28 -0
- data/lib/xapor/model_integration.rb +54 -0
- data/lib/xapor.rb +10 -0
- data/spec/lib/xapor/config_spec.rb +29 -0
- data/spec/lib/xapor/model_integration_spec.rb +36 -0
- data/spec/lib/xapor_spec.rb +2 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +14 -0
- metadata +136 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 David Workman
|
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.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= xapor
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 David Workman. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "xapor"
|
8
|
+
gem.summary = %Q{Rails plugin for Xapian search}
|
9
|
+
gem.description = %Q{Rails plugin for Xapian search, built on XapianFu and DelayedJob.}
|
10
|
+
gem.email = "workmad3@hedtek.com"
|
11
|
+
gem.homepage = "http://github.com/hedtekltd/xapor"
|
12
|
+
gem.authors = ["David Workman"]
|
13
|
+
gem.add_dependency "xapian-fu", ">= 1.1.0"
|
14
|
+
gem.add_dependency "delayed_job", ">= 2.0.3"
|
15
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
16
|
+
gem.add_development_dependency "cucumber", ">= 0"
|
17
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
+
end
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
rescue LoadError
|
21
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'spec/rake/spectask'
|
25
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
26
|
+
spec.libs << 'lib' << 'spec'
|
27
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
28
|
+
end
|
29
|
+
|
30
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
31
|
+
spec.libs << 'lib' << 'spec'
|
32
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
+
spec.rcov = true
|
34
|
+
end
|
35
|
+
|
36
|
+
task :spec => :check_dependencies
|
37
|
+
|
38
|
+
begin
|
39
|
+
require 'cucumber/rake/task'
|
40
|
+
Cucumber::Rake::Task.new(:features)
|
41
|
+
|
42
|
+
task :features => :check_dependencies
|
43
|
+
rescue LoadError
|
44
|
+
task :features do
|
45
|
+
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
task :default => :spec
|
50
|
+
|
51
|
+
require 'rake/rdoctask'
|
52
|
+
Rake::RDocTask.new do |rdoc|
|
53
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
54
|
+
|
55
|
+
rdoc.rdoc_dir = 'rdoc'
|
56
|
+
rdoc.title = "xapor #{version}"
|
57
|
+
rdoc.rdoc_files.include('README*')
|
58
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
59
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class XaporTest
|
2
|
+
|
3
|
+
end
|
4
|
+
|
5
|
+
Given /^I have a model object with "([^\"]*)"$/ do |field|
|
6
|
+
XaporTest.send(:attr_accessor, field.to_sym)
|
7
|
+
XaporTest.new.respond_to?(field.to_sym).should be_true
|
8
|
+
XaporTest.new.respond_to?(:"#{field}=").should be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
When /^I call xapor to index "([^\"]*)"$/ do |field|
|
12
|
+
XaporTest.send(:include, Xapor::ModelIntegration)
|
13
|
+
XaporTest.send(:xapor) do |index|
|
14
|
+
index.search field.to_sym
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Then /^I should have a "([^\"]*)" function$/ do |func_name|
|
19
|
+
@test = XaporTest.new
|
20
|
+
@test.respond_to?(func_name.to_sym).should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
Then /^I should have a "([^\"]*)" class function$/ do |func_name|
|
24
|
+
XaporTest.respond_to?(func_name.to_sym).should be_true
|
25
|
+
end
|
26
|
+
|
27
|
+
Given /^I have a xapor model object with a name$/ do
|
28
|
+
XaporTest.send(:attr_accessor, :name)
|
29
|
+
XaporTest.send(:include, Xapor::ModelIntegration)
|
30
|
+
XaporTest.send(:xapor) do |index|
|
31
|
+
index.search :name
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
When /^I have a xapor model with name "([^\"]*)"$/ do |name|
|
36
|
+
model = XaporTest.new
|
37
|
+
model.name = name
|
38
|
+
if !@models
|
39
|
+
@models = []
|
40
|
+
end
|
41
|
+
@models << model
|
42
|
+
end
|
43
|
+
When /^I search the model for "([^\"]*)"$/ do |query|
|
44
|
+
@search_results = XaporTest.search(query)
|
45
|
+
end
|
46
|
+
Then /^I should get 1 result$/ do
|
47
|
+
@search_results.size.should == 1
|
48
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Feature:
|
2
|
+
In order to search models
|
3
|
+
I need to add search functionality to a model with xapor
|
4
|
+
|
5
|
+
Scenario: Adding xapor searching to an object
|
6
|
+
Given I have a model object with "name"
|
7
|
+
When I call xapor to index "name"
|
8
|
+
Then I should have a "search" class function
|
9
|
+
And I should have a "search_by_name" class function
|
10
|
+
|
11
|
+
Scenario: Searching with xapor
|
12
|
+
Given I have a xapor model object with a name
|
13
|
+
And I have a xapor model with name "Testing"
|
14
|
+
And I have a xapor model with name "Awesome"
|
15
|
+
When I search the model for "Testing"
|
16
|
+
Then I should get 1 result
|
17
|
+
And I should have a result with name "Testing"
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'xapor'
|
data/lib/xapor/config.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class Xapor::Config
|
2
|
+
attr_reader :search_fields
|
3
|
+
attr_reader :store_fields
|
4
|
+
attr_reader :directory_config
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@search_fields = []
|
8
|
+
@store_fields = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def search(field, options = {})
|
12
|
+
@search_fields << field
|
13
|
+
if options[:store]
|
14
|
+
@store_fields << field
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def directory(path)
|
19
|
+
@directory_config = path
|
20
|
+
end
|
21
|
+
|
22
|
+
def xapian_fu_db
|
23
|
+
db_settings = {}
|
24
|
+
db_settings[:dir] = @directory_config if @directory_config
|
25
|
+
db_settings[:store] = @store_fields unless @store_fields.empty?
|
26
|
+
return db_settings
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Xapor::ModelIntegration
|
2
|
+
def self.included(base)
|
3
|
+
base.send(:include, Xapor::XapianFuIntegration)
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
module Xapor::XapianFuIntegration
|
8
|
+
include XapianFu
|
9
|
+
def self.included(base)
|
10
|
+
base.extend ClassMethods
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def xapor
|
15
|
+
class << self
|
16
|
+
include XapianFu
|
17
|
+
|
18
|
+
def search(query)
|
19
|
+
db = XapianDb.new(@config.xapian_fu_db)
|
20
|
+
db.search(query)
|
21
|
+
end
|
22
|
+
|
23
|
+
def xapor_config
|
24
|
+
@config
|
25
|
+
end
|
26
|
+
end
|
27
|
+
@config = Xapor::Config.new
|
28
|
+
if block_given?
|
29
|
+
yield @config
|
30
|
+
end
|
31
|
+
@config.search_fields.each do |field|
|
32
|
+
class_eval("def self.search_by_#{field}(query)\nself.search(query)\nend")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def perform
|
38
|
+
config = self.class.xapor_config
|
39
|
+
db = XapianDb.new(config.xapian_fu_db.merge(:create => true))
|
40
|
+
doc = {:id => self.id}
|
41
|
+
config.search_fields.each do |field|
|
42
|
+
doc[field] = self.send(field.to_sym)
|
43
|
+
end
|
44
|
+
db << doc
|
45
|
+
db.flush
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_to_index
|
49
|
+
Delayed::Job.enqueue self
|
50
|
+
Thread.new do
|
51
|
+
Delayed::Worker.new.start
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/xapor.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Xapor::Config, "Configuration settings for a Xapor index" do
|
4
|
+
it "should allow specification of search fields" do
|
5
|
+
config = Xapor::Config.new
|
6
|
+
config.respond_to?(:search).should be_true
|
7
|
+
config.search :test
|
8
|
+
config.search_fields.should == [:test]
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should allow specification of the index location" do
|
12
|
+
config = Xapor::Config.new
|
13
|
+
config.respond_to?(:directory).should be_true
|
14
|
+
config.directory "test/path.db"
|
15
|
+
config.directory_config.should == "test/path.db"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should let you specify if you want to store a field" do
|
19
|
+
config = Xapor::Config.new
|
20
|
+
config.search :test, :store => true
|
21
|
+
config.store_fields.should == [:test]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should provide XapianFu config settings" do
|
25
|
+
config = Xapor::Config.new
|
26
|
+
config.directory "test/path.db"
|
27
|
+
config.xapian_fu_db.should == {:dir => "test/path.db"}
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Xapor::ModelIntegration, "Search integration into a model class" do
|
4
|
+
it "should add a xapor function when included" do
|
5
|
+
XaporTest.respond_to?(:xapor).should be_false
|
6
|
+
XaporTest.send(:include, Xapor::ModelIntegration)
|
7
|
+
XaporTest.respond_to?(:xapor).should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should add a search function when xapor is called" do
|
11
|
+
XaporTest.send(:include, Xapor::ModelIntegration)
|
12
|
+
XaporTest.send(:xapor)
|
13
|
+
XaporTest.respond_to?(:search).should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should add a search_by_name function when xapor is called with a block that indexes the name" do
|
17
|
+
XaporTest.send(:attr_accessor, :name)
|
18
|
+
XaporTest.send(:include, Xapor::ModelIntegration)
|
19
|
+
XaporTest.send(:xapor) {|idx| idx.search :name}
|
20
|
+
XaporTest.respond_to?(:search_by_name).should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "add a perform method for delayed job" do
|
24
|
+
XaporTest.send(:attr_accessor, :name)
|
25
|
+
XaporTest.send(:include, Xapor::ModelIntegration)
|
26
|
+
XaporTest.send(:xapor) {|idx|
|
27
|
+
idx.search :name
|
28
|
+
idx.directory "test.db"
|
29
|
+
}
|
30
|
+
XaporTest.new.respond_to?(:perform).should be_true
|
31
|
+
test = XaporTest.new
|
32
|
+
test.should_receive(:id).and_return(1)
|
33
|
+
test.should_receive(:name).and_return("Awesome")
|
34
|
+
test.perform
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'xapor'
|
4
|
+
require 'spec'
|
5
|
+
require 'spec/autorun'
|
6
|
+
|
7
|
+
Spec::Runner.configure do |config|
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
# An empty class to be used for hooking on the Xapor spec functionality
|
12
|
+
class XaporTest
|
13
|
+
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xapor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 0.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- David Workman
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-20 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: xapian-fu
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
version: 1.1.0
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: delayed_job
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 0
|
44
|
+
- 3
|
45
|
+
version: 2.0.3
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rspec
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 2
|
58
|
+
- 9
|
59
|
+
version: 1.2.9
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: cucumber
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
type: :development
|
73
|
+
version_requirements: *id004
|
74
|
+
description: Rails plugin for Xapian search, built on XapianFu and DelayedJob.
|
75
|
+
email: workmad3@hedtek.com
|
76
|
+
executables: []
|
77
|
+
|
78
|
+
extensions: []
|
79
|
+
|
80
|
+
extra_rdoc_files:
|
81
|
+
- LICENSE
|
82
|
+
- README.rdoc
|
83
|
+
files:
|
84
|
+
- .document
|
85
|
+
- .gitignore
|
86
|
+
- LICENSE
|
87
|
+
- README.rdoc
|
88
|
+
- Rakefile
|
89
|
+
- VERSION
|
90
|
+
- features/step_definitions/xapor_steps.rb
|
91
|
+
- features/support/env.rb
|
92
|
+
- features/xapor.feature
|
93
|
+
- init.rb
|
94
|
+
- lib/xapor.rb
|
95
|
+
- lib/xapor/config.rb
|
96
|
+
- lib/xapor/model_integration.rb
|
97
|
+
- spec/lib/xapor/config_spec.rb
|
98
|
+
- spec/lib/xapor/model_integration_spec.rb
|
99
|
+
- spec/lib/xapor_spec.rb
|
100
|
+
- spec/spec.opts
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
has_rdoc: true
|
103
|
+
homepage: http://github.com/hedtekltd/xapor
|
104
|
+
licenses: []
|
105
|
+
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options:
|
108
|
+
- --charset=UTF-8
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
version: "0"
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
requirements: []
|
126
|
+
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 1.3.6
|
129
|
+
signing_key:
|
130
|
+
specification_version: 3
|
131
|
+
summary: Rails plugin for Xapian search
|
132
|
+
test_files:
|
133
|
+
- spec/lib/xapor/config_spec.rb
|
134
|
+
- spec/lib/xapor/model_integration_spec.rb
|
135
|
+
- spec/lib/xapor_spec.rb
|
136
|
+
- spec/spec_helper.rb
|