erichummel-sunspot_rails 1.2.1a → 1.2.1b
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/lib/sunspot/rails/configuration.rb +3 -7
- data/lib/sunspot/rails/railtie.rb +0 -10
- data/lib/sunspot/rails/searchable.rb +2 -2
- data/lib/sunspot/rails/server.rb +1 -1
- data/lib/sunspot/rails/tasks.rb +3 -4
- data/lib/sunspot/rails.rb +3 -4
- data/lib/sunspot_rails.rb +0 -5
- data/spec/configuration_spec.rb +4 -4
- data/spec/server_spec.rb +1 -1
- metadata +2 -5
- data/lib/sunspot/rails/log_subscriber.rb +0 -33
- data/lib/sunspot/rails/railties/controller_runtime.rb +0 -36
- data/lib/sunspot/rails/solr_instrumentation.rb +0 -21
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'erb'
|
2
|
-
|
3
1
|
module Sunspot #:nodoc:
|
4
2
|
module Rails #:nodoc:
|
5
3
|
#
|
@@ -195,10 +193,9 @@ module Sunspot #:nodoc:
|
|
195
193
|
@data_path ||= user_configuration_from_key('solr', 'data_path') || File.join(::Rails.root, 'solr', 'data', ::Rails.env)
|
196
194
|
end
|
197
195
|
|
198
|
-
def
|
199
|
-
@
|
196
|
+
def pid_path
|
197
|
+
@pids_path ||= user_configuration_from_key('solr', 'pid_path') || File.join(::Rails.root, 'solr', 'pids', ::Rails.env)
|
200
198
|
end
|
201
|
-
|
202
199
|
|
203
200
|
#
|
204
201
|
# The solr home directory. Sunspot::Rails expects this directory
|
@@ -280,8 +277,7 @@ module Sunspot #:nodoc:
|
|
280
277
|
path = File.join(::Rails.root, 'config', 'sunspot.yml')
|
281
278
|
if File.exist?(path)
|
282
279
|
File.open(path) do |file|
|
283
|
-
|
284
|
-
YAML.load(processed)[::Rails.env]
|
280
|
+
YAML.load(file)[::Rails.env]
|
285
281
|
end
|
286
282
|
else
|
287
283
|
{}
|
@@ -11,16 +11,6 @@ module Sunspot
|
|
11
11
|
ActiveSupport.on_load(:action_controller) do
|
12
12
|
include(Sunspot::Rails::RequestLifecycle)
|
13
13
|
end
|
14
|
-
require 'sunspot/rails/log_subscriber'
|
15
|
-
RSolr::Client.module_eval{ include Sunspot::Rails::SolrInstrumentation }
|
16
|
-
end
|
17
|
-
|
18
|
-
# Expose database runtime to controller for logging.
|
19
|
-
initializer "sunspot_rails.log_runtime" do |app|
|
20
|
-
require "sunspot/rails/railties/controller_runtime"
|
21
|
-
ActiveSupport.on_load(:action_controller) do
|
22
|
-
include Sunspot::Rails::Railties::ControllerRuntime
|
23
|
-
end
|
24
14
|
end
|
25
15
|
|
26
16
|
rake_tasks do
|
@@ -67,8 +67,8 @@ module Sunspot #:nodoc:
|
|
67
67
|
extend ClassMethods
|
68
68
|
include InstanceMethods
|
69
69
|
|
70
|
-
|
71
|
-
|
70
|
+
class_inheritable_hash :sunspot_options
|
71
|
+
|
72
72
|
unless options[:auto_index] == false
|
73
73
|
before_save :maybe_mark_for_auto_indexing
|
74
74
|
after_save :maybe_auto_index
|
data/lib/sunspot/rails/server.rb
CHANGED
data/lib/sunspot/rails/tasks.rb
CHANGED
@@ -38,7 +38,7 @@ namespace :sunspot do
|
|
38
38
|
# $ rake sunspot:reindex[1000,Post] # reindex only the Post model in
|
39
39
|
# # batchs of 1000
|
40
40
|
# $ rake sunspot:reindex[,Post+Author] # reindex Post and Author model
|
41
|
-
task :reindex,
|
41
|
+
task :reindex, :batch_size, :models, :needs => :environment do |t, args|
|
42
42
|
reindex_options = {:batch_commit => false}
|
43
43
|
case args[:batch_size]
|
44
44
|
when 'false'
|
@@ -47,9 +47,8 @@ namespace :sunspot do
|
|
47
47
|
reindex_options[:batch_size] = args[:batch_size].to_i if args[:batch_size].to_i > 0
|
48
48
|
end
|
49
49
|
unless args[:models]
|
50
|
-
|
51
|
-
|
52
|
-
all_models = all_files.map { |path| path.sub(models_path.to_s, '')[0..-4].camelize.sub(/^::/, '').constantize rescue nil }.compact
|
50
|
+
all_files = Dir.glob(Rails.root.join('app', 'models', '*.rb'))
|
51
|
+
all_models = all_files.map { |path| File.basename(path, '.rb').camelize.constantize }
|
53
52
|
sunspot_models = all_models.select { |m| m < ActiveRecord::Base and m.searchable? }
|
54
53
|
else
|
55
54
|
sunspot_models = args[:models].split('+').map{|m| m.constantize}
|
data/lib/sunspot/rails.rb
CHANGED
@@ -6,7 +6,6 @@ require File.join(File.dirname(__FILE__), 'rails', 'searchable')
|
|
6
6
|
|
7
7
|
module Sunspot #:nodoc:
|
8
8
|
module Rails #:nodoc:
|
9
|
-
autoload :SolrInstrumentation, File.join(File.dirname(__FILE__), 'rails', 'solr_instrumentation')
|
10
9
|
autoload :StubSessionProxy, File.join(File.dirname(__FILE__), 'rails', 'stub_session_proxy')
|
11
10
|
autoload :Server, File.join(File.dirname(__FILE__), 'rails', 'server')
|
12
11
|
autoload :VERSION, File.join(File.dirname(__FILE__), 'rails', 'version')
|
@@ -48,9 +47,9 @@ module Sunspot #:nodoc:
|
|
48
47
|
def slave_config(sunspot_rails_configuration)
|
49
48
|
config = Sunspot::Configuration.build
|
50
49
|
config.solr.url = URI::HTTP.build(
|
51
|
-
:host =>
|
52
|
-
:port =>
|
53
|
-
:path =>
|
50
|
+
:host => configuration.hostname,
|
51
|
+
:port => configuration.port,
|
52
|
+
:path => configuration.path
|
54
53
|
).to_s
|
55
54
|
config
|
56
55
|
end
|
data/lib/sunspot_rails.rb
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
# This needs to be loaded before sunspot/search/paginated_collection
|
2
|
-
# or #to_json gets defined in Object breaking delegation to Array via
|
3
|
-
# method_missing
|
4
|
-
require 'active_support/core_ext/object/to_json' if Rails::VERSION::MAJOR == 3
|
5
|
-
|
6
1
|
require 'sunspot/rails'
|
7
2
|
|
8
3
|
if Rails::VERSION::MAJOR == 3
|
data/spec/configuration_spec.rb
CHANGED
@@ -55,9 +55,9 @@ describe Sunspot::Rails::Configuration, "default values without a sunspot.yml" d
|
|
55
55
|
@config.data_path.should == '/some/path/solr/data/test'
|
56
56
|
end
|
57
57
|
|
58
|
-
it "should handle the '
|
58
|
+
it "should handle the 'pid_path' property when not set" do
|
59
59
|
Rails.should_receive(:root).at_least(1).and_return('/some/path')
|
60
|
-
@config.
|
60
|
+
@config.pid_path.should == '/some/path/solr/pids/test'
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should handle the 'auto_commit_after_request' propery when not set" do
|
@@ -99,8 +99,8 @@ describe Sunspot::Rails::Configuration, "user provided sunspot.yml" do
|
|
99
99
|
@config.data_path.should == '/my_superior_path/data'
|
100
100
|
end
|
101
101
|
|
102
|
-
it "should handle the '
|
103
|
-
@config.
|
102
|
+
it "should handle the 'pid_path' property when set" do
|
103
|
+
@config.pid_path.should == '/my_superior_path/pids'
|
104
104
|
end
|
105
105
|
|
106
106
|
it "should handle the 'solr_home' property when set" do
|
data/spec/server_spec.rb
CHANGED
@@ -16,7 +16,7 @@ describe Sunspot::Rails::Server do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "sets the correct Solr PID path" do
|
19
|
-
@server.pid_path.should == File.join(
|
19
|
+
@server.pid_path.should == File.join(Rails.root, 'tmp', 'pids', 'sunspot-solr-test.pid')
|
20
20
|
end
|
21
21
|
|
22
22
|
it "sets the correct Solr data dir" do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: erichummel-sunspot_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 5
|
5
|
-
version: 1.2.
|
5
|
+
version: 1.2.1b
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Mat Brown
|
@@ -21,7 +21,7 @@ cert_chain: []
|
|
21
21
|
date: 2011-08-17 00:00:00 Z
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
|
-
name:
|
24
|
+
name: sunspot
|
25
25
|
prerelease: false
|
26
26
|
requirement: &id001 !ruby/object:Gem::Requirement
|
27
27
|
none: false
|
@@ -94,13 +94,10 @@ files:
|
|
94
94
|
- lib/sunspot/rails/adapters.rb
|
95
95
|
- lib/sunspot/rails/configuration.rb
|
96
96
|
- lib/sunspot/rails/init.rb
|
97
|
-
- lib/sunspot/rails/log_subscriber.rb
|
98
97
|
- lib/sunspot/rails/railtie.rb
|
99
|
-
- lib/sunspot/rails/railties/controller_runtime.rb
|
100
98
|
- lib/sunspot/rails/request_lifecycle.rb
|
101
99
|
- lib/sunspot/rails/searchable.rb
|
102
100
|
- lib/sunspot/rails/server.rb
|
103
|
-
- lib/sunspot/rails/solr_instrumentation.rb
|
104
101
|
- lib/sunspot/rails/solr_logging.rb
|
105
102
|
- lib/sunspot/rails/spec_helper.rb
|
106
103
|
- lib/sunspot/rails/stub_session_proxy.rb
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
module Rails
|
3
|
-
class LogSubscriber < ActiveSupport::LogSubscriber
|
4
|
-
def self.runtime=(value)
|
5
|
-
Thread.current["sorl_runtime"] = value
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.runtime
|
9
|
-
Thread.current["sorl_runtime"] ||= 0
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.reset_runtime
|
13
|
-
rt, self.runtime = runtime, 0
|
14
|
-
rt
|
15
|
-
end
|
16
|
-
|
17
|
-
def request(event)
|
18
|
-
self.class.runtime += event.duration
|
19
|
-
return unless logger.debug?
|
20
|
-
|
21
|
-
name = '%s (%.1fms)' % ["SOLR Request", event.duration]
|
22
|
-
|
23
|
-
# produces: path=/select parameters={fq: ["type:Tag"], q: rossi, fl: * score, qf: tag_name_text, defType: dismax, start: 0, rows: 20}
|
24
|
-
parameters = event.payload[:parameters].map { |k, v| "#{k}: #{color(v, BOLD, true)}" }.join(', ')
|
25
|
-
request = "path=#{event.payload[:path]} parameters={#{parameters}}"
|
26
|
-
|
27
|
-
debug " #{color(name, GREEN, true)} [ #{request} ]"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
Sunspot::Rails::LogSubscriber.attach_to :rsolr
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
module Rails
|
3
|
-
module Railties
|
4
|
-
module ControllerRuntime
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
protected
|
8
|
-
|
9
|
-
attr_internal :solr_runtime
|
10
|
-
|
11
|
-
def cleanup_view_runtime
|
12
|
-
# TODO only if solr is connected? if not call to super
|
13
|
-
|
14
|
-
solr_rt_before_render = Sunspot::Rails::LogSubscriber.reset_runtime
|
15
|
-
runtime = super
|
16
|
-
solr_rt_after_render = Sunspot::Rails::LogSubscriber.reset_runtime
|
17
|
-
self.solr_runtime = solr_rt_before_render + solr_rt_after_render
|
18
|
-
runtime - solr_rt_after_render
|
19
|
-
end
|
20
|
-
|
21
|
-
def append_info_to_payload(payload)
|
22
|
-
super
|
23
|
-
payload[:solr_runtime] = solr_runtime
|
24
|
-
end
|
25
|
-
|
26
|
-
module ClassMethods
|
27
|
-
def log_process_action(payload)
|
28
|
-
messages, solr_runtime = super, payload[:solr_runtime]
|
29
|
-
messages << ("Solr: %.1fms" % solr_runtime.to_f) if solr_runtime
|
30
|
-
messages
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Sunspot
|
2
|
-
module Rails
|
3
|
-
module SolrInstrumentation
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
included do
|
7
|
-
alias_method :request_without_as_instrumentation, :request
|
8
|
-
alias_method :request, :request_with_as_instrumentation
|
9
|
-
end
|
10
|
-
|
11
|
-
module InstanceMethods
|
12
|
-
def request_with_as_instrumentation(path, params={}, *extra)
|
13
|
-
ActiveSupport::Notifications.instrument("request.rsolr",
|
14
|
-
{:path => path, :parameters => params}) do
|
15
|
-
request_without_as_instrumentation(path, params, *extra)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|