sunspot_mongoid2 0.5.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 819da31a85723db82618fafa0c5e3afc5ae6b68d
4
+ data.tar.gz: 5f050e56fdd23c886619a327a887cd93498da183
5
+ SHA512:
6
+ metadata.gz: 73eb200b759b8bf2eb7e3dab39089e4b42ee125fa6fcc6a6007cf652f263c85bef6f7f5de61c9d30f2a16652e4d7af78f8131e6c9f5ffdc8b3219b44e85fae93
7
+ data.tar.gz: dbf935fb20c72b0582352d688fcde25a8ba7db4fc861fc32a63b1e3d1d8d840be2abef973efd89c5c49acb4999ef6885ffd0e9b88e1c7da9faef569252536e81
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
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,75 @@
1
+ sunspot_mongoid 2
2
+ ====
3
+
4
+ A Sunspot wrapper for Mongoid that just works.
5
+
6
+ Gemfile
7
+ ----
8
+ gem 'sunspot_mongoid2'
9
+ bundle install
10
+
11
+ For Rails 3.x
12
+ ----
13
+
14
+ ### Configure your gem
15
+
16
+ Create `config/initializers/sunspot_mongoid.rb`:
17
+
18
+ Sunspot.session = Sunspot::Rails.build_session
19
+ ActionController::Base.module_eval { include(Sunspot::Rails::RequestLifecycle) }
20
+
21
+ Don't forget to restart your rack server (or pow.cx)
22
+
23
+ ### as plugin (only if really needed):
24
+
25
+ add gems to Gemfile as following,
26
+
27
+ gem 'sunspot_mongoid2'
28
+ gem 'sunspot_rails'
29
+
30
+ and install `sunspot_mongoid` as rails plugin,
31
+
32
+ rails plugin install https://github.com/hlegius/sunspot_mongoid2.git
33
+
34
+
35
+ A Simple Example
36
+ ----
37
+
38
+ class Post
39
+ include Mongoid::Document
40
+ include Sunspot::Mongoid2
41
+
42
+ searchable do
43
+ text :title
44
+ end
45
+
46
+ field :title
47
+ end
48
+
49
+ class SomeController < ActionController::Base
50
+ def index
51
+ search = Sunspot.search(Post) do
52
+ fulltext params[:q]
53
+ end
54
+
55
+ @results = search.results
56
+ @total_lines = search.total
57
+ end
58
+ end
59
+
60
+ # http://yourapplication.dev/search?q=foobarbaz
61
+
62
+ Links
63
+ ----
64
+
65
+ * [sunspot](http://github.com/outoftime/sunspot)
66
+ * [sunspot_rails](http://github.com/outoftime/sunspot/tree/master/sunspot_rails/)
67
+
68
+
69
+
70
+ Copyright (and left)
71
+ ----
72
+
73
+ Copyright (c) 2010 jugyo. See LICENSE for details.
74
+
75
+ A lot of other contributions were made before I did.
data/Rakefile ADDED
@@ -0,0 +1,77 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "sunspot_mongoid2"
8
+ gem.version = '0.5.1.5'
9
+ gem.summary = %Q{A Sunspot wrapper for Mongoid 2 or newer.}
10
+ gem.description = %Q{A Sunspot wrapper for Mongoid that is like sunspot_rails.}
11
+ gem.email = "jugyo.org@gmail.com aq1018@gmail.com hlegius@gmail.com"
12
+ gem.homepage = "http://github.com/hlegius/sunspot_mongoid"
13
+ gem.authors = ["jugyo", "aq1018", 'hlegius']
14
+ gem.add_runtime_dependency "mongoid", ">= 0"
15
+ gem.add_runtime_dependency "sunspot", ">= 2"
16
+ gem.add_runtime_dependency "sunspot_rails", ">= 2"
17
+ gem.add_development_dependency "shoulda", ">= 0"
18
+ gem.add_development_dependency "rr", ">= 0"
19
+ gem.extra_rdoc_files = [
20
+ "LICENSE",
21
+ "README.md"
22
+ ]
23
+ gem.files = [
24
+ ".document",
25
+ "LICENSE",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "examples/example.rb",
30
+ "init.rb",
31
+ "lib/sunspot_mongoid2.rb",
32
+ "lib/sunspot/mongoid2.rb",
33
+ "lib/sunspot/mongoid2/railtie.rb",
34
+ "sunspot_mongoid2.gemspec",
35
+ "tasks/sunspot_mongoid2.rake",
36
+ "test/helper.rb",
37
+ "test/test_sunspot_mongoid.rb"
38
+ ]
39
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
40
+ end
41
+ Jeweler::GemcutterTasks.new
42
+ rescue LoadError
43
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
44
+ end
45
+
46
+ require 'rake/testtask'
47
+ Rake::TestTask.new(:test) do |test|
48
+ test.libs << 'lib' << 'test'
49
+ test.pattern = 'test/**/test_*.rb'
50
+ test.verbose = true
51
+ end
52
+
53
+ begin
54
+ require 'rcov/rcovtask'
55
+ Rcov::RcovTask.new do |test|
56
+ test.libs << 'test'
57
+ test.pattern = 'test/**/test_*.rb'
58
+ test.verbose = true
59
+ end
60
+ rescue LoadError
61
+ task :rcov do
62
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
63
+ end
64
+ end
65
+
66
+ task :test => :check_dependencies
67
+ task :default => :test
68
+
69
+ require 'rdoc/task'
70
+ Rake::RDocTask.new do |rdoc|
71
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
72
+
73
+ rdoc.rdoc_dir = 'rdoc'
74
+ rdoc.title = "sunspot_mongoid2 #{version}"
75
+ rdoc.rdoc_files.include('README*')
76
+ rdoc.rdoc_files.include('lib/**/*.rb')
77
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.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
+ searchable 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/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'sunspot_mongoid2'
2
+ Sunspot.session = Sunspot::Rails.build_session
3
+ ActionController::Base.module_eval { include(Sunspot::Rails::RequestLifecycle) }
@@ -0,0 +1,50 @@
1
+ require 'sunspot'
2
+ require 'mongoid'
3
+ require 'sunspot/rails'
4
+
5
+ module Sunspot
6
+ module Mongoid2
7
+ def self.included(base)
8
+ base.class_eval do
9
+ extend Sunspot::Rails::Searchable::ActsAsMethods
10
+ extend Sunspot::Mongoid2::ActsAsMethods
11
+ Sunspot::Adapters::DataAccessor.register(DataAccessor, base)
12
+ Sunspot::Adapters::InstanceAdapter.register(InstanceAdapter, base)
13
+ end
14
+ end
15
+
16
+ module ActsAsMethods
17
+ # ClassMethods isn't loaded until searchable is called so we need
18
+ # call it, then extend our own ClassMethods.
19
+ def searchable (opt = {}, &block)
20
+ super
21
+ extend ClassMethods
22
+ end
23
+ end
24
+
25
+ module ClassMethods
26
+ # The sunspot solr_index method is very dependent on ActiveRecord, so
27
+ # we'll change it to work more efficiently with Mongoid.
28
+ def solr_index(opt={})
29
+ Sunspot.index!(all)
30
+ end
31
+ end
32
+
33
+
34
+ class InstanceAdapter < Sunspot::Adapters::InstanceAdapter
35
+ def id
36
+ @instance.id
37
+ end
38
+ end
39
+
40
+ class DataAccessor < Sunspot::Adapters::DataAccessor
41
+ def load(id)
42
+ @clazz.find(::Moped::BSON::ObjectId.from_string(id)) rescue nil
43
+ end
44
+
45
+ def load_all(ids)
46
+ @clazz.where(:_id.in => ids.map { |id| ::Moped::BSON::ObjectId.from_string(id) })
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,10 @@
1
+ require 'sunspot/mongoid2'
2
+ require 'rails'
3
+
4
+ module Sunspot::Mongoid2
5
+ class Railtie < Rails::Railtie
6
+ rake_tasks do
7
+ load File.expand_path("../../../../tasks/sunspot_mongoid2.rake", __FILE__)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,2 @@
1
+ require 'sunspot/mongoid2'
2
+ require 'sunspot/mongoid2/railtie' if defined?(Rails)
@@ -0,0 +1,64 @@
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 = "sunspot_mongoid2"
8
+ s.version = "0.5.1.5"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["jugyo", "aq1018", "hlegius"]
12
+ s.date = "2013-05-27"
13
+ s.description = "A Sunspot wrapper for Mongoid that is like sunspot_rails."
14
+ s.email = "jugyo.org@gmail.com aq1018@gmail.com hlegius@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "LICENSE",
22
+ "README.md",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "examples/example.rb",
26
+ "init.rb",
27
+ "lib/sunspot/mongoid2.rb",
28
+ "lib/sunspot/mongoid2/railtie.rb",
29
+ "lib/sunspot_mongoid2.rb",
30
+ "sunspot_mongoid2.gemspec",
31
+ "tasks/sunspot_mongoid2.rake",
32
+ "test/helper.rb",
33
+ "test/test_sunspot_mongoid.rb"
34
+ ]
35
+ s.homepage = "http://github.com/hlegius/sunspot_mongoid"
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "2.0.3"
38
+ s.summary = "A Sunspot wrapper for Mongoid 2 or newer."
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 4
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<mongoid>, [">= 0"])
45
+ s.add_runtime_dependency(%q<sunspot>, [">= 2"])
46
+ s.add_runtime_dependency(%q<sunspot_rails>, [">= 2"])
47
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
48
+ s.add_development_dependency(%q<rr>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<mongoid>, [">= 0"])
51
+ s.add_dependency(%q<sunspot>, [">= 2"])
52
+ s.add_dependency(%q<sunspot_rails>, [">= 2"])
53
+ s.add_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_dependency(%q<rr>, [">= 0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<mongoid>, [">= 0"])
58
+ s.add_dependency(%q<sunspot>, [">= 2"])
59
+ s.add_dependency(%q<sunspot_rails>, [">= 2"])
60
+ s.add_dependency(%q<shoulda>, [">= 0"])
61
+ s.add_dependency(%q<rr>, [">= 0"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,43 @@
1
+ # auto load rails tasks
2
+ require 'sunspot/rails/tasks'
3
+
4
+ # hack to remove 'sunspot:reindex' task and add our own
5
+ Rake::TaskManager.class_eval do
6
+ def remove_task(task_name)
7
+ @tasks.delete(task_name.to_s)
8
+ end
9
+ end
10
+
11
+ Rake.application.remove_task('sunspot:reindex')
12
+
13
+ # override the tasks that depends on active record
14
+ namespace :sunspot do
15
+
16
+ desc "Reindex all solr models that are located in your application's models directory. (Batch size ignored)"
17
+ # This task depends on the standard Rails file naming \
18
+ # conventions, in that the file name matches the defined class name. \
19
+ # By default the indexing system works in batches of 50 records, you can \
20
+ # set your own value for this by using the batch_size argument. You can \
21
+ # also optionally define a list of models to separated by a forward slash '/'
22
+ #
23
+ # $ rake sunspot:reindex # reindex all models
24
+ # $ rake sunspot:reindex[1000] # reindex in batches of 1000
25
+ # $ rake sunspot:reindex[false] # reindex without batching
26
+ # $ rake sunspot:reindex[,Post] # reindex only the Post model
27
+ # $ rake sunspot:reindex[1000,Post] # reindex only the Post model in
28
+ # # batchs of 1000
29
+ # $ rake sunspot:reindex[,Post+Author] # reindex Post and Author model
30
+ task :reindex, [:batch_size, :models] => :environment do |t, args|
31
+ unless args[:models]
32
+ all_files = Dir.glob(Rails.root.join('app', 'models', '*.rb'))
33
+ all_models = all_files.map { |path| File.basename(path, '.rb').camelize.constantize }
34
+ sunspot_models = all_models.select { |m| m.respond_to?(:searchable?) and m.searchable? }
35
+ else
36
+ sunspot_models = args[:models].split('+').map{|m| m.constantize}
37
+ end
38
+ sunspot_models.each do |model|
39
+ puts "Re-indexing #{model.name}"
40
+ model.solr_reindex
41
+ end
42
+ end
43
+ end
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
+ searchable 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
+ searchable(: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.searchable' do
34
+ mock(Sunspot).setup(Foo)
35
+ Foo.searchable
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,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sunspot_mongoid2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.1.5
5
+ platform: ruby
6
+ authors:
7
+ - jugyo
8
+ - aq1018
9
+ - hlegius
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-05-27 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mongoid
17
+ requirement: !ruby/object:Gem::Requirement
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
+ requirements:
26
+ - - '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: sunspot
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '2'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '2'
43
+ - !ruby/object:Gem::Dependency
44
+ name: sunspot_rails
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '2'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '2'
57
+ - !ruby/object:Gem::Dependency
58
+ name: shoulda
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rr
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ description: A Sunspot wrapper for Mongoid that is like sunspot_rails.
86
+ email: jugyo.org@gmail.com aq1018@gmail.com hlegius@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files:
90
+ - LICENSE
91
+ - README.md
92
+ files:
93
+ - .document
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - VERSION
98
+ - examples/example.rb
99
+ - init.rb
100
+ - lib/sunspot/mongoid2.rb
101
+ - lib/sunspot/mongoid2/railtie.rb
102
+ - lib/sunspot_mongoid2.rb
103
+ - sunspot_mongoid2.gemspec
104
+ - tasks/sunspot_mongoid2.rake
105
+ - test/helper.rb
106
+ - test/test_sunspot_mongoid.rb
107
+ homepage: http://github.com/hlegius/sunspot_mongoid
108
+ licenses: []
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.0.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: A Sunspot wrapper for Mongoid 2 or newer.
130
+ test_files: []