sunspot_mongo 1.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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sunspot_mongo.gemspec
4
+ 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.rdoc ADDED
@@ -0,0 +1,55 @@
1
+ == Installation
2
+
3
+ === Mongo Mapper
4
+
5
+ Put the following in your Gemfile:
6
+
7
+ gem 'bson_ext'
8
+ gem 'mongo_mapper'
9
+ gem 'sunspot_mongo'
10
+
11
+ Then run:
12
+
13
+ rails g mongo_mapper:config
14
+ rails g sunspot_rails:install
15
+ rake sunspot:solr:start
16
+
17
+ === Mongoid
18
+
19
+ gem 'bson_ext'
20
+ gem 'mongoid'
21
+ gem 'sunspot_mongo'
22
+
23
+ Then run:
24
+
25
+ rails g mongoid:config
26
+ rails g sunspot_rails:install
27
+ rake sunspot:solr:start
28
+
29
+ == Usage
30
+
31
+ Add the following to your model (assuming you have a string field named "content"):
32
+
33
+ include Sunspot::Mongo
34
+ searchable do
35
+ text :content
36
+ end
37
+
38
+ Then search like usual:
39
+
40
+ search = Article.search do
41
+ fulltext "something interesting"
42
+ end
43
+ search.results
44
+
45
+ == More info
46
+
47
+ See the {Sunspot documentation}[http://outoftime.github.com/sunspot/].
48
+
49
+ == Compatibility
50
+
51
+ This gem has been tested against Ruby 1.9.2 and Rails 3.1, although it should work with older versions.
52
+
53
+ == Credit
54
+
55
+ Based on {sunspot_mongoid}[https://github.com/jugyo/sunspot_mongoid] by jugyo.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,30 @@
1
+ require 'sunspot'
2
+ require 'sunspot/rails'
3
+
4
+ module Sunspot
5
+ module Mongo
6
+ def self.included(base)
7
+ base.class_eval do
8
+ extend Sunspot::Rails::Searchable::ActsAsMethods
9
+ Sunspot::Adapters::DataAccessor.register(DataAccessor, base)
10
+ Sunspot::Adapters::InstanceAdapter.register(InstanceAdapter, base)
11
+ end
12
+ end
13
+
14
+ class InstanceAdapter < Sunspot::Adapters::InstanceAdapter
15
+ def id
16
+ @instance.id
17
+ end
18
+ end
19
+
20
+ class DataAccessor < Sunspot::Adapters::DataAccessor
21
+ def load(id)
22
+ @clazz.find(BSON::ObjectID.from_string(id)) rescue nil
23
+ end
24
+
25
+ def load_all(ids)
26
+ @clazz.where(:_id.in => ids.map { |id| BSON::ObjectId.from_string(id) })
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module Sunspot
2
+ module Mongo
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require "sunspot_rails"
2
+ require "sunspot/mongo"
3
+ require "sunspot/mongo/version"
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require "rails"
3
+ require "sunspot_mongo"
4
+
5
+ require "mongo_mapper"
6
+ require "mongoid"
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ class MongoMapperTestDocument
4
+ include MongoMapper::Document
5
+ key :title, String
6
+
7
+ include Sunspot::Mongo
8
+ searchable do
9
+ text :title
10
+ end
11
+ end
12
+
13
+ class MongoidTestDocument
14
+ include Mongoid::Document
15
+ field :title
16
+
17
+ include Sunspot::Mongo
18
+ searchable do
19
+ text :title
20
+ end
21
+ end
22
+
23
+ class MongoMapperTestDocumentWithOptions
24
+ include MongoMapper::Document
25
+ key :title, String
26
+
27
+ include Sunspot::Mongo
28
+ searchable(:auto_index => false, :auto_remove => false) do
29
+ text :title
30
+ end
31
+ end
32
+
33
+ shared_examples "a mongo document" do
34
+ it "should call Sunspot.setup when searchable is called" do
35
+ Sunspot.should_receive(:setup).once.with(described_class)
36
+ described_class.searchable
37
+ end
38
+
39
+ it "should search" do
40
+ options = {}
41
+ Sunspot.should_receive(:new_search).once.and_return(double("search", :execute => nil))
42
+ MongoMapperTestDocument.search(options)
43
+ end
44
+ end
45
+
46
+ describe MongoMapperTestDocument do
47
+ it_behaves_like "a mongo document"
48
+ end
49
+
50
+ describe MongoidTestDocument do
51
+ it_behaves_like "a mongo document"
52
+ end
53
+
54
+ describe "test documents with options" do
55
+ it "should set sunspot_options" do
56
+ MongoidTestDocument.sunspot_options.should == {:include => []}
57
+ MongoMapperTestDocumentWithOptions.sunspot_options.should == {:auto_index=>false, :auto_remove=>false, :include=>[]}
58
+ end
59
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sunspot/mongo/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sunspot_mongo"
7
+ s.version = Sunspot::Mongo::VERSION
8
+ s.authors = ["Brian Alexander"]
9
+ s.email = ["balexand@gmail.com"]
10
+ s.homepage = "https://github.com/balexand/sunspot_mongo"
11
+ s.summary = %q{Sunspot search for both MongoDB. Supports Mongo Mapper and Mongoid.}
12
+ s.description = %q{Sunspot search for both MongoDB. Supports Mongo Mapper and Mongoid.}
13
+
14
+ s.rubyforge_project = "sunspot_mongo"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "sunspot_rails", [">= 0"]
22
+
23
+ s.add_development_dependency "bson_ext", [">= 0"]
24
+ s.add_development_dependency "mongo_mapper", [">= 0"]
25
+ s.add_development_dependency "mongoid", [">= 0"]
26
+ s.add_development_dependency "rails", [">= 0"]
27
+ s.add_development_dependency "rspec", [">= 0"]
28
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sunspot_mongo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brian Alexander
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-11 00:00:00.000000000 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sunspot_rails
17
+ requirement: &70272339071280 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70272339071280
26
+ - !ruby/object:Gem::Dependency
27
+ name: bson_ext
28
+ requirement: &70272339070760 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *70272339070760
37
+ - !ruby/object:Gem::Dependency
38
+ name: mongo_mapper
39
+ requirement: &70272339070280 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *70272339070280
48
+ - !ruby/object:Gem::Dependency
49
+ name: mongoid
50
+ requirement: &70272339069760 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *70272339069760
59
+ - !ruby/object:Gem::Dependency
60
+ name: rails
61
+ requirement: &70272339069280 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *70272339069280
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: &70272339068760 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *70272339068760
81
+ description: Sunspot search for both MongoDB. Supports Mongo Mapper and Mongoid.
82
+ email:
83
+ - balexand@gmail.com
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files: []
87
+ files:
88
+ - .gitignore
89
+ - Gemfile
90
+ - LICENSE
91
+ - README.rdoc
92
+ - Rakefile
93
+ - lib/sunspot/mongo.rb
94
+ - lib/sunspot/mongo/version.rb
95
+ - lib/sunspot_mongo.rb
96
+ - spec/spec_helper.rb
97
+ - spec/sunspot_mongoid_spec.rb
98
+ - sunspot_mongo.gemspec
99
+ has_rdoc: true
100
+ homepage: https://github.com/balexand/sunspot_mongo
101
+ licenses: []
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project: sunspot_mongo
120
+ rubygems_version: 1.6.2
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: Sunspot search for both MongoDB. Supports Mongo Mapper and Mongoid.
124
+ test_files:
125
+ - spec/spec_helper.rb
126
+ - spec/sunspot_mongoid_spec.rb