Commit fa694deb661d39d8ec20d824b0edbfad2110388a

Authored by Victor Costa
2 parents b76a4336 bda87f25

Merge branch 'master' into rails3_stable

Showing 32 changed files with 359 additions and 305 deletions   Show diff stats
1 --ignore-dir=log 1 --ignore-dir=log
2 --ignore-dir=tmp 2 --ignore-dir=tmp
3 --ignore-dir=pkg 3 --ignore-dir=pkg
  4 +--ignore-dir=public/javascripts/cache
  5 +--ignore-dir=public/stylesheets/cache
plugins/solr/config/solr.yml.dist
@@ -9,18 +9,18 @@ @@ -9,18 +9,18 @@
9 production: 9 production:
10 url: http://127.0.0.1:8983/solr 10 url: http://127.0.0.1:8983/solr
11 jvm_options: -server -Xmx192M -Xms64M 11 jvm_options: -server -Xmx192M -Xms64M
12 - timeout: 0 12 + timeout: 600
13 data_path: /var/lib/noosfero-data/solr/index 13 data_path: /var/lib/noosfero-data/solr/index
14 14
15 development: 15 development:
16 url: http://0.0.0.0:8982/solr 16 url: http://0.0.0.0:8982/solr
17 jvm_options: -server -Xmx128M -Xms16M 17 jvm_options: -server -Xmx128M -Xms16M
18 - timeout: 0 18 + timeout: 600
19 19
20 test: &TEST 20 test: &TEST
21 url: http://0.0.0.0:8981/solr 21 url: http://0.0.0.0:8981/solr
22 jvm_options: -server -Xmx128M -Xms16M 22 jvm_options: -server -Xmx128M -Xms16M
23 - timeout: 0 23 + timeout: 600
24 24
25 cucumber: 25 cucumber:
26 <<: *TEST 26 <<: *TEST
plugins/solr/install.rb
1 -raise "Not ready yet. Some tests are failing." 1 +#raise "Not ready yet. Some tests are failing."
2 require 'rubygems' 2 require 'rubygems'
3 require 'rake' 3 require 'rake'
4 4
plugins/solr/lib/ext/product.rb
@@ -27,7 +27,8 @@ class Product @@ -27,7 +27,8 @@ class Product
27 {:name => {:type => :text, :boost => 2.0}}, 27 {:name => {:type => :text, :boost => 2.0}},
28 {:description => :text}, {:category_full_name => :text}, 28 {:description => :text}, {:category_full_name => :text},
29 # filtered fields 29 # filtered fields
30 - {:solr_plugin_public => :boolean}, {:environment_id => :integer}, 30 + {:solr_plugin_public => :boolean},
  31 + {:environment_id => :integer}, {:profile_id => :integer},
31 {:enabled => :boolean}, {:solr_plugin_category_filter => :integer}, 32 {:enabled => :boolean}, {:solr_plugin_category_filter => :integer},
32 # ordered/query-boosted fields 33 # ordered/query-boosted fields
33 {:solr_plugin_price_sortable => :decimal}, {:solr_plugin_name_sortable => :string}, 34 {:solr_plugin_price_sortable => :decimal}, {:solr_plugin_name_sortable => :string},
plugins/solr/lib/ext/profile.rb
@@ -42,7 +42,7 @@ class Profile @@ -42,7 +42,7 @@ class Profile
42 handle_asynchronously :solr_save 42 handle_asynchronously :solr_save
43 handle_asynchronously :solr_destroy 43 handle_asynchronously :solr_destroy
44 44
45 - class_inheritable_accessor :solr_plugin_extra_index_methods 45 + class_attribute :solr_plugin_extra_index_methods
46 self.solr_plugin_extra_index_methods = [] 46 self.solr_plugin_extra_index_methods = []
47 47
48 def solr_plugin_extra_data_for_index 48 def solr_plugin_extra_data_for_index
plugins/solr/lib/solr_plugin.rb
@@ -33,8 +33,8 @@ class SolrPlugin &lt; Noosfero::Plugin @@ -33,8 +33,8 @@ class SolrPlugin &lt; Noosfero::Plugin
33 33
34 solr_options = solr_options(class_asset(klass), category) 34 solr_options = solr_options(class_asset(klass), category)
35 solr_options[:filter_queries] ||= [] 35 solr_options[:filter_queries] ||= []
36 - solr_options[:filter_queries] += scopes_to_solr_filters scope, klass, options  
37 - solr_options.merge! products_options(user) if klass == Product and empty_query 36 + solr_options[:filter_queries] += scopes_to_solr_options scope, klass, options
  37 + solr_options.merge! products_options(user) if asset == :products and empty_query
38 solr_options.merge! options.except(:category, :filter) 38 solr_options.merge! options.except(:category, :filter)
39 39
40 scope.find_by_contents query, paginate_options, solr_options 40 scope.find_by_contents query, paginate_options, solr_options
@@ -42,14 +42,14 @@ class SolrPlugin &lt; Noosfero::Plugin @@ -42,14 +42,14 @@ class SolrPlugin &lt; Noosfero::Plugin
42 42
43 protected 43 protected
44 44
45 - def scopes_to_solr_filters scope, klass = nil, options = {} 45 + def scopes_to_solr_options scope, klass = nil, options = {}
46 filter_queries = [] 46 filter_queries = []
47 klass ||= scope.base_class 47 klass ||= scope.base_class
48 solr_fields = klass.configuration[:solr_fields].keys 48 solr_fields = klass.configuration[:solr_fields].keys
49 scopes_applied = scope.scopes_applied.dup rescue [] #rescue association and class direct filtering 49 scopes_applied = scope.scopes_applied.dup rescue [] #rescue association and class direct filtering
50 50
51 - scope.current_scoped_methods[:create].each do |attr, value|  
52 - next unless solr_fields.include? attr.to_sym 51 + scope.scope_attributes.each do |attr, value|
  52 + raise "Non-indexed attribute '#{attr}' speficied in scope_attributes" unless solr_fields.include? attr.to_sym
53 53
54 # if the filter is present here, then prefer it 54 # if the filter is present here, then prefer it
55 scopes_applied.reject!{ |name| name == attr.to_sym } 55 scopes_applied.reject!{ |name| name == attr.to_sym }
plugins/solr/vendor/plugins/acts_as_solr_reloaded/.travis.yml
  1 +services:
  2 + - mongodb
  3 +
  4 +language: ruby
  5 +rvm:
  6 + - 1.8.7
  7 +
  8 +before_install:
  9 + - sudo apt-get update
  10 + - sudo apt-get install default-jdk
  11 +
1 before_script: 12 before_script:
2 - mongo mydb_test --eval 'db.addUser("travis", "test");' 13 - mongo mydb_test --eval 'db.addUser("travis", "test");'
3 - gem update --system 1.4.1 > /dev/null 2>&1 14 - gem update --system 1.4.1 > /dev/null 2>&1
4 - rake solr:download 15 - rake solr:download
5 - RAILS_ENV=test rake solr:start 16 - RAILS_ENV=test rake solr:start
6 17
7 -script: "bundle exec rake $TASK --trace" 18 +script:
  19 + - bundle exec rake test --trace
  20 + - bundle exec rake test:functional --trace
8 21
9 -rvm:  
10 - - 1.8.7  
11 -env:  
12 - - TASK=test  
13 - - TASK=test:functional  
plugins/solr/vendor/plugins/acts_as_solr_reloaded/Gemfile
1 -source :rubygems 1 +source 'https://rubygems.org'
2 2
3 gem 'ruby-debug' 3 gem 'ruby-debug'
  4 +gem 'rdoc'
  5 +
  6 +gem 'jeweler'
