honkster-acts_as_solr 0.3.6 → 0.3.7
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.yml +1 -1
- data/lib/acts_as_solr/tasks/solr.rake +43 -21
- metadata +28 -28
data/VERSION.yml
CHANGED
@@ -7,8 +7,7 @@ namespace :solr do
|
|
7
7
|
FileUtils.mkdir_p(SOLR_DATA_PATH)
|
8
8
|
FileUtils.mkdir_p(SOLR_PIDS_PATH)
|
9
9
|
begin
|
10
|
-
|
11
|
-
n.request_head('/').value
|
10
|
+
get_raw_solr_response
|
12
11
|
|
13
12
|
rescue Net::HTTPServerException #responding
|
14
13
|
puts "Port #{SOLR_PORT} in use" and return
|
@@ -19,20 +18,20 @@ namespace :solr do
|
|
19
18
|
#STDERR.close
|
20
19
|
exec "java #{SOLR_JVM_OPTIONS} -Dsolr.data.dir=#{SOLR_DATA_PATH} -Djetty.logs=#{SOLR_LOGS_PATH} -Djetty.port=#{SOLR_PORT} -jar start.jar"
|
21
20
|
end
|
22
|
-
sleep(5)
|
23
21
|
File.open("#{SOLR_PIDS_PATH}/#{ENV['RAILS_ENV']}_pid", "w"){ |f| f << pid}
|
22
|
+
wait_for_solr_to_respond
|
24
23
|
puts "#{ENV['RAILS_ENV']} Solr started successfully on #{SOLR_PORT}, pid: #{pid}."
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
28
|
-
|
27
|
+
|
29
28
|
desc 'Stops Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.'
|
30
29
|
task :stop do
|
31
30
|
require File.expand_path("#{File.dirname(__FILE__)}/../../../config/solr_environment")
|
32
31
|
fork do
|
33
32
|
file_path = "#{SOLR_PIDS_PATH}/#{ENV['RAILS_ENV']}_pid"
|
34
33
|
if File.exists?(file_path)
|
35
|
-
File.open(file_path, "r") do |f|
|
34
|
+
File.open(file_path, "r") do |f|
|
36
35
|
pid = f.readline
|
37
36
|
Process.kill('TERM', pid.to_i)
|
38
37
|
end
|
@@ -44,7 +43,7 @@ namespace :solr do
|
|
44
43
|
end
|
45
44
|
end
|
46
45
|
end
|
47
|
-
|
46
|
+
|
48
47
|
desc 'Remove Solr index'
|
49
48
|
task :destroy_index do
|
50
49
|
require File.expand_path("#{File.dirname(__FILE__)}/../../../config/solr_environment")
|
@@ -55,7 +54,7 @@ namespace :solr do
|
|
55
54
|
puts "Index files removed under " + ENV['RAILS_ENV'] + " environment"
|
56
55
|
end
|
57
56
|
end
|
58
|
-
|
57
|
+
|
59
58
|
# this task is by Henrik Nyh
|
60
59
|
# http://henrik.nyh.se/2007/06/rake-task-to-reindex-models-for-acts_as_solr
|
61
60
|
desc %{Reindexes data for all acts_as_solr models. Clears index first to get rid of orphaned records and optimizes index afterwards. RAILS_ENV=your_env to set environment. ONLY=book,person,magazine to only reindex those models; EXCEPT=book,magazine to exclude those models. START_SERVER=true to solr:start before and solr:stop after. BATCH=123 to post/commit in batches of that size: default is 300. CLEAR=false to not clear the index first; OPTIMIZE=false to not optimize the index afterwards.}
|
@@ -68,7 +67,7 @@ namespace :solr do
|
|
68
67
|
end
|
69
68
|
excludes = env_array_to_constants('EXCEPT')
|
70
69
|
includes -= excludes
|
71
|
-
|
70
|
+
|
72
71
|
optimize = env_to_bool('OPTIMIZE', true)
|
73
72
|
start_server = env_to_bool('START_SERVER', false)
|
74
73
|
clear_first = env_to_bool('CLEAR', true)
|
@@ -79,29 +78,29 @@ namespace :solr do
|
|
79
78
|
|
80
79
|
if start_server
|
81
80
|
puts "Starting Solr server..."
|
82
|
-
Rake::Task["solr:start"].invoke
|
81
|
+
Rake::Task["solr:start"].invoke
|
83
82
|
end
|
84
|
-
|
83
|
+
|
85
84
|
# Disable solr_optimize
|
86
85
|
module ActsAsSolr::CommonMethods
|
87
86
|
def blank() end
|
88
87
|
alias_method :deferred_solr_optimize, :solr_optimize
|
89
88
|
alias_method :solr_optimize, :blank
|
90
89
|
end
|
91
|
-
|
92
|
-
models = includes.select { |m| m.respond_to?(:rebuild_solr_index) }
|
90
|
+
|
91
|
+
models = includes.select { |m| m.respond_to?(:rebuild_solr_index) }
|
93
92
|
models.each do |model|
|
94
|
-
|
93
|
+
|
95
94
|
if clear_first
|
96
95
|
puts "Clearing index for #{model}..."
|
97
|
-
ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "#{model.solr_configuration[:type_field]}:#{model}"))
|
96
|
+
ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "#{model.solr_configuration[:type_field]}:#{model}"))
|
98
97
|
ActsAsSolr::Post.execute(Solr::Request::Commit.new)
|
99
98
|
end
|
100
|
-
|
99
|
+
|
101
100
|
puts "Rebuilding index for #{model}..."
|
102
101
|
model.rebuild_solr_index(batch_size)
|
103
102
|
|
104
|
-
end
|
103
|
+
end
|
105
104
|
|
106
105
|
if models.empty?
|
107
106
|
puts "There were no models to reindex."
|
@@ -112,16 +111,16 @@ namespace :solr do
|
|
112
111
|
|
113
112
|
if start_server
|
114
113
|
puts "Shutting down Solr server..."
|
115
|
-
Rake::Task["solr:stop"].invoke
|
114
|
+
Rake::Task["solr:stop"].invoke
|
116
115
|
end
|
117
|
-
|
116
|
+
|
118
117
|
end
|
119
|
-
|
118
|
+
|
120
119
|
def env_array_to_constants(env)
|
121
120
|
env = ENV[env] || ''
|
122
121
|
env.split(/\s*,\s*/).map { |m| m.singularize.camelize.constantize }.uniq
|
123
122
|
end
|
124
|
-
|
123
|
+
|
125
124
|
def env_to_bool(env, default)
|
126
125
|
env = ENV[env] || ''
|
127
126
|
case env
|
@@ -131,5 +130,28 @@ namespace :solr do
|
|
131
130
|
end
|
132
131
|
end
|
133
132
|
|
134
|
-
|
133
|
+
def wait_for_solr_to_respond
|
134
|
+
tries = 0
|
135
|
+
while !solr_up? && tries < 30 do
|
136
|
+
tries += 1
|
137
|
+
sleep 2
|
138
|
+
end
|
139
|
+
throw "Could not connect to the solr server after #{tries} tries." unless solr_up?
|
140
|
+
end
|
141
|
+
|
142
|
+
def solr_up?
|
143
|
+
begin
|
144
|
+
get_raw_solr_response
|
145
|
+
rescue Errno::ECONNREFUSED #not responding
|
146
|
+
return false
|
147
|
+
rescue Net::HTTPServerException #responding
|
148
|
+
return true
|
149
|
+
end
|
150
|
+
end
|
135
151
|
|
152
|
+
def get_raw_solr_response
|
153
|
+
n = Net::HTTP.new('127.0.0.1', SOLR_PORT)
|
154
|
+
n.request_head('/').value
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: honkster-acts_as_solr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mathias Meyer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-09 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -208,36 +208,36 @@ signing_key:
|
|
208
208
|
specification_version: 3
|
209
209
|
summary: "This plugin adds full text search capabilities and many other nifty features from Apache\xEF\xBF\xBDs Solr to any Rails model. I'm currently rearranging the test suite to include a real unit test suite, and adding a few features I need myself."
|
210
210
|
test_files:
|
211
|
-
- test/
|
212
|
-
- test/
|
213
|
-
- test/
|
214
|
-
- test/
|
215
|
-
- test/
|
216
|
-
- test/
|
217
|
-
- test/
|
218
|
-
- test/
|
219
|
-
- test/
|
220
|
-
- test/
|
211
|
+
- test/db/connections/mysql/connection.rb
|
212
|
+
- test/db/connections/sqlite/connection.rb
|
213
|
+
- test/db/migrate/001_create_books.rb
|
214
|
+
- test/db/migrate/002_create_movies.rb
|
215
|
+
- test/db/migrate/003_create_categories.rb
|
216
|
+
- test/db/migrate/004_create_electronics.rb
|
217
|
+
- test/db/migrate/005_create_authors.rb
|
218
|
+
- test/db/migrate/006_create_postings.rb
|
219
|
+
- test/db/migrate/007_create_posts.rb
|
220
|
+
- test/db/migrate/008_create_gadgets.rb
|
221
221
|
- test/functional/acts_as_solr_test.rb
|
222
222
|
- test/functional/association_indexing_test.rb
|
223
|
-
- test/functional/multi_solr_search_test.rb
|
224
223
|
- test/functional/faceted_search_test.rb
|
225
|
-
- test/
|
226
|
-
- test/models/movie.rb
|
224
|
+
- test/functional/multi_solr_search_test.rb
|
227
225
|
- test/models/author.rb
|
226
|
+
- test/models/book.rb
|
227
|
+
- test/models/category.rb
|
228
228
|
- test/models/electronic.rb
|
229
|
-
- test/models/novel.rb
|
230
229
|
- test/models/gadget.rb
|
230
|
+
- test/models/movie.rb
|
231
|
+
- test/models/novel.rb
|
231
232
|
- test/models/post.rb
|
232
|
-
- test/models/
|
233
|
-
- test/
|
234
|
-
- test/
|
235
|
-
- test/
|
236
|
-
- test/
|
237
|
-
- test/
|
238
|
-
- test/
|
239
|
-
- test/
|
240
|
-
- test/
|
241
|
-
- test/
|
242
|
-
- test/
|
243
|
-
- test/db/migrate/001_create_books.rb
|
233
|
+
- test/models/posting.rb
|
234
|
+
- test/test_helper.rb
|
235
|
+
- test/unit/acts_methods_shoulda.rb
|
236
|
+
- test/unit/class_methods_shoulda.rb
|
237
|
+
- test/unit/common_methods_shoulda.rb
|
238
|
+
- test/unit/instance_methods_shoulda.rb
|
239
|
+
- test/unit/lazy_document_shoulda.rb
|
240
|
+
- test/unit/parser_instance.rb
|
241
|
+
- test/unit/parser_methods_shoulda.rb
|
242
|
+
- test/unit/solr_instance.rb
|
243
|
+
- test/unit/test_helper.rb
|