diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/.travis.yml b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/.travis.yml index 45f3335..5457e50 100644 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/.travis.yml +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/.travis.yml @@ -1,13 +1,21 @@ +services: + - mongodb + +language: ruby +rvm: + - 1.8.7 + +before_install: + - sudo apt-get update + - sudo apt-get install default-jdk + before_script: - mongo mydb_test --eval 'db.addUser("travis", "test");' - gem update --system 1.4.1 > /dev/null 2>&1 - rake solr:download - RAILS_ENV=test rake solr:start -script: "bundle exec rake $TASK --trace" +script: + - bundle exec rake test --trace + - bundle exec rake test:functional --trace -rvm: - - 1.8.7 -env: - - TASK=test - - TASK=test:functional diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/Gemfile b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/Gemfile index 9caafb8..409d345 100644 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/Gemfile +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/Gemfile @@ -1,6 +1,9 @@ -source :rubygems +source 'https://rubygems.org' gem 'ruby-debug' +gem 'rdoc' + +gem 'jeweler' gem 'rails', '2.3.5' diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/Rakefile b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/Rakefile index cc29d3c..31f261d 100644 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/Rakefile +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/Rakefile @@ -1,71 +1,10 @@ require 'rubygems' require 'rake' require 'rake/testtask' -require 'rake/rdoctask' +require 'rdoc/task' ENV['RAILS_ENV'] = "test" require File.expand_path("#{File.dirname(__FILE__)}/config/solr_environment") Dir["#{File.dirname(__FILE__)}/lib/tasks/*.rake"].sort.each { |ext| load ext } -desc "Default Task" -task :default => [:test] - -desc "Runs the unit tests" -task :test => "test:unit" - -namespace :test do - task :setup do - DB ||= 'sqlite' - puts "Using " + DB - %x(mysql -u#{MYSQL_USER} < #{File.dirname(__FILE__) + "/test/fixtures/db_definitions/mysql.sql"}) if DB == 'mysql' - - Rake::Task["test:migrate"].invoke - end - - desc 'Measures test coverage using rcov' - task :rcov => :setup do - rm_f "coverage" - rm_f "coverage.data" - rcov = "rcov --rails --aggregate coverage.data --text-summary -Ilib" - - system("#{rcov} --html #{Dir.glob('test/**/*_shoulda.rb').join(' ')}") - system("open coverage/index.html") if PLATFORM['darwin'] - end - - desc 'Runs the functional tests, testing integration with Solr' - Rake::TestTask.new(:functional => :setup) do |t| - t.pattern = "test/functional/*_test.rb" - t.verbose = true - end - - desc "Unit tests" - Rake::TestTask.new(:unit => :setup) do |t| - t.libs << 'test/unit' - t.pattern = "test/unit/*_shoulda.rb" - t.verbose = true - end -end - -Rake::RDocTask.new do |rd| - rd.main = "README.rdoc" - rd.rdoc_dir = "rdoc" - rd.rdoc_files.exclude("lib/solr/**/*.rb", "lib/solr.rb") - rd.rdoc_files.include("README.rdoc", "lib/**/*.rb") -end - -begin - require 'jeweler' - Jeweler::Tasks.new do |s| - s.name = "acts_as_solr_reloaded" - s.summary = "This gem adds full text search capabilities and many other nifty features from Apache Solr to any Rails model." - s.email = "dc.rec1@gmail.com" - s.homepage = "http://github.com/dcrec1/acts_as_solr_reloaded" - s.description = "This gem adds full text search capabilities and many other nifty features from Apache Solr to any Rails model." - s.authors = ["Diego Carrion"] - s.files = FileList["[A-Z]*", "{bin,generators,config,lib,solr}/**/*"] + - FileList["test/**/*"].reject {|f| f.include?("test/log")}.reject {|f| f.include?("test/tmp")} - end -rescue LoadError - puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler" -end diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/config/solr_environment.rb b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/config/solr_environment.rb index 20b98ea..640093e 100644 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/config/solr_environment.rb +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/config/solr_environment.rb @@ -6,23 +6,19 @@ require 'net/http' dir = File.dirname(__FILE__) SOLR_PATH = File.expand_path("#{dir}/../solr") unless defined? SOLR_PATH -config = YAML::load_file(RAILS_ROOT+'/plugins/solr/config/solr.yml') +config = YAML::load_file("#{Rails.root}/plugins/solr/config/solr.yml") -unless defined? RAILS_ROOT - # define RAILS_ROOT for test environment - RAILS_ROOT = defined?(Rails) ? Rails.root : File.expand_path("#{File.dirname(__FILE__)}/../test") -end unless defined? RAILS_ENV RAILS_ENV = ENV['RAILS_ENV'] end unless defined? SOLR_LOGS_PATH - SOLR_LOGS_PATH = ENV["SOLR_LOGS_PATH"] || "#{RAILS_ROOT}/log" + SOLR_LOGS_PATH = ENV["SOLR_LOGS_PATH"] || "#{Rails.root}/log" end unless defined? SOLR_PIDS_PATH - SOLR_PIDS_PATH = ENV["SOLR_PIDS_PATH"] || "#{RAILS_ROOT}/tmp/pids" + SOLR_PIDS_PATH = ENV["SOLR_PIDS_PATH"] || "#{Rails.root}/tmp/pids" end unless defined? SOLR_DATA_PATH - SOLR_DATA_PATH = ENV["SOLR_DATA_PATH"] || config[ENV['RAILS_ENV']]['data_path'] || "#{RAILS_ROOT}/solr/#{ENV['RAILS_ENV']}" + SOLR_DATA_PATH = ENV["SOLR_DATA_PATH"] || config[ENV['RAILS_ENV']]['data_path'] || "#{Rails.root}/solr/#{ENV['RAILS_ENV']}" end unless defined? SOLR_CONFIG_PATH SOLR_CONFIG_PATH = ENV["SOLR_CONFIG_PATH"] || "#{SOLR_PATH}/solr" diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr.rb b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr.rb index 468a47f..d12a8c4 100644 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr.rb +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr.rb @@ -20,6 +20,7 @@ require File.dirname(__FILE__) + '/acts_as_solr/search_results' require File.dirname(__FILE__) + '/acts_as_solr/lazy_document' require File.dirname(__FILE__) + '/acts_as_solr/mongo_mapper' require File.dirname(__FILE__) + '/acts_as_solr/post' +require File.dirname(__FILE__) + '/acts_as_solr/scope_with_applied_names' # reopen ActiveRecord and include the acts_as_solr method ActiveRecord::Base.extend ActsAsSolr::ActsMethods diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb index 0455ff7..fe1e58b 100644 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb @@ -178,6 +178,8 @@ module ActsAsSolr #:nodoc: include CommonMethods include ParserMethods + attr_accessor :solr_score + define_solr_configuration_methods acts_as_taggable_on :tags if options[:taggable] diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/common_methods.rb b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/common_methods.rb index d2cceaa..709f3e8 100644 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/common_methods.rb +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/common_methods.rb @@ -1,5 +1,5 @@ module ActsAsSolr #:nodoc: - + module CommonMethods TypeMapping = { @@ -14,6 +14,7 @@ module ActsAsSolr #:nodoc: :range_integer => "ri", :facet => "facet", :text => "t", + :ngram_text => "nt", } # Converts field types into Solr types @@ -39,39 +40,39 @@ module ActsAsSolr #:nodoc: result = [result] unless result.is_a?(Array) solr_batch_add result end - + # Sends an add command to Solr def solr_add(add_xml) ActsAsSolr::Post.execute(Solr::Request::AddDocument.new(add_xml)) end - + # Sends the delete command to Solr def solr_delete(solr_ids) ActsAsSolr::Post.execute(Solr::Request::Delete.new(:id => solr_ids)) end - + # Sends the commit command to Solr def solr_commit ActsAsSolr::Post.execute(Solr::Request::Commit.new) end - + # Optimizes the Solr index. Solr says: - # - # Optimizations can take nearly ten minutes to run. - # We are presuming optimizations should be run once following large + # + # Optimizations can take nearly ten minutes to run. + # We are presuming optimizations should be run once following large # batch-like updates to the collection and/or once a day. - # - # One of the solutions for this would be to create a cron job that + # + # One of the solutions for this would be to create a cron job that # runs every day at midnight and optmizes the index: # 0 0 * * * /your_rails_dir/script/runner -e production "Model.solr_optimize" - # + # def solr_optimize ActsAsSolr::Post.execute(Solr::Request::Optimize.new) end - + # Returns the id for the given instance - def record_id(object) - eval "object.#{object.class.primary_key}" + def record_id object + object.send object.class.primary_key end end end diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb index aeac654..37af994 100644 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb @@ -4,12 +4,16 @@ module ActsAsSolr #:nodoc: # Method used by mostly all the ClassMethods when doing a search def parse_query(query=nil, options={}) - valid_options = [:models, :lazy, :core, :results_format, :sql_options, + valid_options = [ + :models, :lazy, :core, :results_format, :sql_options, :alternate_query, :boost_functions, :filter_queries, :facets, :sort, :scores, :operator, :latitude, :longitude, :radius, :relevance, :highlight, - :offset, :per_page, :limit, :page,] + :offset, :per_page, :limit, :page, + :query_fields, :default_field, + ] query_options = {} options[:results_format] ||= :objects + options[:default_field] ||= 'text' return if query.nil? raise "Query should be a string" unless query.is_a?(String) @@ -49,77 +53,95 @@ module ActsAsSolr #:nodoc: query_options[:rows] = per_page query_options[:start] = offset + query_options[:boost_functions] = replace_types([*options[:boost_functions]], '').join(' ') if options[:boost_functions] + + parse_facets query_options, options + parse_highlight query_options, options + parse_sort query_options, options + parse_location query_options, options + parse_query_fields query_options, options + query_options[:operator] = options[:operator] + not_dismax = query_options[:operator] == :or + request = if not_dismax then Solr::Request::Standard.new(query_options) else Solr::Request::Dismax.new query_options end + ActsAsSolr::Post.execute request, options[:core] + rescue + raise "#{$query} There was a problem executing your search\n#{query_options.inspect}\n: #{$!} in #{$!.backtrace.first}" + end + end - query_options[:boost_functions] = replace_types([*options[:boost_functions]], '').join(' ') if options[:boost_functions] + def parse_query_fields query_options, options + options[:query_fields] ||= [] + query_options[:query_fields] = replace_types([*options[:query_fields]], '').join ' ' + end + + def parse_sort query_options, options + query_options[:sort] = replace_types([*options[:sort]], '')[0] if options[:sort] + end - # first steps on the facet parameter processing - if options[:facets] - query_options[:facets] = {} - query_options[:facets][:limit] = -1 # TODO: make this configurable - query_options[:facets][:sort] = :count if options[:facets][:sort] - query_options[:facets][:mincount] = 0 - query_options[:facets][:mincount] = 1 if options[:facets][:zeros] == false - # override the :zeros (it's deprecated anyway) if :mincount exists - query_options[:facets][:mincount] = options[:facets][:mincount] if options[:facets][:mincount] - query_options[:facets][:fields] = options[:facets][:fields].map{ |k| "#{k}_facet" } if options[:facets][:fields] - query_options[:filter_queries] += replace_types([*options[:facets][:browse]]) if options[:facets][:browse] - query_options[:facets][:queries] = replace_types([*options[:facets][:query]]) if options[:facets][:query] - - if options[:facets][:dates] - query_options[:date_facets] = {} - # if options[:facets][:dates][:fields] exists then :start, :end, and :gap must be there - if options[:facets][:dates][:fields] - [:start, :end, :gap].each { |k| raise "#{k} must be present in faceted date query" unless options[:facets][:dates].include?(k) } - query_options[:date_facets][:fields] = [] - options[:facets][:dates][:fields].each { |f| - if f.kind_of? Hash - key = f.keys[0] - query_options[:date_facets][:fields] << {"#{key}_d" => f[key]} - validate_date_facet_other_options(f[key][:other]) if f[key][:other] - else - query_options[:date_facets][:fields] << "#{f}_d" - end - } - end - - query_options[:date_facets][:start] = options[:facets][:dates][:start] if options[:facets][:dates][:start] - query_options[:date_facets][:end] = options[:facets][:dates][:end] if options[:facets][:dates][:end] - query_options[:date_facets][:gap] = options[:facets][:dates][:gap] if options[:facets][:dates][:gap] - query_options[:date_facets][:hardend] = options[:facets][:dates][:hardend] if options[:facets][:dates][:hardend] - query_options[:date_facets][:filter] = replace_types([*options[:facets][:dates][:filter]].collect{|k| "#{k.dup.sub!(/ *:(?!\d) */,"_d:")}"}) if options[:facets][:dates][:filter] - - if options[:facets][:dates][:other] - validate_date_facet_other_options(options[:facets][:dates][:other]) - query_options[:date_facets][:other] = options[:facets][:dates][:other] - end + def parse_location query_options, options + if options[:radius] + query_options[:radius] = options[:radius] + query_options[:filter_queries] << '{!geofilt}' + end + query_options[:latitude] = options[:latitude] + query_options[:longitude] = options[:longitude] + end + def parse_highlight query_options, options + if options[:highlight] + query_options[:highlighting] = {} + query_options[:highlighting][:field_list] = replace_types([*options[:highlight][:fields]], '') if options[:highlight][:fields] + query_options[:highlighting][:require_field_match] = options[:highlight][:require_field_match] if options[:highlight][:require_field_match] + query_options[:highlighting][:max_snippets] = options[:highlight][:max_snippets] if options[:highlight][:max_snippets] + query_options[:highlighting][:prefix] = options[:highlight][:prefix] if options[:highlight][:prefix] + query_options[:highlighting][:suffix] = options[:highlight][:suffix] if options[:highlight][:suffix] + end + end + + def parse_facets query_options, options + # first steps on the facet parameter processing + if options[:facets] + query_options[:facets] = {} + query_options[:facets][:limit] = -1 # TODO: make this configurable + query_options[:facets][:sort] = :count if options[:facets][:sort] + query_options[:facets][:mincount] = 0 + query_options[:facets][:mincount] = 1 if options[:facets][:zeros] == false + # override the :zeros (it's deprecated anyway) if :mincount exists + query_options[:facets][:mincount] = options[:facets][:mincount] if options[:facets][:mincount] + query_options[:facets][:fields] = options[:facets][:fields].map{ |k| "#{k}_facet" } if options[:facets][:fields] + query_options[:filter_queries] += replace_types([*options[:facets][:browse]]) if options[:facets][:browse] + query_options[:facets][:queries] = replace_types([*options[:facets][:query]]) if options[:facets][:query] + + if options[:facets][:dates] + query_options[:date_facets] = {} + # if options[:facets][:dates][:fields] exists then :start, :end, and :gap must be there + if options[:facets][:dates][:fields] + [:start, :end, :gap].each { |k| raise "#{k} must be present in faceted date query" unless options[:facets][:dates].include?(k) } + query_options[:date_facets][:fields] = [] + options[:facets][:dates][:fields].each { |f| + if f.kind_of? Hash + key = f.keys[0] + query_options[:date_facets][:fields] << {"#{key}_d" => f[key]} + validate_date_facet_other_options(f[key][:other]) if f[key][:other] + else + query_options[:date_facets][:fields] << "#{f}_d" + end + } end - end - if options[:highlight] - query_options[:highlighting] = {} - query_options[:highlighting][:field_list] = replace_types([*options[:highlight][:fields]], '') if options[:highlight][:fields] - query_options[:highlighting][:require_field_match] = options[:highlight][:require_field_match] if options[:highlight][:require_field_match] - query_options[:highlighting][:max_snippets] = options[:highlight][:max_snippets] if options[:highlight][:max_snippets] - query_options[:highlighting][:prefix] = options[:highlight][:prefix] if options[:highlight][:prefix] - query_options[:highlighting][:suffix] = options[:highlight][:suffix] if options[:highlight][:suffix] - end + query_options[:date_facets][:start] = options[:facets][:dates][:start] if options[:facets][:dates][:start] + query_options[:date_facets][:end] = options[:facets][:dates][:end] if options[:facets][:dates][:end] + query_options[:date_facets][:gap] = options[:facets][:dates][:gap] if options[:facets][:dates][:gap] + query_options[:date_facets][:hardend] = options[:facets][:dates][:hardend] if options[:facets][:dates][:hardend] + query_options[:date_facets][:filter] = replace_types([*options[:facets][:dates][:filter]].collect{|k| "#{k.dup.sub!(/ *:(?!\d) */,"_d:")}"}) if options[:facets][:dates][:filter] - query_options[:sort] = replace_types([*options[:sort]], '')[0] if options[:sort] + if options[:facets][:dates][:other] + validate_date_facet_other_options(options[:facets][:dates][:other]) + query_options[:date_facets][:other] = options[:facets][:dates][:other] + end - if options[:radius] - query_options[:radius] = options[:radius] - query_options[:filter_queries] << '{!geofilt}' end - query_options[:latitude] = options[:latitude] - query_options[:longitude] = options[:longitude] - - not_dismax = query_options[:operator] == :or - request = not_dismax ? Solr::Request::Standard.new(query_options) : Solr::Request::Dismax.new(query_options) - ActsAsSolr::Post.execute(request, options[:core]) - rescue - raise "#{$query} There was a problem executing your search\n#{query_options.inspect}\n: #{$!} in #{$!.backtrace.first}" end end @@ -148,21 +170,21 @@ module ActsAsSolr #:nodoc: results.update :start => header['params']['start'] end - results.update(:facets => {'facet_fields' => []}) if options[:facets] + results.update(:facets => {'facet_fields' => {}}) if options[:facets] return SearchResults.new(results) if solr_data.total_hits == 0 results.update(:facets => solr_data.data['facet_counts']) if options[:facets] - ids = solr_data.hits.collect {|doc| doc["#{solr_configuration[:primary_key_field]}"]}.flatten - result = find_objects(ids, options) - results.update(:docs => result) + ids = solr_data.hits.collect{ |doc| doc["#{solr_configuration[:primary_key_field]}"] }.flatten + result = find_objects ids, options + results.update :ids => ids, :docs => result add_scores(result, solr_data) if options[:results_format] == :objects and options[:scores] highlighted = {} solr_data.highlighting.map do |x,y| e={} - y1=y.map{|x1,y1| e[x1.gsub(/_[^_]*/,"")]=y1} unless y.nil? + y.map{ |x1,y1| e[x1.gsub(/_[^_]*/,"")]=y1 } unless y.nil? highlighted[x.gsub(/[^:]*:/,"").to_i]=e end unless solr_data.highlighting.nil? results.update(:highlights => highlighted) @@ -179,8 +201,12 @@ module ActsAsSolr #:nodoc: ids.collect{ |id| ActsAsSolr::LazyDocument.new(id, self) } elsif options[:results_format] == :objects find_options = options[:sql_options] || {} - find_options[:conditions] = self.send :merge_conditions, {self.primary_key => ids}, (find_options[:conditions] || []) - result = self.all(find_options) || [] + if Rails::VERSION::STRING >= '3.0' + result = self.scoped(find_options).where(self.primary_key => ids).all + else + find_options[:conditions] = self.send :merge_conditions, {self.primary_key => ids}, (find_options[:conditions] || []) + result = self.all(find_options) + end result = reorder(result, ids) unless find_options[:order] result elsif options[:results_format] == :none @@ -226,22 +252,15 @@ module ActsAsSolr #:nodoc: def add_scores(results, solr_data) with_score = [] solr_data.hits.each do |doc| - with_score.push([doc["score"], - results.find {|record| scorable_record?(record, doc) }]) - end - with_score.each do |score, object| - class << object; attr_accessor :solr_score; end - object.solr_score = score + record = results.find do |result| + doc_id = doc["#{solr_configuration[:primary_key_field]}"].first rescue nil + record_id(result).to_s == doc_id + end + with_score.push [doc["score"], record] end - end - - def scorable_record?(record, doc) - doc_id = doc["#{solr_configuration[:primary_key_field]}"] - if doc_id.nil? - doc_id = doc["id"] - "#{record.class.name}:#{record_id(record)}" == doc_id.first.to_s - else - record_id(record).to_s == doc_id.to_s + with_score.each do |score, record| + next unless record + record.solr_score = score end end diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/scope_with_applied_names.rb b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/scope_with_applied_names.rb new file mode 100644 index 0000000..ccac40a --- /dev/null +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/scope_with_applied_names.rb @@ -0,0 +1,91 @@ + +if Rails::VERSION::STRING >= "3.2" + module ::ActiveRecord + + class Relation + attr_accessor :scopes_applied + end + + module Scoping + module Named + module ClassMethods + attr_accessor :scope_name, :scopes_applied + + def scope_with_applied_names name, scope_options = {} + name = name.to_sym + valid_scope_name?(name) + extension = Module.new(&Proc.new) if block_given? + + scope_proc = lambda do |*args| + options = scope_options.respond_to?(:call) ? unscoped { scope_options.call(*args) } : scope_options + options = scoped.apply_finder_options(options) if options.is_a?(Hash) + + relation = scoped.merge(options) + relation.scopes_applied ||= Set.new + relation.scopes_applied << name + + extension ? relation.extending(extension) : relation + end + + singleton_class.send(:redefine_method, name, &scope_proc) + end + alias_method_chain :scope, :applied_names + + end + end + end + end +else + require_dependency 'active_record/named_scope' + + module ::ActiveRecord + module NamedScope + module ClassMethods + + def named_scope_with_applied_names name, options = {}, &block + named_scope_without_applied_names name, options, &block + + name = name.to_sym + scopes[name] = lambda do |parent_scope, *args| + scope = Scope.new(parent_scope, case options + when Hash + options + when Proc + if self.model_name != parent_scope.model_name + options.bind(parent_scope).call(*args) + else + options.call(*args) + end + end, &block) + scope.scope_name = name + scope + end + end + alias_method_chain :named_scope, :applied_names + end + + class Scope + attr_accessor :scope_name, :scopes_applied + + def initialize_with_applied_names proxy_scope, options, &block + initialize_without_applied_names proxy_scope, options, &block + self.scopes_applied ||= [] + self.scopes_applied += proxy_scope.send :scopes_applied if Scope === proxy_scope + + # unrelated bugfix: use if instead of unless + if (Scope === proxy_scope || ActiveRecord::Associations::AssociationCollection === proxy_scope) + @current_scoped_methods_when_defined = proxy_scope.send(:current_scoped_methods) + end + end + alias_method_chain :initialize, :applied_names + + def scope_name= name + @scope_name = name + self.scopes_applied << @scope_name + end + + end + + end + end +end diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/dismax.rb b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/dismax.rb index 7c8ba66..371aa8a 100644 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/dismax.rb +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/dismax.rb @@ -12,13 +12,15 @@ class Solr::Request::Dismax < Solr::Request::Standard - VALID_PARAMS.replace(VALID_PARAMS + [:tie_breaker, :query_fields, :minimum_match, :phrase_fields, :phrase_slop, - :alternate_query, :boost_query, :boost_functions]) + VALID_PARAMS.replace VALID_PARAMS + [ + :tie_breaker, :query_fields, :minimum_match, :phrase_fields, :phrase_slop, + :alternate_query, :boost_query, :boost_functions, + ] def initialize(params) super end - + def to_hash hash = super hash[:defType] = 'edismax' diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/standard.rb b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/standard.rb index 4209f95..82b8aab 100755 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/standard.rb +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/standard.rb @@ -12,40 +12,42 @@ class Solr::Request::Standard < Solr::Request::Select - VALID_PARAMS = [:query, :sort, :default_field, :operator, :start, :rows, :shards, :date_facets, - :filter_queries, :field_list, :debug_query, :explain_other, :facets, :highlighting, :mlt, :radius, - :radius, :latitude, :longitude, :spellcheck] - + VALID_PARAMS = [ + :query, :sort, :default_field, :operator, :start, :rows, :shards, :date_facets, + :filter_queries, :field_list, :debug_query, :explain_other, :facets, :highlighting, :mlt, :radius, + :radius, :latitude, :longitude, :spellcheck, + ] + def initialize(params) super 'search' - - raise "Invalid parameters: #{(params.keys - VALID_PARAMS).join(',')}" unless + + raise "Invalid parameters: #{(params.keys - VALID_PARAMS).join(',')}" unless (params.keys - VALID_PARAMS).empty? - + raise ":query parameter required" unless params[:query] - + @params = params.dup - + # Validate operator if params[:operator] - raise "Only :and/:or operators allowed" unless + raise "Only :and/:or operators allowed" unless [:and, :or].include?(params[:operator]) - + @params[:operator] = params[:operator].to_s.upcase end # Validate start, rows can be transformed to ints @params[:start] = params[:start].to_i if params[:start] @params[:rows] = params[:rows].to_i if params[:rows] - + @params[:field_list] ||= ["*","score"] - + @params[:shards] ||= [] end - + def to_hash hash = {} - + # standard request param processing hash[:sort] = @params[:sort] hash[:q] = @params[:query] @@ -61,11 +63,11 @@ class Solr::Request::Standard < Solr::Request::Select hash[:debugQuery] = @params[:debug_query] hash[:explainOther] = @params[:explain_other] hash[:shards] = @params[:shards].join(',') unless @params[:shards].empty? - + hash[:sfield] = 'latlng' hash[:d] = @params[:radius] hash[:pt] = "#{@params[:latitude]}, #{@params[:longitude]}" if @params[:latitude] and @params[:longitude] - + # facet parameter processing if @params[:facets] # TODO need validation of all that is under the :facets Hash too @@ -95,7 +97,7 @@ class Solr::Request::Standard < Solr::Request::Select end end end - + if @params[:date_facets] hash["facet.date"] = [] if @params[:date_facets][:fields] @@ -125,7 +127,7 @@ class Solr::Request::Standard < Solr::Request::Select end end end - + # highlighting parameter processing - http://wiki.apache.org/solr/HighlightingParameters if @params[:highlighting] hash[:hl] = true @@ -385,7 +387,7 @@ class Solr::Request::Standard < Solr::Request::Select end end - + if @params[:mlt] hash[:mlt] = true hash["mlt.count"] = @params[:mlt][:count] @@ -398,10 +400,10 @@ class Solr::Request::Standard < Solr::Request::Select hash["mlt.maxntp"] = @params[:mlt][:max_tokens_parsed] hash["mlt.boost"] = @params[:mlt][:boost] end - + hash[:spellcheck] = true hash['spellcheck.collate'] = true - + hash.merge(super.to_hash) end diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/response/ruby.rb b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/response/ruby.rb index 05424c1..46f8c42 100644 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/response/ruby.rb +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/response/ruby.rb @@ -14,13 +14,14 @@ class Solr::Response::Ruby < Solr::Response::Base attr_reader :data, :header def initialize(ruby_code) + ruby_code.force_encoding('UTF-8') if RUBY_VERSION >= '1.9' super begin #TODO: what about pulling up data/header/response to ResponseBase, # or maybe a new middle class like SelectResponseBase since # all Select queries return this same sort of stuff?? # XML (&wt=xml) and Ruby (&wt=ruby) responses contain exactly the same structure. - # a goal of solrb is to make it irrelevant which gets used under the hood, + # a goal of solrb is to make it irrelevant which gets used under the hood, # but favor Ruby responses. @data = eval(ruby_code) @header = @data['responseHeader'] @@ -38,5 +39,5 @@ class Solr::Response::Ruby < Solr::Response::Base def query_time @header['QTime'] end - + end diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/response/xml.rb b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/response/xml.rb index 1fff3ed..f4f48dc 100644 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/response/xml.rb +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/solr/response/xml.rb @@ -18,7 +18,7 @@ class Solr::Response::Xml < Solr::Response::Base # parse the xml @doc = REXML::Document.new(xml) - # look for the result code and string + # look for the result code and string # # # 02 diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/database.rake b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/database.rake index ea63419..2c3ae27 100644 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/database.rake +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/database.rake @@ -5,12 +5,12 @@ namespace :db do begin ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "*:*")) ActsAsSolr::Post.execute(Solr::Request::Commit.new) - (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file| + (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(Rails.root, 'test', 'fixtures', '*.{yml,csv}'))).each do |fixture_file| ActsAsSolr::SolrFixtures.load(File.basename(fixture_file, '.*')) - end - puts "The fixtures loaded have been added to Solr" + end + puts "The fixtures loaded have been added to Solr" rescue end end end -end \ No newline at end of file +end diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/jeweler.rake b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/jeweler.rake new file mode 100644 index 0000000..de235b8 --- /dev/null +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/jeweler.rake @@ -0,0 +1,15 @@ +begin + require 'jeweler' +rescue LoadError +end + +Jeweler::Tasks.new do |s| + s.name = "acts_as_solr_reloaded" + s.summary = "This gem adds full text search capabilities and many other nifty features from Apache Solr to any Rails model." + s.email = "dc.rec1@gmail.com" + s.homepage = "http://github.com/dcrec1/acts_as_solr_reloaded" + s.description = "This gem adds full text search capabilities and many other nifty features from Apache Solr to any Rails model." + s.authors = ["Diego Carrion"] + s.files = FileList["[A-Z]*", "{bin,generators,config,lib,solr}/**/*"] + + FileList["test/**/*"].reject {|f| f.include?("test/log")}.reject {|f| f.include?("test/tmp")} +end if defined? Jeweler diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/rdoc.rake b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/rdoc.rake new file mode 100644 index 0000000..e24ca21 --- /dev/null +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/rdoc.rake @@ -0,0 +1,10 @@ +require 'rake/testtask' +require 'rdoc/task' + +Rake::RDocTask.new do |rd| + rd.main = "README.rdoc" + rd.rdoc_dir = "rdoc" + rd.rdoc_files.exclude("lib/solr/**/*.rb", "lib/solr.rb") + rd.rdoc_files.include("README.rdoc", "lib/**/*.rb") +end + diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake index b51d858..6a6e120 100644 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake @@ -158,7 +158,7 @@ namespace :solr do logger = ActiveRecord::Base.logger = Logger.new(STDOUT) logger.level = ActiveSupport::BufferedLogger::INFO unless debug_output - Dir["#{RAILS_ROOT}/app/models/*.rb"].each{ |file| require file } + Dir["#{Rails.root}/app/models/*.rb"].each{ |file| require file } if start_server puts "Starting Solr server..." diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/test.rake b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/test.rake index c1c420b..e4201ea 100644 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/test.rake +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/lib/tasks/test.rake @@ -1,5 +1,45 @@ + +desc "Default Task" +task :default => [:test] + +desc "Runs the unit tests" +task :test => "test:unit" + namespace :test do + task :migrate do + ActiveRecord::Base.logger = Logger.new(STDOUT) ActiveRecord::Migrator.migrate("test/db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) end + + task :setup do + DB ||= 'sqlite' + puts "Using " + DB + %x(mysql -u#{MYSQL_USER} < #{File.dirname(__FILE__) + "/test/fixtures/db_definitions/mysql.sql"}) if DB == 'mysql' + + Rake::Task["test:migrate"].invoke + end + + desc 'Measures test coverage using rcov' + task :rcov => :setup do + rm_f "coverage" + rm_f "coverage.data" + rcov = "rcov --rails --aggregate coverage.data --text-summary -Ilib" + + system("#{rcov} --html #{Dir.glob('test/**/*_shoulda.rb').join(' ')}") + system("open coverage/index.html") if PLATFORM['darwin'] + end + + desc 'Runs the functional tests, testing integration with Solr' + Rake::TestTask.new(:functional => :setup) do |t| + t.pattern = "test/functional/*_test.rb" + t.verbose = true + end + + desc "Unit tests" + Rake::TestTask.new(:unit => :setup) do |t| + t.libs << 'test/unit' + t.pattern = "test/unit/*_shoulda.rb" + t.verbose = true + end end diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/schema.xml b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/schema.xml index c2b75c6..949bac2 100644 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/schema.xml +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/schema.xml @@ -57,11 +57,9 @@ - - - + - - - - - + + + - + + + + + + + + + + + + + + @@ -151,6 +156,7 @@ + @@ -168,6 +174,7 @@ + @@ -187,6 +194,10 @@ + + + + diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/solr_test_rakefile.rb b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/solr_test_rakefile.rb index 8f711f5..8b92cb6 100644 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/solr_test_rakefile.rb +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/solr_test_rakefile.rb @@ -2,5 +2,4 @@ require 'rubygems' require 'rake' dir = File.dirname(__FILE__) $:.unshift("#{dir}/lib") -RAILS_ROOT = dir require "acts_as_solr/tasks" diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/test/fixtures/locals.yml b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/test/fixtures/locals.yml new file mode 100644 index 0000000..eddf888 --- /dev/null +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/test/fixtures/locals.yml @@ -0,0 +1,9 @@ +home: + id: 1 + longitude: -77.4027 + latitude: 39.36 + +work: + id: 2 + longitude: -77.4027 + latitude: 38.36 diff --git a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/test/test_helper.rb b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/test/test_helper.rb index 66be519..3199fbf 100644 --- a/plugins/solr/vendor/plugins/acts_as_solr_reloaded/test/test_helper.rb +++ b/plugins/solr/vendor/plugins/acts_as_solr_reloaded/test/test_helper.rb @@ -16,7 +16,7 @@ require 'mongo_mapper' class Rails def self.root - RAILS_ROOT + Rails.root end def self.env @@ -26,13 +26,14 @@ end MongoMapper.database = "acts_as_solr_reloaded-test" -RAILS_ROOT = File.dirname(__FILE__) unless defined? RAILS_ROOT -RAILS_ENV = 'test' unless defined? RAILS_ENV +RAILS_ENV = 'test' unless defined? RAILS_ENV ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + '/../config/solr_environment') require File.expand_path(File.dirname(__FILE__) + '/../lib/acts_as_solr') +ActiveRecord::Base.logger = Logger.new('/dev/null') + # Load Models models_dir = File.join(File.dirname( __FILE__ ), 'models') require "#{models_dir}/book.rb" @@ -60,10 +61,10 @@ class Test::Unit::TestCase klass = instance_eval table_name.to_s.capitalize.singularize klass.find(:all).each{|content| content.solr_save} end - + clear_from_solr(:novels) end - + private def self.clear_from_solr(table_name) ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "type_s:#{table_name.to_s.capitalize.singularize}")) diff --git a/plugins/solr/vendor/plugins/named_scope_with_applied_names/init.rb b/plugins/solr/vendor/plugins/named_scope_with_applied_names/init.rb deleted file mode 100644 index 7dac14a..0000000 --- a/plugins/solr/vendor/plugins/named_scope_with_applied_names/init.rb +++ /dev/null @@ -1,57 +0,0 @@ -require_dependency 'active_record/named_scope' - -if Rails::VERSION::STRING < "2.3.99" - - module ::ActiveRecord - - module NamedScope - - module ClassMethods - - def named_scope_with_applied_names name, options = {}, &block - named_scope_without_applied_names name, options, &block - - name = name.to_sym - scopes[name] = lambda do |parent_scope, *args| - scope = Scope.new(parent_scope, case options - when Hash - options - when Proc - if self.model_name != parent_scope.model_name - options.bind(parent_scope).call(*args) - else - options.call(*args) - end - end, &block) - scope.scope_name = name - scope - end - end - alias_method_chain :named_scope, :applied_names - end - - class Scope - attr_accessor :scope_name, :scopes_applied - - def initialize_with_applied_names proxy_scope, options, &block - initialize_without_applied_names proxy_scope, options, &block - self.scopes_applied ||= [] - self.scopes_applied += proxy_scope.send :scopes_applied if Scope === proxy_scope - - # unrelated bugfix: use if instead of unless - if (Scope === proxy_scope || ActiveRecord::Associations::AssociationCollection === proxy_scope) - @current_scoped_methods_when_defined = proxy_scope.send(:current_scoped_methods) - end - end - alias_method_chain :initialize, :applied_names - - def scope_name= name - @scope_name = name - self.scopes_applied << @scope_name - end - - end - - end - end -end -- libgit2 0.21.2