4 7
5 gem 'rails', '2.3.5' 8 gem 'rails', '2.3.5'
6 9
plugins/solr/vendor/plugins/acts_as_solr_reloaded/Rakefile
1 require 'rubygems' 1 require 'rubygems'
2 require 'rake' 2 require 'rake'
3 require 'rake/testtask' 3 require 'rake/testtask'
4 -require 'rake/rdoctask' 4 +require 'rdoc/task'
5 5
6 ENV['RAILS_ENV'] = "test" 6 ENV['RAILS_ENV'] = "test"
7 require File.expand_path("#{File.dirname(__FILE__)}/config/solr_environment") 7 require File.expand_path("#{File.dirname(__FILE__)}/config/solr_environment")
8 8
9 Dir["#{File.dirname(__FILE__)}/lib/tasks/*.rake"].sort.each { |ext| load ext } 9 Dir["#{File.dirname(__FILE__)}/lib/tasks/*.rake"].sort.each { |ext| load ext }
10 10
11 -desc "Default Task"  
12 -task :default => [:test]  
13 -  
14 -desc "Runs the unit tests"  
15 -task :test => "test:unit"  
16 -  
17 -namespace :test do  
18 - task :setup do  
19 - DB ||= 'sqlite'  
20 - puts "Using " + DB  
21 - %x(mysql -u#{MYSQL_USER} < #{File.dirname(__FILE__) + "/test/fixtures/db_definitions/mysql.sql"}) if DB == 'mysql'  
22 -  
23 - Rake::Task["test:migrate"].invoke  
24 - end  
25 -  
26 - desc 'Measures test coverage using rcov'  
27 - task :rcov => :setup do  
28 - rm_f "coverage"  
29 - rm_f "coverage.data"  
30 - rcov = "rcov --rails --aggregate coverage.data --text-summary -Ilib"  
31 -  
32 - system("#{rcov} --html #{Dir.glob('test/**/*_shoulda.rb').join(' ')}")  
33 - system("open coverage/index.html") if PLATFORM['darwin']  
34 - end  
35 -  
36 - desc 'Runs the functional tests, testing integration with Solr'  
37 - Rake::TestTask.new(:functional => :setup) do |t|  
38 - t.pattern = "test/functional/*_test.rb"  
39 - t.verbose = true  
40 - end  
41 -  
42 - desc "Unit tests"  
43 - Rake::TestTask.new(:unit => :setup) do |t|  
44 - t.libs << 'test/unit'  
45 - t.pattern = "test/unit/*_shoulda.rb"  
46 - t.verbose = true  
47 - end  
48 -end  
49 -  
50 -Rake::RDocTask.new do |rd|  
51 - rd.main = "README.rdoc"  
52 - rd.rdoc_dir = "rdoc"  
53 - rd.rdoc_files.exclude("lib/solr/**/*.rb", "lib/solr.rb")  
54 - rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")  
55 -end  
56 -  
57 -begin  
58 - require 'jeweler'  
59 - Jeweler::Tasks.new do |s|  
60 - s.name = "acts_as_solr_reloaded"  
61 - s.summary = "This gem adds full text search capabilities and many other nifty features from Apache Solr to any Rails model."  
62 - s.email = "dc.rec1@gmail.com"  
63 - s.homepage = "http://github.com/dcrec1/acts_as_solr_reloaded"  
64 - s.description = "This gem adds full text search capabilities and many other nifty features from Apache Solr to any Rails model."  
65 - s.authors = ["Diego Carrion"]  
66 - s.files = FileList["[A-Z]*", "{bin,generators,config,lib,solr}/**/*"] +  
67 - FileList["test/**/*"].reject {|f| f.include?("test/log")}.reject {|f| f.include?("test/tmp")}  
68 - end  
69 -rescue LoadError  
70 - puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"  
71 -end  
plugins/solr/vendor/plugins/acts_as_solr_reloaded/config/solr_environment.rb
@@ -6,23 +6,19 @@ require &#39;net/http&#39; @@ -6,23 +6,19 @@ require &#39;net/http&#39;
6 6
7 dir = File.dirname(__FILE__) 7 dir = File.dirname(__FILE__)
8 SOLR_PATH = File.expand_path("#{dir}/../solr") unless defined? SOLR_PATH 8 SOLR_PATH = File.expand_path("#{dir}/../solr") unless defined? SOLR_PATH
9 -config = YAML::load_file(RAILS_ROOT+'/plugins/solr/config/solr.yml') 9 +config = YAML::load_file("#{Rails.root}/plugins/solr/config/solr.yml")
10 10
11 -unless defined? RAILS_ROOT  
12 - # define RAILS_ROOT for test environment  
13 - RAILS_ROOT = defined?(Rails) ? Rails.root : File.expand_path("#{File.dirname(__FILE__)}/../test")  
14 -end  
15 unless defined? RAILS_ENV 11 unless defined? RAILS_ENV
16 RAILS_ENV = ENV['RAILS_ENV'] 12 RAILS_ENV = ENV['RAILS_ENV']
17 end 13 end
18 unless defined? SOLR_LOGS_PATH 14 unless defined? SOLR_LOGS_PATH
19 - SOLR_LOGS_PATH = ENV["SOLR_LOGS_PATH"] || "#{RAILS_ROOT}/log" 15 + SOLR_LOGS_PATH = ENV["SOLR_LOGS_PATH"] || "#{Rails.root}/log"
20 end 16 end
21 unless defined? SOLR_PIDS_PATH 17 unless defined? SOLR_PIDS_PATH
22 - SOLR_PIDS_PATH = ENV["SOLR_PIDS_PATH"] || "#{RAILS_ROOT}/tmp/pids" 18 + SOLR_PIDS_PATH = ENV["SOLR_PIDS_PATH"] || "#{Rails.root}/tmp/pids"
23 end 19 end
24 unless defined? SOLR_DATA_PATH 20 unless defined? SOLR_DATA_PATH
25 - SOLR_DATA_PATH = ENV["SOLR_DATA_PATH"] || config[ENV['RAILS_ENV']]['data_path'] || "#{RAILS_ROOT}/solr/#{ENV['RAILS_ENV']}" 21 + SOLR_DATA_PATH = ENV["SOLR_DATA_PATH"] || config[ENV['RAILS_ENV']]['data_path'] || "#{Rails.root}/solr/#{ENV['RAILS_ENV']}"
26 end 22 end
27 unless defined? SOLR_CONFIG_PATH 23 unless defined? SOLR_CONFIG_PATH
28 SOLR_CONFIG_PATH = ENV["SOLR_CONFIG_PATH"] || "#{SOLR_PATH}/solr" 24 SOLR_CONFIG_PATH = ENV["SOLR_CONFIG_PATH"] || "#{SOLR_PATH}/solr"
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr.rb
@@ -20,6 +20,7 @@ require File.dirname(__FILE__) + &#39;/acts_as_solr/search_results&#39; @@ -20,6 +20,7 @@ require File.dirname(__FILE__) + &#39;/acts_as_solr/search_results&#39;
20 require File.dirname(__FILE__) + '/acts_as_solr/lazy_document' 20 require File.dirname(__FILE__) + '/acts_as_solr/lazy_document'
21 require File.dirname(__FILE__) + '/acts_as_solr/mongo_mapper' 21 require File.dirname(__FILE__) + '/acts_as_solr/mongo_mapper'
22 require File.dirname(__FILE__) + '/acts_as_solr/post' 22 require File.dirname(__FILE__) + '/acts_as_solr/post'
  23 +require File.dirname(__FILE__) + '/acts_as_solr/scope_with_applied_names'
23 24
24 # reopen ActiveRecord and include the acts_as_solr method 25 # reopen ActiveRecord and include the acts_as_solr method
25 ActiveRecord::Base.extend ActsAsSolr::ActsMethods 26 ActiveRecord::Base.extend ActsAsSolr::ActsMethods
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb
@@ -178,6 +178,8 @@ module ActsAsSolr #:nodoc: @@ -178,6 +178,8 @@ module ActsAsSolr #:nodoc:
178 include CommonMethods 178 include CommonMethods
179 include ParserMethods 179 include ParserMethods
180 180
  181 + attr_accessor :solr_score
  182 +
181 define_solr_configuration_methods 183 define_solr_configuration_methods
182 184
183 acts_as_taggable_on :tags if options[:taggable] 185 acts_as_taggable_on :tags if options[:taggable]
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/common_methods.rb
1 module ActsAsSolr #:nodoc: 1 module ActsAsSolr #:nodoc:
2 - 2 +
3 module CommonMethods 3 module CommonMethods
4 4
5 TypeMapping = { 5 TypeMapping = {
@@ -14,6 +14,7 @@ module ActsAsSolr #:nodoc: @@ -14,6 +14,7 @@ module ActsAsSolr #:nodoc:
14 :range_integer => "ri", 14 :range_integer => "ri",
15 :facet => "facet", 15 :facet => "facet",
16 :text => "t", 16 :text => "t",
  17 + :ngram_text => "nt",
17 } 18 }
18 19
19 # Converts field types into Solr types 20 # Converts field types into Solr types
@@ -39,39 +40,39 @@ module ActsAsSolr #:nodoc: @@ -39,39 +40,39 @@ module ActsAsSolr #:nodoc:
39 result = [result] unless result.is_a?(Array) 40 result = [result] unless result.is_a?(Array)
40 solr_batch_add result 41 solr_batch_add result
41 end 42 end
42 - 43 +
43 # Sends an add command to Solr 44 # Sends an add command to Solr
44 def solr_add(add_xml) 45 def solr_add(add_xml)
45 ActsAsSolr::Post.execute(Solr::Request::AddDocument.new(add_xml)) 46 ActsAsSolr::Post.execute(Solr::Request::AddDocument.new(add_xml))
46 end 47 end
47 - 48 +
48 # Sends the delete command to Solr 49 # Sends the delete command to Solr
49 def solr_delete(solr_ids) 50 def solr_delete(solr_ids)
50 ActsAsSolr::Post.execute(Solr::Request::Delete.new(:id => solr_ids)) 51 ActsAsSolr::Post.execute(Solr::Request::Delete.new(:id => solr_ids))
51 end 52 end
52 - 53 +
53 # Sends the commit command to Solr 54 # Sends the commit command to Solr
54 def solr_commit 55 def solr_commit
55 ActsAsSolr::Post.execute(Solr::Request::Commit.new) 56 ActsAsSolr::Post.execute(Solr::Request::Commit.new)
56 end 57 end
57 - 58 +
58 # Optimizes the Solr index. Solr says: 59 # Optimizes the Solr index. Solr says:
59 - #  
60 - # Optimizations can take nearly ten minutes to run.  
61 - # We are presuming optimizations should be run once following large 60 + #
  61 + # Optimizations can take nearly ten minutes to run.
  62 + # We are presuming optimizations should be run once following large
62 # batch-like updates to the collection and/or once a day. 63 # batch-like updates to the collection and/or once a day.
63 - #  
64 - # One of the solutions for this would be to create a cron job that 64 + #
  65 + # One of the solutions for this would be to create a cron job that
65 # runs every day at midnight and optmizes the index: 66 # runs every day at midnight and optmizes the index:
66 # 0 0 * * * /your_rails_dir/script/runner -e production "Model.solr_optimize" 67 # 0 0 * * * /your_rails_dir/script/runner -e production "Model.solr_optimize"
67 - # 68 + #
68 def solr_optimize 69 def solr_optimize
69 ActsAsSolr::Post.execute(Solr::Request::Optimize.new) 70 ActsAsSolr::Post.execute(Solr::Request::Optimize.new)
70 end 71 end
71 - 72 +
72 # Returns the id for the given instance 73 # Returns the id for the given instance
73 - def record_id(object)  
74 - eval "object.#{object.class.primary_key}" 74 + def record_id object
  75 + object.send object.class.primary_key
75 end 76 end
76 end 77 end
77 end 78 end
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb
@@ -4,12 +4,16 @@ module ActsAsSolr #:nodoc: @@ -4,12 +4,16 @@ module ActsAsSolr #:nodoc:
4 4
5 # Method used by mostly all the ClassMethods when doing a search 5 # Method used by mostly all the ClassMethods when doing a search
6 def parse_query(query=nil, options={}) 6 def parse_query(query=nil, options={})
7 - valid_options = [:models, :lazy, :core, :results_format, :sql_options, 7 + valid_options = [
  8 + :models, :lazy, :core, :results_format, :sql_options,
8 :alternate_query, :boost_functions, :filter_queries, :facets, :sort, 9 :alternate_query, :boost_functions, :filter_queries, :facets, :sort,
9 :scores, :operator, :latitude, :longitude, :radius, :relevance, :highlight, 10 :scores, :operator, :latitude, :longitude, :radius, :relevance, :highlight,
10 - :offset, :per_page, :limit, :page,] 11 + :offset, :per_page, :limit, :page,
  12 + :query_fields, :default_field,
  13 + ]
11 query_options = {} 14 query_options = {}
12 options[:results_format] ||= :objects 15 options[:results_format] ||= :objects
  16 + options[:default_field] ||= 'text'
13 17
14 return if query.nil? 18 return if query.nil?
15 raise "Query should be a string" unless query.is_a?(String) 19 raise "Query should be a string" unless query.is_a?(String)
@@ -49,77 +53,95 @@ module ActsAsSolr #:nodoc: @@ -49,77 +53,95 @@ module ActsAsSolr #:nodoc:
49 query_options[:rows] = per_page 53 query_options[:rows] = per_page
50 query_options[:start] = offset 54 query_options[:start] = offset
51 55
  56 + query_options[:boost_functions] = replace_types([*options[:boost_functions]], '').join(' ') if options[:boost_functions]
  57 +
  58 + parse_facets query_options, options
  59 + parse_highlight query_options, options
  60 + parse_sort query_options, options
  61 + parse_location query_options, options
  62 + parse_query_fields query_options, options
  63 +
52 query_options[:operator] = options[:operator] 64 query_options[:operator] = options[:operator]
  65 + not_dismax = query_options[:operator] == :or
  66 + request = if not_dismax then Solr::Request::Standard.new(query_options) else Solr::Request::Dismax.new query_options end
  67 + ActsAsSolr::Post.execute request, options[:core]
  68 + rescue
  69 + raise "#{$query} There was a problem executing your search\n#{query_options.inspect}\n: #{$!} in #{$!.backtrace.first}"
  70 + end
  71 + end
53 72
54 - query_options[:boost_functions] = replace_types([*options[:boost_functions]], '').join(' ') if options[:boost_functions] 73 + def parse_query_fields query_options, options
  74 + options[:query_fields] ||= []
  75 + query_options[:query_fields] = replace_types([*options[:query_fields]], '').join ' '
  76 + end
  77 +
  78 + def parse_sort query_options, options
  79 + query_options[:sort] = replace_types([*options[:sort]], '')[0] if options[:sort]
  80 + end
55 81
56 - # first steps on the facet parameter processing  
57 - if options[:facets]  
58 - query_options[:facets] = {}  
59 - query_options[:facets][:limit] = -1 # TODO: make this configurable  
60 - query_options[:facets][:sort] = :count if options[:facets][:sort]  
61 - query_options[:facets][:mincount] = 0  
62 - query_options[:facets][:mincount] = 1 if options[:facets][:zeros] == false  
63 - # override the :zeros (it's deprecated anyway) if :mincount exists  
64 - query_options[:facets][:mincount] = options[:facets][:mincount] if options[:facets][:mincount]  
65 - query_options[:facets][:fields] = options[:facets][:fields].map{ |k| "#{k}_facet" } if options[:facets][:fields]  
66 - query_options[:filter_queries] += replace_types([*options[:facets][:browse]]) if options[:facets][:browse]  
67 - query_options[:facets][:queries] = replace_types([*options[:facets][:query]]) if options[:facets][:query]  
68 -  
69 - if options[:facets][:dates]  
70 - query_options[:date_facets] = {}  
71 - # if options[:facets][:dates][:fields] exists then :start, :end, and :gap must be there  
72 - if options[:facets][:dates][:fields]  
73 - [:start, :end, :gap].each { |k| raise "#{k} must be present in faceted date query" unless options[:facets][:dates].include?(k) }  
74 - query_options[:date_facets][:fields] = []  
75 - options[:facets][:dates][:fields].each { |f|  
76 - if f.kind_of? Hash  
77 - key = f.keys[0]  
78 - query_options[:date_facets][:fields] << {"#{key}_d" => f[key]}  
79 - validate_date_facet_other_options(f[key][:other]) if f[key][:other]  
80 - else  
81 - query_options[:date_facets][:fields] << "#{f}_d"  
82 - end  
83 - }  
84 - end  
85 -  
86 - query_options[:date_facets][:start] = options[:facets][:dates][:start] if options[:facets][:dates][:start]  
87 - query_options[:date_facets][:end] = options[:facets][:dates][:end] if options[:facets][:dates][:end]  
88 - query_options[:date_facets][:gap] = options[:facets][:dates][:gap] if options[:facets][:dates][:gap]  
89 - query_options[:date_facets][:hardend] = options[:facets][:dates][:hardend] if options[:facets][:dates][:hardend]  
90 - query_options[:date_facets][:filter] = replace_types([*options[:facets][:dates][:filter]].collect{|k| "#{k.dup.sub!(/ *:(?!\d) */,"_d:")}"}) if options[:facets][:dates][:filter]  
91 -  
92 - if options[:facets][:dates][:other]  
93 - validate_date_facet_other_options(options[:facets][:dates][:other])  
94 - query_options[:date_facets][:other] = options[:facets][:dates][:other]  
95 - end 82 + def parse_location query_options, options
  83 + if options[:radius]
  84 + query_options[:radius] = options[:radius]
  85 + query_options[:filter_queries] << '{!geofilt}'
  86 + end
  87 + query_options[:latitude] = options[:latitude]
  88 + query_options[:longitude] = options[:longitude]
  89 + end
96 90
  91 + def parse_highlight query_options, options
  92 + if options[:highlight]
  93 + query_options[:highlighting] = {}
  94 + query_options[:highlighting][:field_list] = replace_types([*options[:highlight][:fields]], '') if options[:highlight][:fields]
  95 + query_options[:highlighting][:require_field_match] = options[:highlight][:require_field_match] if options[:highlight][:require_field_match]
  96 + query_options[:highlighting][:max_snippets] = options[:highlight][:max_snippets] if options[:highlight][:max_snippets]
  97 + query_options[:highlighting][:prefix] = options[:highlight][:prefix] if options[:highlight][:prefix]
  98 + query_options[:highlighting][:suffix] = options[:highlight][:suffix] if options[:highlight][:suffix]
  99 + end
  100 + end
  101 +
  102 + def parse_facets query_options, options
  103 + # first steps on the facet parameter processing
  104 + if options[:facets]
  105 + query_options[:facets] = {}
  106 + query_options[:facets][:limit] = -1 # TODO: make this configurable
  107 + query_options[:facets][:sort] = :count if options[:facets][:sort]
  108 + query_options[:facets][:mincount] = 0
  109 + query_options[:facets][:mincount] = 1 if options[:facets][:zeros] == false
  110 + # override the :zeros (it's deprecated anyway) if :mincount exists
  111 + query_options[:facets][:mincount] = options[:facets][:mincount] if options[:facets][:mincount]
  112 + query_options[:facets][:fields] = options[:facets][:fields].map{ |k| "#{k}_facet" } if options[:facets][:fields]
  113 + query_options[:filter_queries] += replace_types([*options[:facets][:browse]]) if options[:facets][:browse]
  114 + query_options[:facets][:queries] = replace_types([*options[:facets][:query]]) if options[:facets][:query]
  115 +
  116 + if options[:facets][:dates]
  117 + query_options[:date_facets] = {}
  118 + # if options[:facets][:dates][:fields] exists then :start, :end, and :gap must be there
  119 + if options[:facets][:dates][:fields]
  120 + [:start, :end, :gap].each { |k| raise "#{k} must be present in faceted date query" unless options[:facets][:dates].include?(k) }
  121 + query_options[:date_facets][:fields] = []
  122 + options[:facets][:dates][:fields].each { |f|
  123 + if f.kind_of? Hash
  124 + key = f.keys[0]
  125 + query_options[:date_facets][:fields] << {"#{key}_d" => f[key]}
  126 + validate_date_facet_other_options(f[key][:other]) if f[key][:other]
  127 + else
  128 + query_options[:date_facets][:fields] << "#{f}_d"
  129 + end
  130 + }
97 end 131 end
98 - end  
99 132
100 - if options[:highlight]  
101 - query_options[:highlighting] = {}  
102 - query_options[:highlighting][:field_list] = replace_types([*options[:highlight][:fields]], '') if options[:highlight][:fields]  
103 - query_options[:highlighting][:require_field_match] = options[:highlight][:require_field_match] if options[:highlight][:require_field_match]  
104 - query_options[:highlighting][:max_snippets] = options[:highlight][:max_snippets] if options[:highlight][:max_snippets]  
105 - query_options[:highlighting][:prefix] = options[:highlight][:prefix] if options[:highlight][:prefix]  
106 - query_options[:highlighting][:suffix] = options[:highlight][:suffix] if options[:highlight][:suffix]  
107 - end 133 + query_options[:date_facets][:start] = options[:facets][:dates][:start] if options[:facets][:dates][:start]
  134 + query_options[:date_facets][:end] = options[:facets][:dates][:end] if options[:facets][:dates][:end]
  135 + query_options[:date_facets][:gap] = options[:facets][:dates][:gap] if options[:facets][:dates][:gap]
  136 + query_options[:date_facets][:hardend] = options[:facets][:dates][:hardend] if options[:facets][:dates][:hardend]
  137 + query_options[:date_facets][:filter] = replace_types([*options[:facets][:dates][:filter]].collect{|k| "#{k.dup.sub!(/ *:(?!\d) */,"_d:")}"}) if options[:facets][:dates][:filter]
108 138
109 - query_options[:sort] = replace_types([*options[:sort]], '')[0] if options[:sort] 139 + if options[:facets][:dates][:other]
  140 + validate_date_facet_other_options(options[:facets][:dates][:other])
  141 + query_options[:date_facets][:other] = options[:facets][:dates][:other]
  142 + end
110 143
111 - if options[:radius]  
112 - query_options[:radius] = options[:radius]  
113 - query_options[:filter_queries] << '{!geofilt}'  
114 end 144 end
115 - query_options[:latitude] = options[:latitude]  
116 - query_options[:longitude] = options[:longitude]  
117 -  
118 - not_dismax = query_options[:operator] == :or  
119 - request = not_dismax ? Solr::Request::Standard.new(query_options) : Solr::Request::Dismax.new(query_options)  
120 - ActsAsSolr::Post.execute(request, options[:core])  
121 - rescue  
122 - raise "#{$query} There was a problem executing your search\n#{query_options.inspect}\n: #{$!} in #{$!.backtrace.first}"  
123 end 145 end
124 end 146 end
125 147
@@ -148,21 +170,21 @@ module ActsAsSolr #:nodoc: @@ -148,21 +170,21 @@ module ActsAsSolr #:nodoc:
148 results.update :start => header['params']['start'] 170 results.update :start => header['params']['start']
149 end 171 end
150 172
151 - results.update(:facets => {'facet_fields' => []}) if options[:facets] 173 + results.update(:facets => {'facet_fields' => {}}) if options[:facets]
152 return SearchResults.new(results) if solr_data.total_hits == 0 174 return SearchResults.new(results) if solr_data.total_hits == 0
153 175
154 results.update(:facets => solr_data.data['facet_counts']) if options[:facets] 176 results.update(:facets => solr_data.data['facet_counts']) if options[:facets]
155 177
156 - ids = solr_data.hits.collect {|doc| doc["#{solr_configuration[:primary_key_field]}"]}.flatten  
157 - result = find_objects(ids, options)  
158 - results.update(:docs => result) 178 + ids = solr_data.hits.collect{ |doc| doc["#{solr_configuration[:primary_key_field]}"] }.flatten
  179 + result = find_objects ids, options
  180 + results.update :ids => ids, :docs => result
159 181
160 add_scores(result, solr_data) if options[:results_format] == :objects and options[:scores] 182 add_scores(result, solr_data) if options[:results_format] == :objects and options[:scores]
161 183
162 highlighted = {} 184 highlighted = {}
163 solr_data.highlighting.map do |x,y| 185 solr_data.highlighting.map do |x,y|
164 e={} 186 e={}
165 - y1=y.map{|x1,y1| e[x1.gsub(/_[^_]*/,"")]=y1} unless y.nil? 187 + y.map{ |x1,y1| e[x1.gsub(/_[^_]*/,"")]=y1 } unless y.nil?
166 highlighted[x.gsub(/[^:]*:/,"").to_i]=e 188 highlighted[x.gsub(/[^:]*:/,"").to_i]=e
167 end unless solr_data.highlighting.nil? 189 end unless solr_data.highlighting.nil?
168 results.update(:highlights => highlighted) 190 results.update(:highlights => highlighted)
@@ -179,8 +201,12 @@ module ActsAsSolr #:nodoc: @@ -179,8 +201,12 @@ module ActsAsSolr #:nodoc:
179 ids.collect{ |id| ActsAsSolr::LazyDocument.new(id, self) } 201 ids.collect{ |id| ActsAsSolr::LazyDocument.new(id, self) }
180 elsif options[:results_format] == :objects 202 elsif options[:results_format] == :objects
181 find_options = options[:sql_options] || {} 203 find_options = options[:sql_options] || {}
182 - find_options[:conditions] = self.send :merge_conditions, {self.primary_key => ids}, (find_options[:conditions] || [])  
183 - result = self.all(find_options) || [] 204 + if Rails::VERSION::STRING >= '3.0'
  205 + result = self.scoped(find_options).where(self.primary_key => ids).all
  206 + else
  207 + find_options[:conditions] = self.send :merge_conditions, {self.primary_key => ids}, (find_options[:conditions] || [])
  208 + result = self.all(find_options)
  209 + end
184 result = reorder(result, ids) unless find_options[:order] 210 result = reorder(result, ids) unless find_options[:order]
185 result 211 result
186 elsif options[:results_format] == :none 212 elsif options[:results_format] == :none
@@ -226,22 +252,15 @@ module ActsAsSolr #:nodoc: @@ -226,22 +252,15 @@ module ActsAsSolr #:nodoc:
226 def add_scores(results, solr_data) 252 def add_scores(results, solr_data)
227 with_score = [] 253 with_score = []
228 solr_data.hits.each do |doc| 254 solr_data.hits.each do |doc|
229 - with_score.push([doc["score"],  
230 - results.find {|record| scorable_record?(record, doc) }])  
231 - end  
232 - with_score.each do |score, object|  
233 - class << object; attr_accessor :solr_score; end  
234 - object.solr_score = score 255 + record = results.find do |result|
  256 + doc_id = doc["#{solr_configuration[:primary_key_field]}"].first rescue nil
  257 + record_id(result).to_s == doc_id
  258 + end
  259 + with_score.push [doc["score"], record]
235 end 260 end
236 - end  
237 -  
238 - def scorable_record?(record, doc)  
239 - doc_id = doc["#{solr_configuration[:primary_key_field]}"]  
240 - if doc_id.nil?  
241 - doc_id = doc["id"]  
242 - "#{record.class.name}:#{record_id(record)}" == doc_id.first.to_s  
243 - else  
244 - record_id(record).to_s == doc_id.to_s 261 + with_score.each do |score, record|
  262 + next unless record
  263 + record.solr_score = score
245 end 264 end
246 end 265 end
247 266
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/scope_with_applied_names.rb 0 → 100644
@@ -0,0 +1,91 @@ @@ -0,0 +1,91 @@
  1 +
  2 +if Rails::VERSION::STRING >= "3.2"
  3 + module ::ActiveRecord
  4 +
  5 + class Relation
  6 + attr_accessor :scopes_applied
  7 + end
  8 +
  9 + module Scoping
  10 + module Named
  11 + module ClassMethods
  12 + attr_accessor :scope_name, :scopes_applied
  13 +
  14 + def scope_with_applied_names name, scope_options = {}
  15 + name = name.to_sym
  16 + valid_scope_name?(name)
  17 + extension = Module.new(&Proc.new) if block_given?
  18 +
  19 + scope_proc = lambda do |*args|
  20 + options = scope_options.respond_to?(:call) ? unscoped { scope_options.call(*args) } : scope_options
  21 + options = scoped.apply_finder_options(options) if options.is_a?(Hash)
  22 +
  23 + relation = scoped.merge(options)
  24 + relation.scopes_applied ||= Set.new
  25 + relation.scopes_applied << name
  26 +
  27 + extension ? relation.extending(extension) : relation
  28 + end
  29 +
  30 + singleton_class.send(:redefine_method, name, &scope_proc)
  31 + end
  32 + alias_method_chain :scope, :applied_names
  33 +
  34 + end
  35 + end
  36 + end
  37 + end
  38 +else
  39 + require_dependency 'active_record/named_scope'
  40 +
  41 + module ::ActiveRecord
  42 + module NamedScope
  43 + module ClassMethods
  44 +
  45 + def named_scope_with_applied_names name, options = {}, &block
  46 + named_scope_without_applied_names name, options, &block
  47 +
  48 + name = name.to_sym
  49 + scopes[name] = lambda do |parent_scope, *args|
  50 + scope = Scope.new(parent_scope, case options
  51 + when Hash
  52 + options
  53 + when Proc
  54 + if self.model_name != parent_scope.model_name
  55 + options.bind(parent_scope).call(*args)
  56 + else
  57 + options.call(*args)
  58 + end
  59 + end, &block)
  60 + scope.scope_name = name
  61 + scope
  62 + end
  63 + end
  64 + alias_method_chain :named_scope, :applied_names
  65 + end
  66 +
  67 + class Scope
  68 + attr_accessor :scope_name, :scopes_applied
  69 +
  70 + def initialize_with_applied_names proxy_scope, options, &block
  71 + initialize_without_applied_names proxy_scope, options, &block
  72 + self.scopes_applied ||= []
  73 + self.scopes_applied += proxy_scope.send :scopes_applied if Scope === proxy_scope
  74 +
  75 + # unrelated bugfix: use if instead of unless
  76 + if (Scope === proxy_scope || ActiveRecord::Associations::AssociationCollection === proxy_scope)
  77 + @current_scoped_methods_when_defined = proxy_scope.send(:current_scoped_methods)
  78 + end
  79 + end
  80 + alias_method_chain :initialize, :applied_names
  81 +
  82 + def scope_name= name
  83 + @scope_name = name
  84 + self.scopes_applied << @scope_name
  85 + end
  86 +
  87 + end
  88 +
  89 + end
  90 + end
  91 +end
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/dismax.rb
@@ -12,13 +12,15 @@ @@ -12,13 +12,15 @@
12 12
13 class Solr::Request::Dismax < Solr::Request::Standard 13 class Solr::Request::Dismax < Solr::Request::Standard
14 14
15 - VALID_PARAMS.replace(VALID_PARAMS + [:tie_breaker, :query_fields, :minimum_match, :phrase_fields, :phrase_slop,  
16 - :alternate_query, :boost_query, :boost_functions]) 15 + VALID_PARAMS.replace VALID_PARAMS + [
  16 + :tie_breaker, :query_fields, :minimum_match, :phrase_fields, :phrase_slop,
  17 + :alternate_query, :boost_query, :boost_functions,
  18 + ]
17 19
18 def initialize(params) 20 def initialize(params)
19 super 21 super
20 end 22 end
21 - 23 +
22 def to_hash 24 def to_hash
23 hash = super 25 hash = super
24 hash[:defType] = 'edismax' 26 hash[:defType] = 'edismax'
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/standard.rb
@@ -12,40 +12,42 @@ @@ -12,40 +12,42 @@
12 12
13 class Solr::Request::Standard < Solr::Request::Select 13 class Solr::Request::Standard < Solr::Request::Select
14 14
15 - VALID_PARAMS = [:query, :sort, :default_field, :operator, :start, :rows, :shards, :date_facets,  
16 - :filter_queries, :field_list, :debug_query, :explain_other, :facets, :highlighting, :mlt, :radius,  
17 - :radius, :latitude, :longitude, :spellcheck]  
18 - 15 + VALID_PARAMS = [
  16 + :query, :sort, :default_field, :operator, :start, :rows, :shards, :date_facets,
  17 + :filter_queries, :field_list, :debug_query, :explain_other, :facets, :highlighting, :mlt, :radius,
  18 + :radius, :latitude, :longitude, :spellcheck,
  19 + ]
  20 +
19 def initialize(params) 21 def initialize(params)
20 super 'search' 22 super 'search'
21 -  
22 - raise "Invalid parameters: #{(params.keys - VALID_PARAMS).join(',')}" unless 23 +
  24 + raise "Invalid parameters: #{(params.keys - VALID_PARAMS).join(',')}" unless
23 (params.keys - VALID_PARAMS).empty? 25 (params.keys - VALID_PARAMS).empty?
24 - 26 +
25 raise ":query parameter required" unless params[:query] 27 raise ":query parameter required" unless params[:query]
26 - 28 +
27 @params = params.dup 29 @params = params.dup
28 - 30 +
29 # Validate operator 31 # Validate operator
30 if params[:operator] 32 if params[:operator]
31 - raise "Only :and/:or operators allowed" unless 33 + raise "Only :and/:or operators allowed" unless
32 [:and, :or].include?(params[:operator]) 34 [:and, :or].include?(params[:operator])
33 - 35 +
34 @params[:operator] = params[:operator].to_s.upcase 36 @params[:operator] = params[:operator].to_s.upcase
35 end 37 end
36 38
37 # Validate start, rows can be transformed to ints 39 # Validate start, rows can be transformed to ints
38 @params[:start] = params[:start].to_i if params[:start] 40 @params[:start] = params[:start].to_i if params[:start]
39 @params[:rows] = params[:rows].to_i if params[:rows] 41 @params[:rows] = params[:rows].to_i if params[:rows]
40 - 42 +
41 @params[:field_list] ||= ["*","score"] 43 @params[:field_list] ||= ["*","score"]
42 - 44 +
43 @params[:shards] ||= [] 45 @params[:shards] ||= []
44 end 46 end
45 - 47 +
46 def to_hash 48 def to_hash
47 hash = {} 49 hash = {}
48 - 50 +
49 # standard request param processing 51 # standard request param processing
50 hash[:sort] = @params[:sort] 52 hash[:sort] = @params[:sort]
51 hash[:q] = @params[:query] 53 hash[:q] = @params[:query]
@@ -61,11 +63,11 @@ class Solr::Request::Standard &lt; Solr::Request::Select @@ -61,11 +63,11 @@ class Solr::Request::Standard &lt; Solr::Request::Select
61 hash[:debugQuery] = @params[:debug_query] 63 hash[:debugQuery] = @params[:debug_query]
62 hash[:explainOther] = @params[:explain_other] 64 hash[:explainOther] = @params[:explain_other]
63 hash[:shards] = @params[:shards].join(',') unless @params[:shards].empty? 65 hash[:shards] = @params[:shards].join(',') unless @params[:shards].empty?
64 - 66 +
65 hash[:sfield] = 'latlng' 67 hash[:sfield] = 'latlng'
66 hash[:d] = @params[:radius] 68 hash[:d] = @params[:radius]
67 hash[:pt] = "#{@params[:latitude]}, #{@params[:longitude]}" if @params[:latitude] and @params[:longitude] 69 hash[:pt] = "#{@params[:latitude]}, #{@params[:longitude]}" if @params[:latitude] and @params[:longitude]
68 - 70 +
69 # facet parameter processing 71 # facet parameter processing
70 if @params[:facets] 72 if @params[:facets]
71 # TODO need validation of all that is under the :facets Hash too 73 # TODO need validation of all that is under the :facets Hash too
@@ -95,7 +97,7 @@ class Solr::Request::Standard &lt; Solr::Request::Select @@ -95,7 +97,7 @@ class Solr::Request::Standard &lt; Solr::Request::Select
95 end 97 end
96 end 98 end
97 end 99 end
98 - 100 +
99 if @params[:date_facets] 101 if @params[:date_facets]
100 hash["facet.date"] = [] 102 hash["facet.date"] = []
101 if @params[:date_facets][:fields] 103 if @params[:date_facets][:fields]
@@ -125,7 +127,7 @@ class Solr::Request::Standard &lt; Solr::Request::Select @@ -125,7 +127,7 @@ class Solr::Request::Standard &lt; Solr::Request::Select
125 end 127 end
126 end 128 end
127 end 129 end
128 - 130 +
129 # highlighting parameter processing - http://wiki.apache.org/solr/HighlightingParameters 131 # highlighting parameter processing - http://wiki.apache.org/solr/HighlightingParameters
130 if @params[:highlighting] 132 if @params[:highlighting]
131 hash[:hl] = true 133 hash[:hl] = true
@@ -385,7 +387,7 @@ class Solr::Request::Standard &lt; Solr::Request::Select @@ -385,7 +387,7 @@ class Solr::Request::Standard &lt; Solr::Request::Select
385 end 387 end
386 388
387 end 389 end
388 - 390 +
389 if @params[:mlt] 391 if @params[:mlt]
390 hash[:mlt] = true 392 hash[:mlt] = true
391 hash["mlt.count"] = @params[:mlt][:count] 393 hash["mlt.count"] = @params[:mlt][:count]
@@ -398,10 +400,10 @@ class Solr::Request::Standard &lt; Solr::Request::Select @@ -398,10 +400,10 @@ class Solr::Request::Standard &lt; Solr::Request::Select
398 hash["mlt.maxntp"] = @params[:mlt][:max_tokens_parsed] 400 hash["mlt.maxntp"] = @params[:mlt][:max_tokens_parsed]
399 hash["mlt.boost"] = @params[:mlt][:boost] 401 hash["mlt.boost"] = @params[:mlt][:boost]
400 end 402 end
401 - 403 +
402 hash[:spellcheck] = true 404 hash[:spellcheck] = true
403 hash['spellcheck.collate'] = true 405 hash['spellcheck.collate'] = true
404 - 406 +
405 hash.merge(super.to_hash) 407 hash.merge(super.to_hash)
406 end 408 end
407 409
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/response/ruby.rb
@@ -14,13 +14,14 @@ class Solr::Response::Ruby &lt; Solr::Response::Base @@ -14,13 +14,14 @@ class Solr::Response::Ruby &lt; Solr::Response::Base
14 attr_reader :data, :header 14 attr_reader :data, :header
15 15
16 def initialize(ruby_code) 16 def initialize(ruby_code)
  17 + ruby_code.force_encoding('UTF-8') if RUBY_VERSION >= '1.9'
17 super 18 super
18 begin 19 begin
19 #TODO: what about pulling up data/header/response to ResponseBase, 20 #TODO: what about pulling up data/header/response to ResponseBase,
20 # or maybe a new middle class like SelectResponseBase since 21 # or maybe a new middle class like SelectResponseBase since
21 # all Select queries return this same sort of stuff?? 22 # all Select queries return this same sort of stuff??
22 # XML (&wt=xml) and Ruby (&wt=ruby) responses contain exactly the same structure. 23 # XML (&wt=xml) and Ruby (&wt=ruby) responses contain exactly the same structure.
23 - # a goal of solrb is to make it irrelevant which gets used under the hood, 24 + # a goal of solrb is to make it irrelevant which gets used under the hood,
24 # but favor Ruby responses. 25 # but favor Ruby responses.
25 @data = eval(ruby_code) 26 @data = eval(ruby_code)
26 @header = @data['responseHeader'] 27 @header = @data['responseHeader']
@@ -38,5 +39,5 @@ class Solr::Response::Ruby &lt; Solr::Response::Base @@ -38,5 +39,5 @@ class Solr::Response::Ruby &lt; Solr::Response::Base
38 def query_time 39 def query_time
39 @header['QTime'] 40 @header['QTime']
40 end 41 end
41 - 42 +
42 end 43 end
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/response/xml.rb
@@ -18,7 +18,7 @@ class Solr::Response::Xml &lt; Solr::Response::Base @@ -18,7 +18,7 @@ class Solr::Response::Xml &lt; Solr::Response::Base
18 # parse the xml 18 # parse the xml
19 @doc = REXML::Document.new(xml) 19 @doc = REXML::Document.new(xml)
20 20
21 - # look for the result code and string 21 + # look for the result code and string
22 # <?xml version="1.0" encoding="UTF-8"?> 22 # <?xml version="1.0" encoding="UTF-8"?>
23 # <response> 23 # <response>
24 # <lst name="responseHeader"><int name="status">0</int><int name="QTime">2</int></lst> 24 # <lst name="responseHeader"><int name="status">0</int><int name="QTime">2</int></lst>
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/database.rake
@@ -5,12 +5,12 @@ namespace :db do @@ -5,12 +5,12 @@ namespace :db do
5 begin 5 begin
6 ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "*:*")) 6 ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "*:*"))
7 ActsAsSolr::Post.execute(Solr::Request::Commit.new) 7 ActsAsSolr::Post.execute(Solr::Request::Commit.new)
8 - (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file| 8 + (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(Rails.root, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
9 ActsAsSolr::SolrFixtures.load(File.basename(fixture_file, '.*')) 9 ActsAsSolr::SolrFixtures.load(File.basename(fixture_file, '.*'))
10 - end  
11 - puts "The fixtures loaded have been added to Solr" 10 + end
  11 + puts "The fixtures loaded have been added to Solr"
12 rescue 12 rescue
13 end 13 end
14 end 14 end
15 end 15 end
16 -end  
17 \ No newline at end of file 16 \ No newline at end of file
  17 +end
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/jeweler.rake 0 → 100644
@@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
  1 +begin
  2 + require 'jeweler'
  3 +rescue LoadError
  4 +end
  5 +
  6 +Jeweler::Tasks.new do |s|
  7 + s.name = "acts_as_solr_reloaded"
  8 + s.summary = "This gem adds full text search capabilities and many other nifty features from Apache Solr to any Rails model."
  9 + s.email = "dc.rec1@gmail.com"
  10 + s.homepage = "http://github.com/dcrec1/acts_as_solr_reloaded"
  11 + s.description = "This gem adds full text search capabilities and many other nifty features from Apache Solr to any Rails model."
  12 + s.authors = ["Diego Carrion"]
  13 + s.files = FileList["[A-Z]*", "{bin,generators,config,lib,solr}/**/*"] +
  14 + FileList["test/**/*"].reject {|f| f.include?("test/log")}.reject {|f| f.include?("test/tmp")}
  15 +end if defined? Jeweler
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/rdoc.rake 0 → 100644
@@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
  1 +require 'rake/testtask'
  2 +require 'rdoc/task'
  3 +
  4 +Rake::RDocTask.new do |rd|
  5 + rd.main = "README.rdoc"
  6 + rd.rdoc_dir = "rdoc"
  7 + rd.rdoc_files.exclude("lib/solr/**/*.rb", "lib/solr.rb")
  8 + rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
  9 +end
  10 +
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake
@@ -158,7 +158,7 @@ namespace :solr do @@ -158,7 +158,7 @@ namespace :solr do
158 158
159 logger = ActiveRecord::Base.logger = Logger.new(STDOUT) 159 logger = ActiveRecord::Base.logger = Logger.new(STDOUT)
160 logger.level = ActiveSupport::BufferedLogger::INFO unless debug_output 160 logger.level = ActiveSupport::BufferedLogger::INFO unless debug_output
161 - Dir["#{RAILS_ROOT}/app/models/*.rb"].each{ |file| require file } 161 + Dir["#{Rails.root}/app/models/*.rb"].each{ |file| require file }
162 162
163 if start_server 163 if start_server
164 puts "Starting Solr server..." 164 puts "Starting Solr server..."
plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/test.rake
@@ -1,5 +0,0 @@ @@ -1,5 +0,0 @@
1 -namespace :test do  
2 - task :migrate do  
3 - ActiveRecord::Migrator.migrate("test/db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)  
4 - end  
5 -end  
plugins/solr/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/schema.xml
@@ -57,11 +57,9 @@ @@ -57,11 +57,9 @@
57 <fieldType name="text" class="solr.TextField" autoGeneratePhraseQueries="false"> 57 <fieldType name="text" class="solr.TextField" autoGeneratePhraseQueries="false">
58 <analyzer type="index"> 58 <analyzer type="index">
59 <tokenizer class="solr.StandardTokenizerFactory"/> 59 <tokenizer class="solr.StandardTokenizerFactory"/>
60 - <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>  
61 -  
62 <filter class="solr.ASCIIFoldingFilterFactory"/> 60 <filter class="solr.ASCIIFoldingFilterFactory"/>
63 <filter class="solr.LowerCaseFilterFactory"/> 61 <filter class="solr.LowerCaseFilterFactory"/>
64 - 62 + <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
65 <filter class="solr.StopFilterFactory" words="stopwords.pt.txt" /> 63 <filter class="solr.StopFilterFactory" words="stopwords.pt.txt" />
66 64
67 <!-- stemming 65 <!-- stemming
@@ -73,18 +71,12 @@ @@ -73,18 +71,12 @@
73 <filter class="solr.HunspellStemFilterFactory" dictionary="en_US.dic" affix="en_US.aff" ignoreCase="true" /> 71 <filter class="solr.HunspellStemFilterFactory" dictionary="en_US.dic" affix="en_US.aff" ignoreCase="true" />
74 <filter class="solr.HunspellStemFilterFactory" dictionary="pt_PT.dic" affix="pt_PT.aff" ignoreCase="true" /> 72 <filter class="solr.HunspellStemFilterFactory" dictionary="pt_PT.dic" affix="pt_PT.aff" ignoreCase="true" />
75 --> 73 -->
76 -  
77 - <!-- improvised stemming  
78 - <filter class="solr.EdgeNGramFilterFactory" minGramSize="3" maxGramSize="20" side="front"/>  
79 - -->  
80 </analyzer> 74 </analyzer>
81 <analyzer type="query"> 75 <analyzer type="query">
82 <tokenizer class="solr.StandardTokenizerFactory"/> 76 <tokenizer class="solr.StandardTokenizerFactory"/>
83 - <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>  
84 -  
85 <filter class="solr.ASCIIFoldingFilterFactory"/> 77 <filter class="solr.ASCIIFoldingFilterFactory"/>
86 <filter class="solr.LowerCaseFilterFactory"/> 78 <filter class="solr.LowerCaseFilterFactory"/>
87 - 79 + <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
88 <filter class="solr.StopFilterFactory" words="stopwords.pt.txt" /> 80 <filter class="solr.StopFilterFactory" words="stopwords.pt.txt" />
89 81
90 <!-- stemming 82 <!-- stemming
@@ -96,10 +88,23 @@ @@ -96,10 +88,23 @@
96 <filter class="solr.HunspellStemFilterFactory" dictionary="en_US.dic" affix="en_US.aff" ignoreCase="true" /> 88 <filter class="solr.HunspellStemFilterFactory" dictionary="en_US.dic" affix="en_US.aff" ignoreCase="true" />
97 <filter class="solr.HunspellStemFilterFactory" dictionary="pt_PT.dic" affix="pt_PT.aff" ignoreCase="true" /> 89 <filter class="solr.HunspellStemFilterFactory" dictionary="pt_PT.dic" affix="pt_PT.aff" ignoreCase="true" />
98 --> 90 -->
  91 + </analyzer>
  92 + </fieldType>
99 93
100 - <!-- improvised stemming  
101 - <filter class="solr.EdgeNGramFilterFactory" minGramSize="3" maxGramSize="20" side="front"/>  
102 - --> 94 + <fieldType name="ngramText" class="solr.TextField" positionIncrementGap="100">
  95 + <analyzer type="index">
  96 + <tokenizer class="solr.StandardTokenizerFactory"/>
  97 + <filter class="solr.ASCIIFoldingFilterFactory"/>
  98 + <filter class="solr.LowerCaseFilterFactory"/>
  99 + <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
  100 +
  101 + <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="20" side="front"/>
  102 + </analyzer>
  103 + <analyzer type="query">
  104 + <tokenizer class="solr.StandardTokenizerFactory"/>
  105 + <filter class="solr.ASCIIFoldingFilterFactory"/>
  106 + <filter class="solr.LowerCaseFilterFactory"/>
  107 + <filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
103 </analyzer> 108 </analyzer>
104 </fieldType> 109 </fieldType>
105 110
@@ -151,6 +156,7 @@ @@ -151,6 +156,7 @@
151 <dynamicField name="*sortable_do" type="sdouble" indexed="true" stored="false" multiValued="false"/> 156 <dynamicField name="*sortable_do" type="sdouble" indexed="true" stored="false" multiValued="false"/>
152 157
153 <dynamicField name="*_t" type="text" indexed="true" stored="true" multiValued="true"/> 158 <dynamicField name="*_t" type="text" indexed="true" stored="true" multiValued="true"/>
  159 + <dynamicField name="*_nt" type="ngramText" indexed="true" stored="true" multiValued="true"/>
154 <dynamicField name="*_s" type="text" indexed="true" stored="true" multiValued="false"/> 160 <dynamicField name="*_s" type="text" indexed="true" stored="true" multiValued="false"/>
155 <dynamicField name="*_i" type="integer" indexed="true" stored="false" multiValued="true"/> 161 <dynamicField name="*_i" type="integer" indexed="true" stored="false" multiValued="true"/>
156 <dynamicField name="*_f" type="float" indexed="true" stored="true" multiValued="false"/> 162 <dynamicField name="*_f" type="float" indexed="true" stored="true" multiValued="false"/>
@@ -168,6 +174,7 @@ @@ -168,6 +174,7 @@
168 <field name="geo_distance" type="sdouble"/> <!-- Optional but used for distributed searching --> 174 <field name="geo_distance" type="sdouble"/> <!-- Optional but used for distributed searching -->
169 175
170 <field name="text" type="text" indexed="true" stored="false" multiValued="true"/> 176 <field name="text" type="text" indexed="true" stored="false" multiValued="true"/>
  177 + <field name="ngramText" type="ngramText" indexed="true" stored="false" multiValued="true"/>
171 <field name="spell" type="textSpell" indexed="true" stored="true" multiValued="true"/> 178 <field name="spell" type="textSpell" indexed="true" stored="true" multiValued="true"/>
172 179
173 <dynamicField name="*_s_mv" type="string" indexed="true" stored="false" multiValued="true"/> 180 <dynamicField name="*_s_mv" type="string" indexed="true" stored="false" multiValued="true"/>
@@ -187,6 +194,10 @@ @@ -187,6 +194,10 @@
187 <copyField source="*_do" dest="text"/> 194 <copyField source="*_do" dest="text"/>
188 <copyField source="*_facet" dest="text"/> 195 <copyField source="*_facet" dest="text"/>
189 196
  197 + <copyField source="*_s" dest="ngramText"/>
  198 + <copyField source="*_t" dest="ngramText"/>
  199 + <copyField source="*_nt" dest="ngramText"/>
  200 +
190 <copyField source="*_s" dest="spell"/> 201 <copyField source="*_s" dest="spell"/>
191 <copyField source="*_t" dest="spell"/> 202 <copyField source="*_t" dest="spell"/>
192 <copyField source="*_facet" dest="spell"/> 203 <copyField source="*_facet" dest="spell"/>
plugins/solr/vendor/plugins/acts_as_solr_reloaded/solr_test_rakefile.rb
@@ -2,5 +2,4 @@ require &#39;rubygems&#39; @@ -2,5 +2,4 @@ require &#39;rubygems&#39;
2 require 'rake' 2 require 'rake'
3 dir = File.dirname(__FILE__) 3 dir = File.dirname(__FILE__)
4 $:.unshift("#{dir}/lib") 4 $:.unshift("#{dir}/lib")
5 -RAILS_ROOT = dir  
6 require "acts_as_solr/tasks" 5 require "acts_as_solr/tasks"
plugins/solr/vendor/plugins/acts_as_solr_reloaded/test/fixtures/locals.yml 0 → 100644
@@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
  1 +home:
  2 + id: 1
  3 + longitude: -77.4027
  4 + latitude: 39.36
  5 +
  6 +work:
  7 + id: 2
  8 + longitude: -77.4027
  9 + latitude: 38.36
plugins/solr/vendor/plugins/acts_as_solr_reloaded/test/test_helper.rb
@@ -16,7 +16,7 @@ require &#39;mongo_mapper&#39; @@ -16,7 +16,7 @@ require &#39;mongo_mapper&#39;
16 16
17 class Rails 17 class Rails
18 def self.root 18 def self.root
19 - RAILS_ROOT 19 + Rails.root
20 end 20 end
21 21
22 def self.env 22 def self.env
@@ -26,13 +26,14 @@ end @@ -26,13 +26,14 @@ end
26 26
27 MongoMapper.database = "acts_as_solr_reloaded-test" 27 MongoMapper.database = "acts_as_solr_reloaded-test"
28 28
29 -RAILS_ROOT = File.dirname(__FILE__) unless defined? RAILS_ROOT  
30 -RAILS_ENV = 'test' unless defined? RAILS_ENV 29 +RAILS_ENV = 'test' unless defined? RAILS_ENV
31 ENV["RAILS_ENV"] = "test" 30 ENV["RAILS_ENV"] = "test"
32 31
33 require File.expand_path(File.dirname(__FILE__) + '/../config/solr_environment') 32 require File.expand_path(File.dirname(__FILE__) + '/../config/solr_environment')
34 require File.expand_path(File.dirname(__FILE__) + '/../lib/acts_as_solr') 33 require File.expand_path(File.dirname(__FILE__) + '/../lib/acts_as_solr')
35 34
  35 +ActiveRecord::Base.logger = Logger.new('/dev/null')
  36 +
36 # Load Models 37 # Load Models
37 models_dir = File.join(File.dirname( __FILE__ ), 'models') 38 models_dir = File.join(File.dirname( __FILE__ ), 'models')
38 require "#{models_dir}/book.rb" 39 require "#{models_dir}/book.rb"
@@ -60,10 +61,10 @@ class Test::Unit::TestCase @@ -60,10 +61,10 @@ class Test::Unit::TestCase
60 klass = instance_eval table_name.to_s.capitalize.singularize 61 klass = instance_eval table_name.to_s.capitalize.singularize
61 klass.find(:all).each{|content| content.solr_save} 62 klass.find(:all).each{|content| content.solr_save}
62 end 63 end
63 - 64 +
64 clear_from_solr(:novels) 65 clear_from_solr(:novels)
65 end 66 end
66 - 67 +
67 private 68 private
68 def self.clear_from_solr(table_name) 69 def self.clear_from_solr(table_name)
69 ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "type_s:#{table_name.to_s.capitalize.singularize}")) 70 ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "type_s:#{table_name.to_s.capitalize.singularize}"))
plugins/solr/vendor/plugins/named_scope_with_applied_names/init.rb
@@ -1,57 +0,0 @@ @@ -1,57 +0,0 @@
1 -require_dependency 'active_record/named_scope'  
2 -  
3 -if Rails::VERSION::STRING < "2.3.99"  
4 -  
5 - module ::ActiveRecord  
6 -  
7 - module NamedScope  
8 -  
9 - module ClassMethods  
10 -  
11 - def named_scope_with_applied_names name, options = {}, &block  
12 - named_scope_without_applied_names name, options, &block  
13 -  
14 - name = name.to_sym  
15 - scopes[name] = lambda do |parent_scope, *args|  
16 - scope = Scope.new(parent_scope, case options  
17 - when Hash  
18 - options  
19 - when Proc  
20 - if self.model_name != parent_scope.model_name  
21 - options.bind(parent_scope).call(*args)  
22 - else  
23 - options.call(*args)  
24 - end  
25 - end, &block)  
26 - scope.scope_name = name  
27 - scope  
28 - end  
29 - end  
30 - alias_method_chain :named_scope, :applied_names  
31 - end  
32 -  
33 - class Scope  
34 - attr_accessor :scope_name, :scopes_applied  
35 -  
36 - def initialize_with_applied_names proxy_scope, options, &block  
37 - initialize_without_applied_names proxy_scope, options, &block  
38 - self.scopes_applied ||= []  
39 - self.scopes_applied += proxy_scope.send :scopes_applied if Scope === proxy_scope  
40 -  
41 - # unrelated bugfix: use if instead of unless  
42 - if (Scope === proxy_scope || ActiveRecord::Associations::AssociationCollection === proxy_scope)  
43 - @current_scoped_methods_when_defined = proxy_scope.send(:current_scoped_methods)  
44 - end  
45 - end  
46 - alias_method_chain :initialize, :applied_names  
47 -  
48 - def scope_name= name  
49 - @scope_name = name  
50 - self.scopes_applied << @scope_name  
51 - end  
52 -  
53 - end  
54 -  
55 - end  
56 - end  
57 -end  
script/noosfero-plugins
@@ -6,7 +6,9 @@ program_name=$(basename $0) @@ -6,7 +6,9 @@ program_name=$(basename $0)
6 6
7 if [ -e /etc/default/noosfero ]; then 7 if [ -e /etc/default/noosfero ]; then
8 . /etc/default/noosfero 8 . /etc/default/noosfero
9 -else 9 +fi
  10 +
  11 +if [ -z "$NOOSFERO_DIR"]; then
