websolr-rails 2.2.0 → 2.3.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/VERSION +1 -1
- data/lib/websolr-rails.rb +56 -0
- data/websolr-rails.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3.0
|
data/lib/websolr-rails.rb
CHANGED
@@ -6,6 +6,8 @@ if ENV["WEBSOLR_URL"]
|
|
6
6
|
|
7
7
|
begin
|
8
8
|
require "sunspot/rails/configuration"
|
9
|
+
require "sunspot/rails/searchable"
|
10
|
+
require "sunspot/rails/request_lifecycle"
|
9
11
|
module Sunspot #:nodoc:
|
10
12
|
module Rails #:nodoc:
|
11
13
|
class Configuration
|
@@ -21,6 +23,60 @@ if ENV["WEBSOLR_URL"]
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
26
|
+
|
27
|
+
module Sunspot #:nodoc:
|
28
|
+
module Rails #:nodoc:
|
29
|
+
#
|
30
|
+
# This module adds an after_filter to ActionController::Base that commits
|
31
|
+
# the Sunspot session if any documents have been added, changed, or removed
|
32
|
+
# in the course of the request.
|
33
|
+
#
|
34
|
+
module RequestLifecycle
|
35
|
+
class <<self
|
36
|
+
def included(base) #:nodoc:
|
37
|
+
base.after_filter do
|
38
|
+
begin
|
39
|
+
if Sunspot::Rails.configuration.auto_commit_after_request?
|
40
|
+
Sunspot::Rails.master_session.commit_if_dirty
|
41
|
+
elsif Sunspot::Rails.configuration.auto_commit_after_delete_request?
|
42
|
+
Sunspot::Rails.master_session.commit_if_delete_dirty
|
43
|
+
end
|
44
|
+
rescue Exception => e
|
45
|
+
ActionController::Base.logger.error e.message
|
46
|
+
ActionController::Base.logger.error e.backtrace.join("\n")
|
47
|
+
false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
module Sunspot
|
58
|
+
module Rails
|
59
|
+
module Searchable
|
60
|
+
module InstanceMethods
|
61
|
+
%w[index index! remove_from_index remove_from_index!].each do |method|
|
62
|
+
new_name = method =~ /!/ ? method.gsub("!", "") + "_with_caught_errors!" : "#{method}_with_caught_errors"
|
63
|
+
old_name = new_name.sub("_with_", "_without_")
|
64
|
+
define_method(new_name) do
|
65
|
+
begin
|
66
|
+
send(old_name)
|
67
|
+
rescue Exception => e
|
68
|
+
logger.error e.message
|
69
|
+
logger.error e.backtrace.join("\n")
|
70
|
+
false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
alias_method_chain method, :caught_errors
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
24
80
|
rescue LoadError
|
25
81
|
#ignore
|
26
82
|
end
|
data/websolr-rails.gemspec
CHANGED