sunspot_mongoid 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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ *.gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 jugyo
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,50 @@
1
+ sunspot_mongoid
2
+ ====
3
+
4
+ A Sunspot wrapper for Mongoid.
5
+
6
+ See also: [http://github.com/outoftime/sunspot/tree/master/sunspot_rails/](http://github.com/outoftime/sunspot/tree/master/sunspot_rails/)
7
+
8
+ Example
9
+ ----
10
+
11
+ require 'sunspot_mongoid'
12
+
13
+ Mongoid.configure do |config|
14
+ config.master = Mongo::Connection.new.db('sunspot-mongoid-test')
15
+ end
16
+
17
+ # model
18
+ class Post
19
+ include Mongoid::Document
20
+ field :title
21
+
22
+ include Sunspot::Mongoid
23
+ sunspot_setup do
24
+ text :title
25
+ end
26
+ end
27
+
28
+ # indexing
29
+ Post.create(:title => 'foo')
30
+ Post.create(:title => 'foo bar')
31
+ Post.create(:title => 'bar baz')
32
+
33
+ # commit
34
+ Sunspot.commit
35
+
36
+ # search
37
+ search = Post.search do
38
+ keywords 'foo'
39
+ end
40
+ search.each_hit_with_result do |hit, post|
41
+ p post
42
+ end
43
+
44
+ #=> #<Post _id: 4c319556327b3c4b42000001, title: "foo">
45
+ #=> #<Post _id: 4c319556327b3c4b42000002, title: "foo bar">
46
+
47
+ Copyright
48
+ ----
49
+
50
+ Copyright (c) 2010 jugyo. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "sunspot_mongoid"
8
+ gem.summary = %Q{A Sunspot wrapper for Mongoid.}
9
+ gem.description = %Q{A Sunspot wrapper for Mongoid that is like sunspot_rails.}
10
+ gem.email = "jugyo.org@gmail.com"
11
+ gem.homepage = "http://github.com/jugyo/sunspot_mongoid"
12
+ gem.authors = ["jugyo"]
13
+ gem.add_runtime_dependency "mongoid", ">= 0"
14
+ gem.add_runtime_dependency "sunspot", ">= 1.1.0"
15
+ gem.add_runtime_dependency "sunspot_rails", ">= 1.1.0"
16
+ gem.add_development_dependency "shoulda", ">= 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 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "sunspot_mongoid #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,36 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'sunspot_mongoid'
3
+
4
+ Mongoid.configure do |config|
5
+ config.master = Mongo::Connection.new.db('sunspot-mongoid-test')
6
+ end
7
+
8
+ # model
9
+ class Post
10
+ include Mongoid::Document
11
+ field :title
12
+
13
+ include Sunspot::Mongoid
14
+ sunspot_setup do
15
+ text :title
16
+ end
17
+ end
18
+
19
+ # remove old indexes
20
+ Post.destroy_all
21
+
22
+ # indexing
23
+ Post.create(:title => 'foo')
24
+ Post.create(:title => 'foo bar')
25
+ Post.create(:title => 'bar baz')
26
+
27
+ # commit
28
+ Sunspot.commit
29
+
30
+ # search
31
+ search = Post.search do
32
+ keywords 'foo'
33
+ end
34
+ search.each_hit_with_result do |hit, post|
35
+ p post
36
+ end
data/examples/test.rb ADDED
@@ -0,0 +1,35 @@
1
+ require 'sunspot_mongoid'
2
+
3
+ Mongoid.configure do |config|
4
+ config.master = Mongo::Connection.new.db('sunspot-mongoid-test')
5
+ end
6
+
7
+ # model
8
+ class Post
9
+ include Mongoid::Document
10
+ field :title
11
+
12
+ include Sunspot::Mongoid
13
+ sunspot_setup do
14
+ text :title
15
+ end
16
+ end
17
+
18
+ # remove old indexes
19
+ Post.destroy_all
20
+
21
+ # indexing
22
+ Post.create(:title => 'foo')
23
+ Post.create(:title => 'foo bar')
24
+ Post.create(:title => 'bar baz')
25
+
26
+ # commit
27
+ Sunspot.commit
28
+
29
+ # search
30
+ search = Post.search do
31
+ keywords 'foo'
32
+ end
33
+ search.each_hit_with_result do |hit, post|
34
+ p post
35
+ end
@@ -0,0 +1,56 @@
1
+ require 'mongoid'
2
+ require 'sunspot/rails/searchable'
3
+
4
+ # This code is modified for mongoid from the follow,
5
+ # http://github.com/outoftime/sunspot/blob/master/sunspot_rails/lib/sunspot/rails/searchable.rb
6
+ #
7
+ # Sunspot::Rails is distributed under the MIT License, copyright © 2009 Mat Brown
8
+ module Sunspot
9
+ module Mongoid
10
+ def self.included(base)
11
+ base.class_eval do
12
+ Sunspot::Adapters::DataAccessor.register(DataAccessor, base)
13
+ Sunspot::Adapters::InstanceAdapter.register(InstanceAdapter, base)
14
+
15
+ extend Sunspot::Rails::Searchable::ClassMethods
16
+ include Sunspot::Rails::Searchable::InstanceMethods
17
+
18
+ def self.sunspot_setup(options = {}, &block)
19
+ Sunspot.setup(self, &block)
20
+
21
+ class_inheritable_hash :sunspot_options
22
+
23
+ unless options[:auto_index] == false
24
+ before_save :maybe_mark_for_auto_indexing
25
+ after_save :maybe_auto_index
26
+ end
27
+
28
+ unless options[:auto_remove] == false
29
+ after_destroy do |searchable|
30
+ searchable.remove_from_index
31
+ end
32
+ end
33
+ options[:include] = Sunspot::Util::Array(options[:include])
34
+
35
+ self.sunspot_options = options
36
+ end
37
+ end
38
+ end
39
+
40
+ class InstanceAdapter < Sunspot::Adapters::InstanceAdapter
41
+ def id
42
+ @instance.id
43
+ end
44
+ end
45
+
46
+ class DataAccessor < Sunspot::Adapters::DataAccessor
47
+ def load(id)
48
+ @clazz.find(id) rescue nil
49
+ end
50
+
51
+ def load_all(ids)
52
+ @clazz.criteria.in(:_id => ids)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,2 @@
1
+ require 'sunspot'
2
+ require 'sunspot/mongoid'
data/rails/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ Sunspot.session = Sunspot::Rails.build_session
2
+ ActionController::Base.module_eval { include(Sunspot::Rails::RequestLifecycle) }
data/test/helper.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'rr'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'sunspot_mongoid'
9
+
10
+ class Test::Unit::TestCase
11
+ include RR::Adapters::TestUnit
12
+ end
@@ -0,0 +1,51 @@
1
+ require 'helper'
2
+
3
+ #
4
+ # NOTE: I think tests are too few...
5
+ #
6
+ class TestSunspotMongoid < Test::Unit::TestCase
7
+ class Foo
8
+ include Mongoid::Document
9
+ field :title
10
+
11
+ include Sunspot::Mongoid
12
+ sunspot_setup do
13
+ text :title
14
+ end
15
+ end
16
+
17
+ class Bar
18
+ include Mongoid::Document
19
+ field :title
20
+
21
+ include Sunspot::Mongoid
22
+ sunspot_setup(:auto_index => false, :auto_remove => false) do
23
+ text :title
24
+ end
25
+ end
26
+
27
+ context 'default' do
28
+ should 'sunspot_options is specified' do
29
+ assert Foo.sunspot_options == {:include => []}
30
+ assert Bar.sunspot_options == {:auto_index=>false, :auto_remove=>false, :include=>[]}
31
+ end
32
+
33
+ should 'be called Sunspot.setup when call Foo.sunspot_setup' do
34
+ mock(Sunspot).setup(Foo)
35
+ Foo.sunspot_setup
36
+ end
37
+
38
+ should 'get as text_fields from Sunspot::Setup' do
39
+ text_field = Sunspot::Setup.for(Foo).all_text_fields.first
40
+ assert text_field.type == Sunspot::Type::TextType.instance
41
+ assert text_field.name == :title
42
+ end
43
+
44
+ should 'search' do
45
+ options = {}
46
+ mock.proxy(Foo).solr_execute_search(options)
47
+ mock(Sunspot).new_search(Foo) { mock(Object.new).execute }
48
+ Foo.search(options)
49
+ end
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sunspot_mongoid
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - jugyo
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-05 00:00:00 +09:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: mongoid
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: sunspot
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 1
41
+ - 1
42
+ - 0
43
+ version: 1.1.0
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: sunspot_rails
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 1
55
+ - 1
56
+ - 0
57
+ version: 1.1.0
58
+ type: :runtime
59
+ version_requirements: *id003
60
+ - !ruby/object:Gem::Dependency
61
+ name: shoulda
62
+ prerelease: false
63
+ requirement: &id004 !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ type: :development
71
+ version_requirements: *id004
72
+ description: A Sunspot wrapper for Mongoid that is like sunspot_rails.
73
+ email: jugyo.org@gmail.com
74
+ executables: []
75
+
76
+ extensions: []
77
+
78
+ extra_rdoc_files:
79
+ - LICENSE
80
+ - README.md
81
+ files:
82
+ - .document
83
+ - .gitignore
84
+ - LICENSE
85
+ - README.md
86
+ - Rakefile
87
+ - VERSION
88
+ - examples/example.rb
89
+ - lib/sunspot/mongoid.rb
90
+ - lib/sunspot_mongoid.rb
91
+ - rails/init.rb
92
+ - test/helper.rb
93
+ - test/test_sunspot_mongoid.rb
94
+ has_rdoc: true
95
+ homepage: http://github.com/jugyo/sunspot_mongoid
96
+ licenses: []
97
+
98
+ post_install_message:
99
+ rdoc_options:
100
+ - --charset=UTF-8
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ requirements: []
118
+
119
+ rubyforge_project:
120
+ rubygems_version: 1.3.6
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: A Sunspot wrapper for Mongoid.
124
+ test_files:
125
+ - test/helper.rb
126
+ - test/test_sunspot_mongoid.rb
127
+ - examples/example.rb
128
+ - examples/test.rb