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 CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
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
@@ -1,3 +1,3 @@
1
1
  module SunspotActiverecord
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
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-04-25 00:00:00 +03:00
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