sunspot_activerecord 0.0.3 → 0.0.4
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/Rakefile +1 -0
- data/lib/rake.rb +40 -0
- data/lib/sunspot_activerecord/version.rb +1 -1
- data/spec/app/db/test.sqlite3 +0 -0
- metadata +5 -4
data/Rakefile
CHANGED
data/lib/rake.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
namespace :sunspot do
|
3
|
+
desc "Reindex all solr models that are located in your application's models directory."
|
4
|
+
# This task depends on the standard Rails file naming \
|
5
|
+
# conventions, in that the file name matches the defined class name. \
|
6
|
+
# By default the indexing system works in batches of 50 records, you can \
|
7
|
+
# set your own value for this by using the batch_size argument. You can \
|
8
|
+
# also optionally define a list of models to separated by a forward slash '/'
|
9
|
+
#
|
10
|
+
# $ rake sunspot:reindex # reindex all models
|
11
|
+
# $ rake sunspot:reindex[1000] # reindex in batches of 1000
|
12
|
+
# $ rake sunspot:reindex[false] # reindex without batching
|
13
|
+
# $ rake sunspot:reindex[,Post] # reindex only the Post model
|
14
|
+
# $ rake sunspot:reindex[1000,Post] # reindex only the Post model in
|
15
|
+
# # batchs of 1000
|
16
|
+
# $ rake sunspot:reindex[,Post+Author] # reindex Post and Author model
|
17
|
+
task :reindex, [:batch_size, :models, :models_path] => [:environment] do |t, args|
|
18
|
+
reindex_options = {:batch_commit => false}
|
19
|
+
case args[:batch_size]
|
20
|
+
when 'false'
|
21
|
+
reindex_options[:batch_size] = nil
|
22
|
+
when /^\d+$/
|
23
|
+
reindex_options[:batch_size] = args[:batch_size].to_i if args[:batch_size].to_i > 0
|
24
|
+
end
|
25
|
+
|
26
|
+
if args[:models] and !args[:models].empty?
|
27
|
+
sunspot_models = args[:models].split('+').map{ |m| m.constantize }
|
28
|
+
else
|
29
|
+
models_path = args[:models_path] || './app/models'
|
30
|
+
all_files = Dir.glob(File.join(models_path, ['*.rb']))
|
31
|
+
all_models = all_files.map { |path| path.sub(models_path.to_s, '')[0..-4].camelize.sub(/^::/, '').constantize rescue nil }.compact
|
32
|
+
sunspot_models = all_models.select { |m| m < ActiveRecord::Base and m.searchable? }
|
33
|
+
end
|
34
|
+
|
35
|
+
sunspot_models.each do |model|
|
36
|
+
model.solr_reindex reindex_options
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/spec/app/db/test.sqlite3
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunspot_activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Olga Gorun
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-06-19 00:00:00 +03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- Gemfile
|
78
78
|
- README
|
79
79
|
- Rakefile
|
80
|
+
- lib/rake.rb
|
80
81
|
- lib/sunspot_activerecord.rb
|
81
82
|
- lib/sunspot_activerecord/adapters.rb
|
82
83
|
- lib/sunspot_activerecord/searchable.rb
|