sunspot_mongo 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +12 -9
- data/CHANGELOG.md +7 -0
- data/README.md +5 -1
- data/UPGRADING.md +8 -0
- data/lib/sunspot/mongo.rb +15 -2
- data/lib/sunspot/mongo/tasks.rb +16 -15
- data/lib/sunspot/mongo/version.rb +1 -1
- data/spec/spec_helper.rb +2 -1
- data/spec/sunspot_mongo_spec.rb +14 -0
- data/spec/support/models/mongoid.rb +11 -0
- data/spec/support/rails.rb +5 -0
- data/sunspot_mongo.gemspec +2 -1
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b69f799044bedbdd34c2e51e95ea5b7de468da6
|
4
|
+
data.tar.gz: 4dde9885c91e575ace88a47e92b543046ea75b0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d81247aaf38e4dbe82cd1f7606b4365d8e290d165a1296c315234d04018d6b39073ec946fdddc0e81f4a4fb4f7a2dd30b6a584eb4665ebc70e3747e03a25817c
|
7
|
+
data.tar.gz: 95a1f3a371d16bcb577f407ef32a363c37ee6819c9d784db5ab970f1d3181eab06a94f7cc8f6c48781a41cdb443e10488565482cd8ad7d428dcfb771151934f1
|
data/.rubocop_todo.yml
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
# This configuration was generated by
|
2
|
-
#
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2015-08-28 12:21:38 -0400 using RuboCop version 0.33.0.
|
3
4
|
# The point is for the user to remove these configuration records
|
4
5
|
# one by one as the offenses are removed from the code base.
|
5
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -9,7 +10,7 @@
|
|
9
10
|
Metrics/AbcSize:
|
10
11
|
Max: 20
|
11
12
|
|
12
|
-
# Offense count:
|
13
|
+
# Offense count: 9
|
13
14
|
# Configuration parameters: AllowURI, URISchemes.
|
14
15
|
Metrics/LineLength:
|
15
16
|
Max: 124
|
@@ -19,10 +20,12 @@ Metrics/LineLength:
|
|
19
20
|
Metrics/MethodLength:
|
20
21
|
Max: 15
|
21
22
|
|
22
|
-
# Offense count:
|
23
|
+
# Offense count: 10
|
23
24
|
Style/Documentation:
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
Exclude:
|
26
|
+
- 'lib/sunspot/mongo.rb'
|
27
|
+
- 'lib/sunspot/mongo/railtie.rb'
|
28
|
+
- 'lib/sunspot/mongo/version.rb'
|
29
|
+
- 'spec/support/models/mongo_mapper.rb'
|
30
|
+
- 'spec/support/models/mongoid.rb'
|
31
|
+
- 'spec/support/rails.rb'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
#### 1.2.0 (2015/08/28)
|
2
|
+
|
3
|
+
* [#9](https://github.com/derekharmel/sunspot_mongo/pull/9): Changed `DataAccessor` to fix support for eager loading of associations - [@cec](https://github.com/cec).
|
4
|
+
* [#9](https://github.com/derekharmel/sunspot_mongo/pull/9): Changed `rake sunspot:mongo:reindex` to support namespaced models - [@cec](https://github.com/cec).
|
5
|
+
* [#9](https://github.com/derekharmel/sunspot_mongo/pull/9): Renamed `rake sunspot:mongo:reindex` to `sunspot:reindex`, overriding Sunspot's original task - [@cec](https://github.com/cec).
|
6
|
+
* [#9](https://github.com/derekharmel/sunspot_mongo/pull/9): Added UPGRADING - [@cec](https://github.com/cec).
|
7
|
+
|
1
8
|
#### 1.1.0 (2015/01/27)
|
2
9
|
|
3
10
|
* Changed `DataAccessor#load_all` to use the `.find` method for MongoMapper and Mongoid for loading a group of documents - [@derekharmel](https://github.com/derekharmel).
|
data/README.md
CHANGED
@@ -35,6 +35,10 @@ rails g sunspot_rails:install
|
|
35
35
|
rake sunspot:solr:start
|
36
36
|
```
|
37
37
|
|
38
|
+
## Upgrading
|
39
|
+
|
40
|
+
When upgrading to a new version, don't forget to check [UPGRADING](UPGRADING.md) for notes about breaking changes.
|
41
|
+
|
38
42
|
## Usage
|
39
43
|
|
40
44
|
Add the following to your model (assuming you have a string field named "content"):
|
@@ -64,7 +68,7 @@ If you are using Rails, objects are automatically indexed to Solr as a part of t
|
|
64
68
|
If you make a change to the object's "schema" (code in the searchable block), you must reindex all objects so the changes are reflected in Solr. Run:
|
65
69
|
|
66
70
|
```
|
67
|
-
bundle exec rake sunspot:
|
71
|
+
bundle exec rake sunspot:reindex
|
68
72
|
```
|
69
73
|
|
70
74
|
## More info
|
data/UPGRADING.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
Upgrading SunspotMongo
|
2
|
+
======================
|
3
|
+
|
4
|
+
### Upgrading to >= 1.2.0
|
5
|
+
|
6
|
+
The Rake task `sunspot:mongo:reindex` has been renamed to `sunspot:reindex` and now overrides the original Rake task from Sunspot.
|
7
|
+
|
8
|
+
See [#9](https://github.com/derekhamel/sunspot_mongo/pull/9) for more information.
|
data/lib/sunspot/mongo.rb
CHANGED
@@ -18,12 +18,25 @@ module Sunspot
|
|
18
18
|
end
|
19
19
|
|
20
20
|
class DataAccessor < Sunspot::Adapters::DataAccessor
|
21
|
+
attr_accessor :include
|
22
|
+
|
23
|
+
# inspired by how Sunspot does this for ActiveRecord
|
24
|
+
def initialize(clazz)
|
25
|
+
super(clazz)
|
26
|
+
@inherited_attributes = [:include]
|
27
|
+
end
|
28
|
+
|
21
29
|
def load(id)
|
22
|
-
|
30
|
+
scope.find(id)
|
23
31
|
end
|
24
32
|
|
25
33
|
def load_all(ids)
|
26
|
-
|
34
|
+
scope.find(ids)
|
35
|
+
end
|
36
|
+
|
37
|
+
def scope
|
38
|
+
sc = @clazz.respond_to?(:criteria) ? @clazz.criteria : @clazz
|
39
|
+
@include ? sc.includes(@include) : sc
|
27
40
|
end
|
28
41
|
end
|
29
42
|
end
|
data/lib/sunspot/mongo/tasks.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
|
+
# Delete reindex task registered by sunspot_rails
|
2
|
+
tasks = Rake.application.instance_variable_get '@tasks'
|
3
|
+
tasks.delete 'sunspot:reindex'
|
4
|
+
|
1
5
|
namespace :sunspot do
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
all_models.select { |m| m.include?(Sunspot::Mongo) && m.searchable? }
|
11
|
-
end
|
6
|
+
desc "Reindex all models that include Sunspot::Mongo and are located in your application's models directory."
|
7
|
+
task :reindex, [:models] => :environment do |_t, args|
|
8
|
+
sunspot_models = if args[:models]
|
9
|
+
args[:models].split('+').map(&:constantize)
|
10
|
+
else
|
11
|
+
Rails.application.eager_load!
|
12
|
+
Sunspot.searchable # when a model calls searchable, it registers itself to Sunspot
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
15
|
+
sunspot_models.each do |model|
|
16
|
+
puts "reindexing #{model}"
|
17
|
+
model.all.each(&:index)
|
18
|
+
Sunspot.commit
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rails'
|
2
2
|
require 'sunspot_mongo'
|
3
|
+
require 'support/rails'
|
3
4
|
|
4
5
|
ENV['MONGOID_VERSION'] = '4' unless ENV['MONGOID_VERSION'] || ENV['MONGO_MAPPER_VERSION']
|
5
6
|
|
@@ -17,7 +18,7 @@ require 'shared_examples'
|
|
17
18
|
def setup_servers_and_connections
|
18
19
|
FileUtils.mkdir_p '/tmp/sunspot_mongo_test/'
|
19
20
|
|
20
|
-
@solr_pid
|
21
|
+
@solr_pid = fork { `sunspot-solr start --log-file=solr.log --data-directory=data --log-level=INFO --port=8900` }
|
21
22
|
sleep 5
|
22
23
|
|
23
24
|
if ENV['MONGOID_VERSION']
|
data/spec/sunspot_mongo_spec.rb
CHANGED
@@ -19,6 +19,20 @@ describe 'Sunspot::Mongo' do
|
|
19
19
|
if ENV['MONGOID_VERSION']
|
20
20
|
describe MongoidTestDocument do
|
21
21
|
it_behaves_like 'a mongo document'
|
22
|
+
it 'eager-loads associations specified through :include option' do
|
23
|
+
test_doc = MongoidTestDocument.create title: 'So much foo, so little bar.'
|
24
|
+
test_tag = MongoidTestDocumentTag.create name: 'A tag'
|
25
|
+
test_doc.tags << test_tag
|
26
|
+
test_doc.save
|
27
|
+
test_doc.index!
|
28
|
+
|
29
|
+
search = MongoidTestDocument.solr_search(include: :tags) do
|
30
|
+
fulltext 'foo'
|
31
|
+
end
|
32
|
+
expect(search.hits.length).to eql 1
|
33
|
+
expect(search.results.first).to eql test_doc
|
34
|
+
expect(search.results.first.tags).to match [test_tag]
|
35
|
+
end
|
22
36
|
end
|
23
37
|
describe 'test documents with options' do
|
24
38
|
it 'should set sunspot_options' do
|
@@ -4,7 +4,18 @@ class MongoidTestDocument
|
|
4
4
|
|
5
5
|
field :title
|
6
6
|
|
7
|
+
has_and_belongs_to_many :tags, class_name: 'MongoidTestDocumentTag'
|
8
|
+
|
7
9
|
searchable do
|
8
10
|
text :title
|
9
11
|
end
|
10
12
|
end
|
13
|
+
|
14
|
+
class MongoidTestDocumentTag
|
15
|
+
include Mongoid::Document
|
16
|
+
include Sunspot::Mongo
|
17
|
+
|
18
|
+
field :name
|
19
|
+
|
20
|
+
has_and_belongs_to_many :documents, class_name: 'MongoidTestDocument'
|
21
|
+
end
|
data/sunspot_mongo.gemspec
CHANGED
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = 'https://github.com/derekharmel/sunspot_mongo'
|
11
11
|
s.summary = 'Sunspot support for Mongo Mapper and Mongoid.'
|
12
12
|
s.description = 'Sunspot support for Mongo Mapper and Mongoid.'
|
13
|
+
s.license = 'MIT'
|
13
14
|
|
14
15
|
s.rubyforge_project = 'sunspot_mongo'
|
15
16
|
|
@@ -25,5 +26,5 @@ Gem::Specification.new do |s|
|
|
25
26
|
s.add_development_dependency 'guard'
|
26
27
|
s.add_development_dependency 'guard-rspec'
|
27
28
|
s.add_development_dependency 'sunspot_solr', '2.0.0'
|
28
|
-
s.add_development_dependency 'rubocop', '0.
|
29
|
+
s.add_development_dependency 'rubocop', '0.33.0'
|
29
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunspot_mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Alexander
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-08-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sunspot_rails
|
@@ -101,14 +101,14 @@ dependencies:
|
|
101
101
|
requirements:
|
102
102
|
- - '='
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: 0.
|
104
|
+
version: 0.33.0
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
109
|
- - '='
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version: 0.
|
111
|
+
version: 0.33.0
|
112
112
|
description: Sunspot support for Mongo Mapper and Mongoid.
|
113
113
|
email:
|
114
114
|
- balexand@gmail.com
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- LICENSE
|
130
130
|
- README.md
|
131
131
|
- Rakefile
|
132
|
+
- UPGRADING.md
|
132
133
|
- lib/sunspot/mongo.rb
|
133
134
|
- lib/sunspot/mongo/railtie.rb
|
134
135
|
- lib/sunspot/mongo/tasks.rb
|
@@ -139,9 +140,11 @@ files:
|
|
139
140
|
- spec/sunspot_mongo_spec.rb
|
140
141
|
- spec/support/models/mongo_mapper.rb
|
141
142
|
- spec/support/models/mongoid.rb
|
143
|
+
- spec/support/rails.rb
|
142
144
|
- sunspot_mongo.gemspec
|
143
145
|
homepage: https://github.com/derekharmel/sunspot_mongo
|
144
|
-
licenses:
|
146
|
+
licenses:
|
147
|
+
- MIT
|
145
148
|
metadata: {}
|
146
149
|
post_install_message:
|
147
150
|
rdoc_options: []
|
@@ -169,3 +172,4 @@ test_files:
|
|
169
172
|
- spec/sunspot_mongo_spec.rb
|
170
173
|
- spec/support/models/mongo_mapper.rb
|
171
174
|
- spec/support/models/mongoid.rb
|
175
|
+
- spec/support/rails.rb
|