10 this_script=$(readlink -f $0) 12 this_script=$(readlink -f $0)
11 NOOSFERO_DIR=$(dirname $this_script | xargs dirname) 13 NOOSFERO_DIR=$(dirname $this_script | xargs dirname)
12 fi 14 fi
test/functional/account_controller_test.rb
@@ -648,7 +648,7 @@ class AccountControllerTest &lt; ActionController::TestCase @@ -648,7 +648,7 @@ class AccountControllerTest &lt; ActionController::TestCase
648 :image => fixture_file_upload('/files/rails.png', 'image/png') 648 :image => fixture_file_upload('/files/rails.png', 'image/png')
649 } 649 }
650 650
651 - assert_response :successs 651 + assert_response :success
652 652
653 person = Person["testuser"] 653 person = Person["testuser"]
654 assert_equal "rails.png", person.image.filename 654 assert_equal "rails.png", person.image.filename
test/unit/article_test.rb
@@ -1077,10 +1077,11 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1077,10 +1077,11 @@ class ArticleTest &lt; ActiveSupport::TestCase
1077 end 1077 end
1078 1078
1079 should 'create the notification to organization and all organization members' do 1079 should 'create the notification to organization and all organization members' do
  1080 + Profile.delete_all
1080 ActionTracker::Record.delete_all 1081 ActionTracker::Record.delete_all
1081 1082
1082 community = fast_create(Community) 1083 community = fast_create(Community)
1083 - member_1 = Person.first 1084 + member_1 = fast_create(Person)
1084 community.add_member(member_1) 1085 community.add_member(member_1)
1085 1086
1086 article = create TinyMceArticle, :name => 'Tracked Article 1', :profile_id => community.id 1087 article = create TinyMceArticle, :name => 'Tracked Article 1', :profile_id => community.id