sunspot_padrino 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +74 -0
- data/LICENSE.txt +20 -0
- data/README.md +5 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/generators/sunspot.rb +57 -0
- data/generators/templates/sunspot.yml +22 -0
- data/lib/sunspot/padrino.rb +73 -0
- data/lib/sunspot/padrino/adapters.rb +90 -0
- data/lib/sunspot/padrino/configuration.rb +404 -0
- data/lib/sunspot/padrino/init.rb +8 -0
- data/lib/sunspot/padrino/request_lifecycle.rb +36 -0
- data/lib/sunspot/padrino/searchable.rb +497 -0
- data/lib/sunspot/padrino/server.rb +99 -0
- data/lib/sunspot/padrino/solr_instrumentation.rb +21 -0
- data/lib/sunspot/padrino/spec_helper.rb +26 -0
- data/lib/sunspot/padrino/stub_session_proxy.rb +168 -0
- data/lib/sunspot/padrino/tasks.rb +67 -0
- data/lib/sunspot_padrino.rb +14 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/sunspot_padrino_spec.rb +7 -0
- metadata +143 -0
@@ -0,0 +1,99 @@
|
|
1
|
+
module Sunspot
|
2
|
+
module Padrino
|
3
|
+
class Server < Sunspot::Solr::Server
|
4
|
+
|
5
|
+
#
|
6
|
+
# Directory in which to store PID files
|
7
|
+
#
|
8
|
+
def pid_dir
|
9
|
+
configuration.pid_dir || File.join(::Padrino.root, 'tmp', 'pids')
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# Name of the PID file
|
14
|
+
#
|
15
|
+
def pid_file
|
16
|
+
"sunspot-solr-#{::Padrino.env}.pid"
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
# Directory to store lucene index data files
|
21
|
+
#
|
22
|
+
# ==== Returns
|
23
|
+
#
|
24
|
+
# String:: data_path
|
25
|
+
#
|
26
|
+
def solr_data_dir
|
27
|
+
configuration.data_path
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Directory to use for Solr home.
|
32
|
+
#
|
33
|
+
def solr_home
|
34
|
+
File.join(configuration.solr_home)
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# Solr start jar
|
39
|
+
#
|
40
|
+
def solr_jar
|
41
|
+
configuration.solr_jar || super
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Address on which to run Solr
|
46
|
+
#
|
47
|
+
def bind_address
|
48
|
+
configuration.bind_address
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# Port on which to run Solr
|
53
|
+
#
|
54
|
+
def port
|
55
|
+
configuration.port
|
56
|
+
end
|
57
|
+
|
58
|
+
def log_level
|
59
|
+
configuration.log_level
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Log file for Solr. File is in the padrino log/ directory.
|
64
|
+
#
|
65
|
+
def log_file
|
66
|
+
File.join(::Padrino.root, 'log', "sunspot-solr-#{::Padrino.env}.log")
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# Minimum Java heap size for Solr
|
71
|
+
#
|
72
|
+
def min_memory
|
73
|
+
configuration.min_memory
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
# Maximum Java heap size for Solr
|
78
|
+
#
|
79
|
+
def max_memory
|
80
|
+
configuration.max_memory
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
#
|
86
|
+
# access to the Sunspot::Padrino::Configuration, defined in
|
87
|
+
# sunspot.yml. Use Sunspot::Padrino.configuration if you want
|
88
|
+
# to access the configuration directly.
|
89
|
+
#
|
90
|
+
# ==== returns
|
91
|
+
#
|
92
|
+
# Sunspot::Padrino::Configuration:: configuration
|
93
|
+
#
|
94
|
+
def configuration
|
95
|
+
Sunspot::Padrino.configuration
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Sunspot
|
2
|
+
module Padrino
|
3
|
+
module SolrInstrumentation
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
alias_method_chain :send_and_receive, :as_instrumentation
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def send_and_receive_with_as_instrumentation(path, opts)
|
12
|
+
parameters = (opts[:params] || {})
|
13
|
+
parameters.merge!(opts[:data]) if opts[:data].is_a? Hash
|
14
|
+
payload = {:path => path, :parameters => parameters}
|
15
|
+
ActiveSupport::Notifications.instrument("request.rsolr", payload) do
|
16
|
+
send_and_receive_without_as_instrumentation(path, opts)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Sunspot
|
2
|
+
module Padrino
|
3
|
+
module SpecHelper
|
4
|
+
def disconnect_sunspot
|
5
|
+
before(:each) do
|
6
|
+
Sunspot.session = StubSessionProxy.new(Sunspot.session)
|
7
|
+
end
|
8
|
+
|
9
|
+
after(:each) do
|
10
|
+
Sunspot.session = Sunspot.session.original_session
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
rspec =
|
18
|
+
begin
|
19
|
+
RSpec
|
20
|
+
rescue NameError, ArgumentError
|
21
|
+
Spec::Runner
|
22
|
+
end
|
23
|
+
|
24
|
+
rspec.configure do |config|
|
25
|
+
config.extend(Sunspot::Padrino::SpecHelper)
|
26
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
module Sunspot
|
2
|
+
module Padrino
|
3
|
+
class StubSessionProxy
|
4
|
+
attr_reader :original_session
|
5
|
+
|
6
|
+
def initialize(original_session)
|
7
|
+
@original_session = original_session
|
8
|
+
end
|
9
|
+
|
10
|
+
def batch
|
11
|
+
yield
|
12
|
+
end
|
13
|
+
|
14
|
+
def index(*objects)
|
15
|
+
end
|
16
|
+
|
17
|
+
def index!(*objects)
|
18
|
+
end
|
19
|
+
|
20
|
+
def remove(*objects)
|
21
|
+
end
|
22
|
+
|
23
|
+
def remove!(*objects)
|
24
|
+
end
|
25
|
+
|
26
|
+
def remove_by_id(clazz, id)
|
27
|
+
end
|
28
|
+
|
29
|
+
def remove_by_id!(clazz, id)
|
30
|
+
end
|
31
|
+
|
32
|
+
def remove_all(clazz = nil)
|
33
|
+
end
|
34
|
+
|
35
|
+
def remove_all!(clazz = nil)
|
36
|
+
end
|
37
|
+
|
38
|
+
def optimize
|
39
|
+
end
|
40
|
+
|
41
|
+
def dirty?
|
42
|
+
false
|
43
|
+
end
|
44
|
+
|
45
|
+
def delete_dirty?
|
46
|
+
false
|
47
|
+
end
|
48
|
+
|
49
|
+
def commit_if_dirty
|
50
|
+
end
|
51
|
+
|
52
|
+
def commit_if_delete_dirty
|
53
|
+
end
|
54
|
+
|
55
|
+
def commit
|
56
|
+
end
|
57
|
+
|
58
|
+
def search(*types)
|
59
|
+
Search.new
|
60
|
+
end
|
61
|
+
|
62
|
+
def new_search(*types)
|
63
|
+
Search.new
|
64
|
+
end
|
65
|
+
|
66
|
+
def more_like_this(*args)
|
67
|
+
Search.new
|
68
|
+
end
|
69
|
+
|
70
|
+
def new_more_like_this(*args)
|
71
|
+
Search.new
|
72
|
+
end
|
73
|
+
|
74
|
+
class Search
|
75
|
+
|
76
|
+
def build
|
77
|
+
self
|
78
|
+
end
|
79
|
+
|
80
|
+
def results
|
81
|
+
PaginatedCollection.new
|
82
|
+
end
|
83
|
+
|
84
|
+
def hits(options = {})
|
85
|
+
PaginatedCollection.new
|
86
|
+
end
|
87
|
+
alias_method :raw_results, :hits
|
88
|
+
|
89
|
+
def total
|
90
|
+
0
|
91
|
+
end
|
92
|
+
|
93
|
+
def facets
|
94
|
+
[]
|
95
|
+
end
|
96
|
+
|
97
|
+
def facet(name)
|
98
|
+
FacetStub.new
|
99
|
+
end
|
100
|
+
|
101
|
+
def dynamic_facet(name)
|
102
|
+
FacetStub.new
|
103
|
+
end
|
104
|
+
|
105
|
+
def execute
|
106
|
+
self
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
class PaginatedCollection < Array
|
112
|
+
|
113
|
+
def total_count
|
114
|
+
0
|
115
|
+
end
|
116
|
+
alias :total_entries :total_count
|
117
|
+
|
118
|
+
def current_page
|
119
|
+
1
|
120
|
+
end
|
121
|
+
|
122
|
+
def per_page
|
123
|
+
30
|
124
|
+
end
|
125
|
+
alias :limit_value :per_page
|
126
|
+
|
127
|
+
def total_pages
|
128
|
+
1
|
129
|
+
end
|
130
|
+
alias :num_pages :total_pages
|
131
|
+
|
132
|
+
def first_page?
|
133
|
+
true
|
134
|
+
end
|
135
|
+
|
136
|
+
def last_page?
|
137
|
+
true
|
138
|
+
end
|
139
|
+
|
140
|
+
def previous_page
|
141
|
+
nil
|
142
|
+
end
|
143
|
+
|
144
|
+
def next_page
|
145
|
+
nil
|
146
|
+
end
|
147
|
+
|
148
|
+
def out_of_bounds?
|
149
|
+
false
|
150
|
+
end
|
151
|
+
|
152
|
+
def offset
|
153
|
+
0
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
class FacetStub
|
159
|
+
|
160
|
+
def rows
|
161
|
+
[]
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
namespace :sunspot do
|
2
|
+
desc "Drop and then reindex all solr models that are located in your application's models directory."
|
3
|
+
# This task depends on the standard Padrino file naming \
|
4
|
+
# conventions, in that the file name matches the defined class name. \
|
5
|
+
# By default the indexing system works in batches of 50 records, you can \
|
6
|
+
# set your own value for this by using the batch_size argument. You can \
|
7
|
+
# also optionally define a list of models separated by a plus sign '+'
|
8
|
+
#
|
9
|
+
# $ rake sunspot:reindex # reindex all models
|
10
|
+
# $ rake sunspot:reindex[1000] # reindex in batches of 1000
|
11
|
+
# $ rake sunspot:reindex[false] # reindex without batching
|
12
|
+
# $ rake sunspot:reindex[,Post] # reindex only the Post model
|
13
|
+
# $ rake sunspot:reindex[1000,Post] # reindex only the Post model in
|
14
|
+
# # batchs of 1000
|
15
|
+
# $ rake sunspot:reindex[,Post+Author] # reindex Post and Author model
|
16
|
+
task :reindex, [:batch_size, :models, :silence] => [:environment] do |t, args|
|
17
|
+
# Retry once or gracefully fail for a 5xx error so we don't break reindexing
|
18
|
+
with_session(Sunspot::SessionProxy::Retry5xxSessionProxy.new(Sunspot.session)) do
|
19
|
+
|
20
|
+
# Set up general options for reindexing
|
21
|
+
reindex_options = { :batch_commit => false }
|
22
|
+
|
23
|
+
case args[:batch_size]
|
24
|
+
when 'false'
|
25
|
+
reindex_options[:batch_size] = nil
|
26
|
+
when /^\d+$/
|
27
|
+
reindex_options[:batch_size] = args[:batch_size].to_i if args[:batch_size].to_i > 0
|
28
|
+
end
|
29
|
+
|
30
|
+
if args[:models].present?
|
31
|
+
# Choose a specific subset of models, if requested
|
32
|
+
model_names = args[:models].split(/[+ ]/)
|
33
|
+
sunspot_models = model_names.map{ |m| m.constantize }
|
34
|
+
else
|
35
|
+
# By default, reindex all searchable models
|
36
|
+
sunspot_models = Sunspot.searchable
|
37
|
+
end
|
38
|
+
|
39
|
+
# Set up progress_bar to, ah, report progress unless the user has chosen to silence output
|
40
|
+
begin
|
41
|
+
require 'progress_bar'
|
42
|
+
total_documents = sunspot_models.map { | m | m.count }.sum
|
43
|
+
reindex_options[:progress_bar] = ProgressBar.new(total_documents)
|
44
|
+
rescue LoadError => e
|
45
|
+
$stdout.puts "Skipping progress bar: for progress reporting, add gem 'progress_bar' to your Gemfile"
|
46
|
+
rescue Exception => e
|
47
|
+
$stderr.puts "Error using progress bar: #{e.message}"
|
48
|
+
end unless args[:silence]
|
49
|
+
|
50
|
+
# Finally, invoke the class-level solr_reindex on each model
|
51
|
+
sunspot_models.each do |model|
|
52
|
+
model.solr_reindex(reindex_options)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Swaps sunspot sessions for the duration of the block
|
58
|
+
# Ensures the session is returned to normal in case this task is called from within the padrino app
|
59
|
+
# and not just a one-off from the command line
|
60
|
+
def with_session(new_session)
|
61
|
+
original_session = Sunspot.session
|
62
|
+
Sunspot.session = new_session
|
63
|
+
yield
|
64
|
+
ensure
|
65
|
+
Sunspot.session = original_session
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
if ActiveRecord::VERSION::MAJOR > 4 || (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR >= 1)
|
2
|
+
require 'active_support/core_ext/object/json'
|
3
|
+
else
|
4
|
+
require 'active_support/core_ext/object/to_json'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'sunspot/padrino'
|
8
|
+
require 'sunspot/padrino/init'
|
9
|
+
|
10
|
+
# Add our generators to Padrino::Generators.
|
11
|
+
Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/../generators/*.rb']
|
12
|
+
|
13
|
+
# Add our tasks to padrino-core.
|
14
|
+
Padrino::Tasks.files << File.dirname(__FILE__) + '/sunspot/padrino/tasks.rb'
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_adapter 'test_frameworks'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
+
add_filter "/.rvm/"
|
16
|
+
end
|
17
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
18
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
19
|
+
|
20
|
+
require 'rspec'
|
21
|
+
require 'sunspot_padrino'
|
22
|
+
|
23
|
+
# Requires supporting files with custom matchers and macros, etc,
|
24
|
+
# in ./support/ and its subdirectories.
|
25
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
26
|
+
|
27
|
+
RSpec.configure do |config|
|
28
|
+
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sunspot_padrino
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jordan Yaker
|
8
|
+
- Supportify, Inc.
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-05-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 2.8.0
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 2.8.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rdoc
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.12'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '3.12'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: jeweler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.0.1
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.0.1
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: simplecov
|
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
|
+
description: |2
|
85
|
+
Sunspot::Padrino is a derived plugin that provides drop-in integration of the
|
86
|
+
Sunspot Solr search library with Padrino. It is based on the original Sunspot
|
87
|
+
::Rails library located at https://github.com/sunspot/sunspot.
|
88
|
+
email: help@supportify.io
|
89
|
+
executables: []
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files:
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
files:
|
95
|
+
- .document
|
96
|
+
- .rspec
|
97
|
+
- Gemfile
|
98
|
+
- Gemfile.lock
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.md
|
101
|
+
- Rakefile
|
102
|
+
- VERSION
|
103
|
+
- generators/sunspot.rb
|
104
|
+
- generators/templates/sunspot.yml
|
105
|
+
- lib/sunspot/padrino.rb
|
106
|
+
- lib/sunspot/padrino/adapters.rb
|
107
|
+
- lib/sunspot/padrino/configuration.rb
|
108
|
+
- lib/sunspot/padrino/init.rb
|
109
|
+
- lib/sunspot/padrino/request_lifecycle.rb
|
110
|
+
- lib/sunspot/padrino/searchable.rb
|
111
|
+
- lib/sunspot/padrino/server.rb
|
112
|
+
- lib/sunspot/padrino/solr_instrumentation.rb
|
113
|
+
- lib/sunspot/padrino/spec_helper.rb
|
114
|
+
- lib/sunspot/padrino/stub_session_proxy.rb
|
115
|
+
- lib/sunspot/padrino/tasks.rb
|
116
|
+
- lib/sunspot_padrino.rb
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
- spec/sunspot_padrino_spec.rb
|
119
|
+
homepage: http://github.com/supportify/sunspot_padrino
|
120
|
+
licenses:
|
121
|
+
- BSD
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.0.6
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: Padrino integration for the Sunspot Solr search library
|
143
|
+
test_files: []
|