sunspot_mongo-toothrot 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f5a756111a18e908df79222b13ce9c347f122eec
4
+ data.tar.gz: bbc79a31ede38e918b91276c242f68aad39f4924
5
+ SHA512:
6
+ metadata.gz: 5bf52cf510d470cb244bb916aeb45c0bb4fa8c24b62d6b0eeac168cc12df44ca8c4004bfbec8610c3437b68dfd5ec6b20bc8ba461b635dd8c896f5c547f73295
7
+ data.tar.gz: 7b3382f2626fccb0ffb567fdce72c25d95ea9c581ed378590911d67e12036aca2cb8a146292a4dba11f99027888e0649268a5ccb2221ebec5a8a1bfc196d6c65
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *.swp
6
+ *.pid
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
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
9
+
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.
@@ -0,0 +1,59 @@
1
+
2
+ == Installation
3
+
4
+ === Mongo Mapper
5
+
6
+ Put the following in your Gemfile:
7
+
8
+ gem 'bson_ext'
9
+ gem 'mongo_mapper'
10
+ gem 'sunspot_mongo'
11
+
12
+ Then run:
13
+
14
+ rails g mongo_mapper:config
15
+ rails g sunspot_rails:install
16
+ rake sunspot:solr:start
17
+
18
+ === Mongoid
19
+
20
+ gem 'bson_ext'
21
+ gem 'mongoid'
22
+ gem 'sunspot_mongo'
23
+
24
+ Then run:
25
+
26
+ rails g mongoid:config
27
+ rails g sunspot_rails:install
28
+ rake sunspot:solr:start
29
+
30
+ == Usage
31
+
32
+ Add the following to your model (assuming you have a string field named "content"):
33
+
34
+ include Sunspot::Mongo
35
+ searchable do
36
+ text :content
37
+ end
38
+
39
+ Then search like usual:
40
+
41
+ search = Article.search do
42
+ fulltext "something interesting"
43
+ end
44
+ search.results
45
+
46
+ Note: Mongoid adds Article.search, use Article.solr_search instead.
47
+
48
+ == More info
49
+
50
+ See the {Sunspot documentation}[http://sunspot.github.com/docs/index.html].
51
+
52
+ == Compatibility
53
+
54
+ This gem has been tested against Ruby 1.9.2 and Rails 3.1, although it should work with older versions.
55
+
56
+ == Credit
57
+
58
+ Based on {sunspot_mongoid}[https://github.com/jugyo/sunspot_mongoid] by jugyo.
59
+ Originally developed by {balexand}[https://github.com/balexand].
@@ -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,41 @@
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
+ attr_accessor :include
22
+
23
+ def initialize(clazz)
24
+ super(clazz)
25
+ @inherited_attributes = [:include]
26
+ end
27
+
28
+ def load(id)
29
+ @clazz.find(id)
30
+ end
31
+
32
+ def load_all(ids)
33
+ if @include.present?
34
+ @clazz.includes(@include).find(ids)
35
+ else
36
+ @clazz.find(ids)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,9 @@
1
+ module Sunspot
2
+ module Mongo
3
+ class Railtie < ::Rails::Railtie
4
+ rake_tasks do
5
+ load 'sunspot/mongo/tasks.rb'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ namespace :sunspot do
2
+ namespace :mongo do
3
+ desc "Reindex all models that include Sunspot::Mongo and are located in your application's models directory."
4
+ task :reindex, [:models] => :environment do |t, args|
5
+ sunspot_models = if args[:models]
6
+ args[:models].split('+').map{|m| m.constantize}
7
+ else
8
+ all_files = Dir.glob(Rails.root.join('app', 'models', '*.rb'))
9
+ all_models = all_files.map { |path| File.basename(path, '.rb').camelize.constantize }
10
+ all_models.select { |m| m.include?(Sunspot::Mongo) and m.searchable? }
11
+ end
12
+
13
+ sunspot_models.each do |model|
14
+ puts "reindexing #{model}"
15
+ model.all.each(&:index)
16
+ Sunspot.commit
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module Sunspot
2
+ module Mongo
3
+ VERSION = "1.1.0"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require "sunspot_rails"
2
+ require "sunspot/mongo"
3
+ require "sunspot/mongo/version"
4
+ require "sunspot/mongo/railtie"
@@ -0,0 +1,30 @@
1
+ require "rails"
2
+ require 'forwardable'
3
+ require 'sunspot/rails/spec_helper'
4
+ require "sunspot_mongo"
5
+ require "mongoid"
6
+
7
+ # Load support files
8
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb' ))].each {|f| require f}
9
+
10
+ def setup_servers_and_connections
11
+ FileUtils.mkdir_p '/tmp/sunspot_mongo_test/'
12
+
13
+ begin
14
+ socket = TCPSocket.new 'localhost', 8900
15
+ rescue Errno::ECONNREFUSED
16
+ @solr_pid = fork { `sunspot-solr start --log-file=/tmp/sunspot_mongo/solr.log --log-level=INFO --port=8900` }
17
+ sleep 5
18
+ end
19
+
20
+ Mongoid::Config.connect_to 'sunspot_mongo_test'
21
+
22
+ Sunspot.config.solr.url = 'http://127.0.0.1:8900/solr'
23
+ end
24
+ setup_servers_and_connections
25
+
26
+ RSpec.configure do |config|
27
+ config.before :each do
28
+ Sunspot.remove_all!
29
+ end
30
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Sunspot::Mongo" do
4
+
5
+ describe MongoidTestDocument do
6
+ subject { MongoidTestDocument }
7
+
8
+ it "should call Sunspot.setup when searchable is called" do
9
+ Sunspot.should_receive(:setup).once.with subject
10
+ subject.searchable
11
+ subject.searchable?.should be_true
12
+ end
13
+
14
+ it "should search" do
15
+ options = {}
16
+ Sunspot.should_receive(:new_search).once.and_return(double("search", :execute => nil))
17
+ subject.solr_search(options)
18
+ end
19
+
20
+ it "should index and retrieve" do
21
+ test_doc = subject.create :title => 'So much foo, so little bar.'
22
+ test_doc.index!
23
+
24
+ search = subject.solr_search do
25
+ fulltext 'foo'
26
+ end
27
+
28
+ search.hits.length.should eql 1
29
+ search.results.first.should eql test_doc
30
+ end
31
+ end
32
+
33
+ describe "test documents with options" do
34
+ it "should set sunspot_options" do
35
+ MongoidTestDocument.sunspot_options.should == {:include => []}
36
+ end
37
+
38
+ context "with the Identity Map enabled" do
39
+ before do
40
+ Mongoid.identity_map_enabled = true
41
+ end
42
+
43
+ after do
44
+ Mongoid.identity_map_enabled = false
45
+ end
46
+
47
+ it "supports includes" do
48
+ test_doc = MongoidTestDocument.create! :title => 'So much foo, so little bar.'
49
+ test_doc_two = MongoidTestDocumentTwo.create! :title => 'So much foo, so little bar.', mongoid_test_document: test_doc
50
+ Sunspot.commit
51
+
52
+ finder = MongoidTestDocument.includes(:mongoid_test_document_two)
53
+ MongoidTestDocument.should_receive(:includes).with(:mongoid_test_document_two).and_return(finder)
54
+ search_results = MongoidTestDocument.solr_search(include: :mongoid_test_document_two) do |query|
55
+ query.fulltext 'foo'
56
+ end.results
57
+
58
+ search_results.first.mongoid_test_document_two.should == test_doc_two
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,25 @@
1
+ class MongoidTestDocument
2
+ include Mongoid::Document
3
+ include Sunspot::Mongo
4
+
5
+ has_one :mongoid_test_document_two
6
+
7
+ field :title
8
+
9
+ searchable do
10
+ text :title
11
+ end
12
+ end
13
+
14
+ class MongoidTestDocumentTwo
15
+ include Mongoid::Document
16
+ include Sunspot::Mongo
17
+
18
+ belongs_to :mongoid_test_document
19
+
20
+ field :title
21
+
22
+ searchable do
23
+ text :title
24
+ end
25
+ end
@@ -0,0 +1,32 @@
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-toothrot"
7
+ s.version = Sunspot::Mongo::VERSION
8
+ s.authors = ["Brian Alexander", "Derek Harmel"]
9
+ s.email = ["balexand@gmail.com", "dgharmel@gmail.com"]
10
+ s.homepage = "https://github.com/derekharmel/sunspot_mongo"
11
+ s.summary = %q{Sunspot support for Mongo Mapper and Mongoid.}
12
+ s.description = %q{Sunspot support for Mongo Mapper and Mongoid.}
13
+
14
+ s.rubyforge_project = "sunspot_mongo-toothrot"
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
+ s.add_development_dependency "guard", [">= 0"]
29
+ s.add_development_dependency "guard-rspec", [">= 0"]
30
+ s.add_development_dependency "sunspot_solr", [">= 0"]
31
+ s.add_development_dependency "pry-rails", [">= 0"]
32
+ end
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sunspot_mongo-toothrot
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Alexander
8
+ - Derek Harmel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sunspot_rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bson_ext
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: mongo_mapper
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: mongoid
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rails
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: guard
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: guard-rspec
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: sunspot_solr
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: pry-rails
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ description: Sunspot support for Mongo Mapper and Mongoid.
155
+ email:
156
+ - balexand@gmail.com
157
+ - dgharmel@gmail.com
158
+ executables: []
159
+ extensions: []
160
+ extra_rdoc_files: []
161
+ files:
162
+ - .gitignore
163
+ - Gemfile
164
+ - Guardfile
165
+ - LICENSE
166
+ - README.rdoc
167
+ - Rakefile
168
+ - lib/sunspot/mongo.rb
169
+ - lib/sunspot/mongo/railtie.rb
170
+ - lib/sunspot/mongo/tasks.rb
171
+ - lib/sunspot/mongo/version.rb
172
+ - lib/sunspot_mongo.rb
173
+ - spec/spec_helper.rb
174
+ - spec/sunspot_mongo_spec.rb
175
+ - spec/support/models/mongoid.rb
176
+ - sunspot_mongo.gemspec
177
+ homepage: https://github.com/derekharmel/sunspot_mongo
178
+ licenses: []
179
+ metadata: {}
180
+ post_install_message:
181
+ rdoc_options: []
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - '>='
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubyforge_project: sunspot_mongo-toothrot
196
+ rubygems_version: 2.0.3
197
+ signing_key:
198
+ specification_version: 4
199
+ summary: Sunspot support for Mongo Mapper and Mongoid.
200
+ test_files:
201
+ - spec/spec_helper.rb
202
+ - spec/sunspot_mongo_spec.rb
203
+ - spec/support/models/mongoid.rb