diff --git a/vendor/plugins/acts_as_solr_reloaded/.gitignore b/vendor/plugins/acts_as_solr_reloaded/.gitignore index 95c7b4a..c4b827f 100644 --- a/vendor/plugins/acts_as_solr_reloaded/.gitignore +++ b/vendor/plugins/acts_as_solr_reloaded/.gitignore @@ -11,6 +11,10 @@ solr/start.jar solr/webapps/ solr/solr/data/* +Gemfile.lock +test/solr +test/tmp + acts_as_solr_reloaded-*.gem *.log *.log diff --git a/vendor/plugins/acts_as_solr_reloaded/.travis.yml b/vendor/plugins/acts_as_solr_reloaded/.travis.yml new file mode 100644 index 0000000..45f3335 --- /dev/null +++ b/vendor/plugins/acts_as_solr_reloaded/.travis.yml @@ -0,0 +1,13 @@ +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" + +rvm: + - 1.8.7 +env: + - TASK=test + - TASK=test:functional diff --git a/vendor/plugins/acts_as_solr_reloaded/Gemfile b/vendor/plugins/acts_as_solr_reloaded/Gemfile new file mode 100644 index 0000000..9caafb8 --- /dev/null +++ b/vendor/plugins/acts_as_solr_reloaded/Gemfile @@ -0,0 +1,13 @@ +source :rubygems + +gem 'ruby-debug' + +gem 'rails', '2.3.5' + +gem 'sqlite3' + +gem 'mongo_mapper', '0.7.6' +gem 'bson_ext', '1.0' + +gem 'mocha' +gem 'thoughtbot-shoulda' diff --git a/vendor/plugins/acts_as_solr_reloaded/README.markdown b/vendor/plugins/acts_as_solr_reloaded/README.markdown index 2bdd8f9..7935f59 100644 --- a/vendor/plugins/acts_as_solr_reloaded/README.markdown +++ b/vendor/plugins/acts_as_solr_reloaded/README.markdown @@ -1,3 +1,5 @@ +[![Build status](https://secure.travis-ci.org/coletivoEITA/acts_as_solr_reloaded.png?branch=master)](http://travis-ci.org/coletivoEITA/acts_as_solr_reloaded) + Description ====== This plugin adds full text search capabilities and many other nifty features from Apache's [Solr](http://lucene.apache.org/solr/) to any Rails model. @@ -6,6 +8,8 @@ It was based on the first draft by Erik Hatcher. This plugin is intended for use in old versions of Rails. For newer versions, I strongly advice using Sunspot! Nevertheless, this plugin is used for Noosfero project in production. Any problem please open an issue. +It should support Rails 2.1 (and greater 2.x) and is developed latest Solr versions, so don't expect it to run on older Solr. + Installation ====== diff --git a/vendor/plugins/acts_as_solr_reloaded/Rakefile b/vendor/plugins/acts_as_solr_reloaded/Rakefile index 18b5a86..cc29d3c 100644 --- a/vendor/plugins/acts_as_solr_reloaded/Rakefile +++ b/vendor/plugins/acts_as_solr_reloaded/Rakefile @@ -3,6 +3,9 @@ require 'rake' require 'rake/testtask' require 'rake/rdoctask' +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" @@ -13,10 +16,7 @@ task :test => "test:unit" namespace :test do task :setup do - RAILS_ROOT = File.expand_path("#{File.dirname(__FILE__)}/test") unless defined? RAILS_ROOT - ENV['RAILS_ENV'] = "test" - ENV["ACTS_AS_SOLR_TEST"] = "true" - require File.expand_path("#{File.dirname(__FILE__)}/config/solr_environment") + DB ||= 'sqlite' puts "Using " + DB %x(mysql -u#{MYSQL_USER} < #{File.dirname(__FILE__) + "/test/fixtures/db_definitions/mysql.sql"}) if DB == 'mysql' @@ -34,13 +34,13 @@ namespace :test do end desc 'Runs the functional tests, testing integration with Solr' - Rake::TestTask.new('functional' => :setup) do |t| + Rake::TestTask.new(:functional => :setup) do |t| t.pattern = "test/functional/*_test.rb" t.verbose = true end desc "Unit tests" - Rake::TestTask.new(:unit) do |t| + Rake::TestTask.new(:unit => :setup) do |t| t.libs << 'test/unit' t.pattern = "test/unit/*_shoulda.rb" t.verbose = true diff --git a/vendor/plugins/acts_as_solr_reloaded/TESTING_THE_PLUGIN b/vendor/plugins/acts_as_solr_reloaded/TESTING_THE_PLUGIN index 2404a55..804583f 100644 --- a/vendor/plugins/acts_as_solr_reloaded/TESTING_THE_PLUGIN +++ b/vendor/plugins/acts_as_solr_reloaded/TESTING_THE_PLUGIN @@ -1,22 +1,18 @@ acts_as_solr comes with a quick and fast unit test suite, and with a longer-running functional test suite, the latter testing the actual integration with Solr. -The unit test suite is written using Shoulda, so make sure you have a recent version -installed. +== Install dependencies +sudo apt-get install mongodb-server +bundle install +gem update --system 1.4.1 -Running `rake test` or just `rake` will run both test suites. Use `rake test:unit` to -just run the unit test suite. - -== How to run functional tests for this plugin: +== Running test To run the acts_as_solr's plugin tests run the following steps: -- create a MySQL database called "actsassolr_test" (if you want to use MySQL) +- RAILS_ENV=test rake solr:start -- create a new Rails project, if needed (the plugin can only be tested from within a Rails project); move/checkout acts_as_solr into its vendor/plugins/, as usual - -- copy vendor/plugins/acts_as_solr_reloaded/config/solr.yml to config/ (the Rails config folder) - -- rake solr:start RAILS_ENV=test +- rake test:unit +(or just rake test) - rake test:functional (Accepts the following arguments: DB=sqlite|mysql and MYSQL_USER=user) diff --git a/vendor/plugins/acts_as_solr_reloaded/config/solr_environment.rb b/vendor/plugins/acts_as_solr_reloaded/config/solr_environment.rb index 1c9dbbc..7c69d11 100644 --- a/vendor/plugins/acts_as_solr_reloaded/config/solr_environment.rb +++ b/vendor/plugins/acts_as_solr_reloaded/config/solr_environment.rb @@ -1,13 +1,18 @@ -ENV['RAILS_ENV'] = (ENV['RAILS_ENV'] || 'development').dup +ENV['RAILS_ENV'] = (ENV['RAILS_ENV'] || 'development').dup require "uri" require "fileutils" require "yaml" +require 'net/http' + dir = File.dirname(__FILE__) SOLR_PATH = File.expand_path("#{dir}/../solr") unless defined? SOLR_PATH -# RAILS_ROOT isn't defined yet, so figure it out. unless defined? RAILS_ROOT - RAILS_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../test") + # 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" @@ -35,9 +40,10 @@ end SOLR_JVM_OPTIONS = config[ENV['RAILS_ENV']]['jvm_options'] unless defined? SOLR_JVM_OPTIONS -if ENV["ACTS_AS_SOLR_TEST"] - require "activerecord" +if ENV["RAILS_ENV"] == 'test' + require "active_record" DB = (ENV['DB'] ? ENV['DB'] : 'sqlite') unless defined?(DB) MYSQL_USER = (ENV['MYSQL_USER'].nil? ? 'root' : ENV['MYSQL_USER']) unless defined? MYSQL_USER require File.join(File.dirname(File.expand_path(__FILE__)), '..', 'test', 'db', 'connections', DB, 'connection.rb') end + diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb index c0ee086..a5d6ad2 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb @@ -262,6 +262,7 @@ module ActsAsSolr #:nodoc: def process_solr_options(options={}, solr_options={}) self.configuration = { :fields => nil, + :format => :objects, :additional_fields => nil, :dynamic_attributes => false, :exclude_fields => [], @@ -279,6 +280,7 @@ module ActsAsSolr #:nodoc: :default_boost => 1.0, } + solr_options ||= {} raise "Invalid options: #{(options.keys-configuration.keys).join(',')}" unless (options.keys-configuration.keys).empty? raise "Invalid solr options: #{(solr_options.keys-solr_configuration.keys).join(',')}" unless (solr_options.keys-solr_configuration.keys).empty? @@ -366,7 +368,7 @@ module ActsAsSolr #:nodoc: column_type = format_column_type(column.type) case column_type - when :string then :text + when :string then :string when :datetime then :date when :time then :date else column_type diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/class_methods.rb b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/class_methods.rb index c0eb4c3..1f05edd 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/class_methods.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/class_methods.rb @@ -24,9 +24,9 @@ module ActsAsSolr #:nodoc: # # Book.find_by_solr 'ruby', :filter_queries => ['price:5'] # - # order:: - Orders (sort by) the result set using a given criteria: + # sort:: - Orders (sort by) the result set using a given criteria: # - # Book.find_by_solr 'ruby', :order => 'description asc' + # Book.find_by_solr 'ruby', :sort => 'description asc' # # field_types:: This option is deprecated and will be obsolete by version 1.0. # There's no need to specify the :field_types anymore when doing a @@ -156,9 +156,8 @@ module ActsAsSolr #:nodoc: # => 0.12321548 # def multi_solr_search(query, options = {}) - models = multi_model_suffix(options) options.update(:results_format => :objects) unless options[:results_format] - data = parse_query(query, options, models) + data = parse_query(query, options) if data.nil? or data.total_hits == 0 return SearchResults.new(:docs => [], :total => 0) @@ -184,12 +183,6 @@ module ActsAsSolr #:nodoc: result end - def multi_model_suffix(options) - models = "AND (#{solr_configuration[:type_field]}:\"#{self.name}\"" - models << " OR " + options[:models].collect {|m| "#{solr_configuration[:type_field]}:\"" + m.to_s + "\""}.join(" OR ") if options[:models].is_a?(Array) - models << ")" - end - # returns the total number of documents found in the query specified: # Book.count_by_solr 'rails' => 3 # diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/deprecation.rb b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/deprecation.rb index a6343f0..80ccba6 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/deprecation.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/deprecation.rb @@ -29,7 +29,7 @@ module ActsAsSolr #:nodoc: "The field types are automatically traced back when you specify a field type in your model." end if options[:sort_by] - plog "The option :sort_by is deprecated, use :order instead!" + plog "The option :sort_by is deprecated, use :sort instead!" options[:sort] ||= options[:sort_by] end if options[:start] diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/instance_methods.rb b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/instance_methods.rb index e6dcf6a..2c2ca35 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/instance_methods.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/instance_methods.rb @@ -51,7 +51,7 @@ module ActsAsSolr #:nodoc: field_type = get_solr_field_type(options[:type]) solr_name = options[:as] || field_name - value = self.send("#{field_name}_for_solr") + value = self.send("#{field_name}_for_solr") rescue nil next if value.nil? suffix = get_solr_field_type(field_type) @@ -60,7 +60,7 @@ module ActsAsSolr #:nodoc: field = Solr::Field.new(:name => "#{solr_name}_#{suffix}", :value => value) processed_boost = validate_boost(field_boost) - field.boost = processed_boost if processed_boost != solr_configuration[:default_boost] + field.boost = processed_boost doc << field end @@ -81,8 +81,8 @@ module ActsAsSolr #:nodoc: def add_space(doc) if configuration[:spatial] and local - doc << Solr::Field.new(:name => "lat", :value => local.latitude) - doc << Solr::Field.new(:name => "lng", :value => local.longitude) + doc << Solr::Field.new(:name => "lat_f", :value => local.latitude) + doc << Solr::Field.new(:name => "lng_f", :value => local.longitude) end end @@ -96,8 +96,8 @@ module ActsAsSolr #:nodoc: def add_dynamic_attributes(doc) dynamic_attributes.each do |attribute| value = ERB::Util.html_escape(attribute.value) - doc << Solr::Field.new(:name => "#{attribute.name}_t", :value => value) - doc << Solr::Field.new(:name => "#{attribute.name}_facet", :value => value) + doc << Solr::Field.new(:name => "#{attribute.name.downcase}_t", :value => value) + doc << Solr::Field.new(:name => "#{attribute.name.downcase}_facet", :value => value) end if configuration[:dynamic_attributes] end @@ -117,7 +117,7 @@ module ActsAsSolr #:nodoc: Array(data).each do |value| field = Solr::Field.new(:name => "#{field_name}_#{suffix}", :value => value) processed_boost = validate_boost(field_boost) - field.boost = processed_boost if processed_boost != solr_configuration[:default_boost] + field.boost = processed_boost doc << field end end diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/mongo_mapper.rb b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/mongo_mapper.rb index 0015f4b..5ac87cd 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/mongo_mapper.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/mongo_mapper.rb @@ -13,14 +13,11 @@ module ActsAsSolr def primary_key 'id' end - - def find(*args) - if args.first.instance_of? Array - ids = args.first.map { |id| Mongo::ObjectID.from_string(id) } - super :all, :conditions => {primary_key => ids} - else - super *args - end + + def merge_conditions(*args) + ret = {} + args.each{ |a| ret.merge!(a) if a.is_a?(Hash) } + ret end end end diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb index ea9306c..b0036a4 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/parser_methods.rb @@ -3,38 +3,43 @@ module ActsAsSolr #:nodoc: protected # Method used by mostly all the ClassMethods when doing a search - def parse_query(query=nil, options={}, models=nil) - valid_options = [ :alternate_query, :boost_functions, :filter_queries, :facets, :models, :sort, - :scores, :operator, :lazy, :core, :latitude, :longitude, :radius, :relevance, :highlight, - :offset, :per_page, :limit, :page, - :results_format, :sql_options] + def parse_query(query=nil, 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,] query_options = {} - field_list = models.nil? ? solr_configuration[:primary_key_field] : "id" - query_options[:field_list] = [field_list, 'score'] - query_options[:filter_queries] = [] - #allow empty queries as a type search will also be done - query = nil if (query.nil? || query == '') - if query.nil? - query = solr_type_condition - else - query = sanitize_query(query) - query_options[:filter_queries].push(solr_type_condition) - end - query_options[:query] = "#{options[:alternate_query]} #{query}" - + return if query.nil? + raise "Query should be a string" unless query.is_a?(String) raise "Invalid parameters: #{(options.keys - valid_options).join(',')}" unless (options.keys - valid_options).empty? begin Deprecation.validate_query(options) + + if options[:alternate_query] + query = query.blank? ? '*:*' : sanitize_query(query) + query = "#{options[:alternate_query]} #{query}" + else + query = query.blank? ? '*:*' : sanitize_query(query) + end + + query = replace_types([*query], ':').first # put types on filtered fields + query = add_relevance query, options[:relevance] + query_options[:query] = query + + field_list = options[:models].nil? ? solr_configuration[:primary_key_field] : "id" + query_options[:field_list] = [field_list, 'score'] + per_page = options[:per_page] || options[:limit] || 30 offset = options[:offset] || (((options[:page] || 1).to_i - 1) * per_page) query_options[:rows] = per_page query_options[:start] = offset - query_options[:operator] = options[:operator] - query = add_relevance query, options[:relevance] + query_options[:operator] = options[:operator] + query_options[:filter_queries] = [solr_type_condition(options)] query_options[:filter_queries] += replace_types([*options[:filter_queries]], '') if options[:filter_queries] + query_options[:boost_functions] = replace_types([*options[:boost_functions]], '').join(' ') if options[:boost_functions] # first steps on the facet parameter processing @@ -46,9 +51,9 @@ module ActsAsSolr #:nodoc: 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].collect{|k| "#{k}_facet"} if options[:facets][:fields] + 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] + query_options[:facets][:queries] = replace_types([*options[:facets][:query]]) if options[:facets][:query] if options[:facets][:dates] query_options[:date_facets] = {} @@ -75,7 +80,7 @@ module ActsAsSolr #:nodoc: if options[:facets][:dates][:other] validate_date_facet_other_options(options[:facets][:dates][:other]) - query_options[:date_facets][:other] = options[:facets][:dates][:other] + query_options[:date_facets][:other] = options[:facets][:dates][:other] end end @@ -83,30 +88,36 @@ module ActsAsSolr #:nodoc: if options[:highlight] query_options[:highlighting] = {} - query_options[:highlighting][:field_list] = [] - query_options[:highlighting][:field_list] << options[:highlight][:fields].collect {|k| "#{k}_t"} if options[:highlight][:fields] + 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[:sort] = replace_types([options[:sort]], '')[0] if options[:sort] + query_options[:sort] = replace_types([*options[:sort]], '')[0] if options[:sort] - query_options[:radius] = options[:radius] + if options[:radius] + query_options[:radius] = options[:radius] + query_options[:filter_queries] << '{!geofilt}' + end query_options[:latitude] = options[:latitude] query_options[:longitude] = options[:longitude] - ActsAsSolr::Post.execute(Solr::Request::Dismax.new(query_options), options[:core]) + 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 - def solr_type_condition - (subclasses || []).inject("(#{solr_configuration[:type_field]}:\"#{self.name}\"") do |condition, subclass| - condition << (subclass.name.empty? ? "" : " OR #{solr_configuration[:type_field]}:\"#{subclass.name}\"") - end << ')' + def solr_type_condition(options = {}) + classes = [self] + (self.subclasses || []) + (options[:models] || []) + classes.map do |klass| + next if klass.name.empty? + "#{solr_configuration[:type_field]}:\"#{klass.name}\"" + end.compact.join(' OR ') end # Parses the data returned from Solr @@ -155,8 +166,8 @@ module ActsAsSolr #:nodoc: ids.collect {|id| ActsAsSolr::LazyDocument.new(id, self)} elsif configuration[:format] == :objects find_options = options[:sql_options] || {} - find_options[:conditions] = self.send :merge_conditions, {:id => ids}, (find_options[:conditions] || []) - result = self.all(find_options) + find_options[:conditions] = self.send :merge_conditions, {self.primary_key => ids}, (find_options[:conditions] || []) + result = self.all(find_options) || [] result = reorder(result, ids) unless find_options[:order] result else @@ -170,8 +181,8 @@ module ActsAsSolr #:nodoc: def reorder(things, ids) ordered_things = [] ids.each do |id| - thing = things.find { |t| t.id.to_s == id.to_s } - ordered_things |= [thing] if thing + thing = things.find{ |t| t.id.to_s == id.to_s } + ordered_things |= [thing] if thing end ordered_things end @@ -229,25 +240,22 @@ module ActsAsSolr #:nodoc: end def sanitize_query(query) - Solr::Util::query_parser_escape query + fields = self.configuration[:solr_fields].keys + fields += DynamicAttribute.all(:select => 'name', :group => 'name').map(&:name) if DynamicAttribute.table_exists? + Solr::Util::query_parser_escape query, fields end private def add_relevance(query, relevance) - return query if relevance.nil? - q = if query.include? ':' - q = query.split(":").first.split(" ") - q.pop - return query if q.empty? - q.join ' ' - else - query - end - relevance.each do |attribute, value| - query = "#{query} OR #{attribute}:(#{q})^#{value}" + return query if relevance.nil? or query.include? ':' + + query = [query] + relevance.map do |attribute, value| + "#{attribute}:(#{query})^#{value}" end - query + query = query.join(' OR ') + + replace_types([query], '').first end end diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/search_results.rb b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/search_results.rb index c1221aa..824de33 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/search_results.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/search_results.rb @@ -72,7 +72,7 @@ module ActsAsSolr #:nodoc: # Returns a suggested query def suggest - @solr_data[:spellcheck]['suggestions']['collation'].match(/\((.+)\) /)[1] + Hash[@solr_data[:spellcheck]['suggestions']]['collation'] end # Returns the number of documents per page @@ -82,12 +82,12 @@ module ActsAsSolr #:nodoc: # Returns the number of pages found def total_pages - (total / per_page.to_f).ceil + per_page.zero? ? 0 : (total / per_page.to_f).ceil end # Returns the current page def current_page - (@solr_data[:start].to_i / per_page) + 1 + per_page.zero? ? 0 : (@solr_data[:start].to_i / per_page) + 1 end def blank? diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/solr.rb b/vendor/plugins/acts_as_solr_reloaded/lib/solr.rb index efdfee5..e101a01 100755 --- a/vendor/plugins/acts_as_solr_reloaded/lib/solr.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/solr.rb @@ -23,4 +23,5 @@ require File.expand_path("#{File.dirname(__FILE__)}/solr/xml") require File.expand_path("#{File.dirname(__FILE__)}/solr/field") require File.expand_path("#{File.dirname(__FILE__)}/solr/request/base") require File.expand_path("#{File.dirname(__FILE__)}/solr/document") +require File.expand_path("#{File.dirname(__FILE__)}/solr/request/json_update") require File.expand_path("#{File.dirname(__FILE__)}/solr/request/update") diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/solr/field.rb b/vendor/plugins/acts_as_solr_reloaded/lib/solr/field.rb index 2601a5a..a723ac3 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/solr/field.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/solr/field.rb @@ -18,7 +18,7 @@ class Solr::Field # Accepts an optional :boost parameter, used to boost the relevance of a particular field. def initialize(params) - @boost = params[:boost] == 1.0 ? nil : params[:boost] + boost = params[:boost] @name = params[:name].to_s @value = params[:value] # Convert any Time values into UTC/XML schema format (which Solr requires). @@ -29,6 +29,10 @@ class Solr::Field @boost.nil? ? @value : {'boost' => @boost, 'value' => @value} end + def boost=(value) + @boost = value == 1.0 ? nil : value + end + def to_xml e = Solr::XML::Element.new 'field' e.attributes['name'] = @name diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/add_document.rb b/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/add_document.rb index 6e0b9af..b5a4d1f 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/add_document.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/add_document.rb @@ -10,6 +10,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +require File.expand_path(File.dirname(__FILE__) + '/json_update') + class Solr::Request::AddDocument < Solr::Request::JsonUpdate # create the request, optionally passing in a Solr::Document diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/standard.rb b/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/standard.rb index aa8d744..4209f95 100755 --- a/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/standard.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/solr/request/standard.rb @@ -64,7 +64,7 @@ class Solr::Request::Standard < Solr::Request::Select hash[:sfield] = 'latlng' hash[:d] = @params[:radius] - hash[:pt] = "#{@params[:latitude]}, #{@params[:longitude]}" + hash[:pt] = "#{@params[:latitude]}, #{@params[:longitude]}" if @params[:latitude] and @params[:longitude] # facet parameter processing if @params[:facets] diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/solr/util.rb b/vendor/plugins/acts_as_solr_reloaded/lib/solr/util.rb index ddffb35..0bbeb6b 100755 --- a/vendor/plugins/acts_as_solr_reloaded/lib/solr/util.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/solr/util.rb @@ -26,11 +26,21 @@ class Solr::Util end # from http://lucene.apache.org/core/old_versioned_docs/versions/3_0_0/queryparsersyntax.html#Escaping Special Characters - ESCAPES = %w[+ - && || ! ( ) { } \[ \] ^ " ~ * ? : \\] + ESCAPES = %w[+ - && || ! ( ) { } \[ \] " ~ * ? \\] - def self.query_parser_escape(string) - string = string.dup + def self.query_parser_escape(string, fields = []) + string = string.split(' ').map do |str| + if /(\w+):(.*)/ =~ str # escape : considering fields + (!$2.empty? and fields.include?($1.to_sym)) ? "#{$1}:#{$2}" : "#{$1}\\:#{$2}" + elsif /^\^(.*)/ =~ str # escape ^ + "\\^#{$1}" + else + str + end + end.join(' ') + ESCAPES.each { |e| string.gsub! e, "\\#{e}" } string end + end diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake b/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake index a743707..94b50f4 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake +++ b/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake @@ -6,9 +6,12 @@ namespace :solr do SOLR_DIR = "apache-solr-#{SOLR_VERSION}" SOLR_URL = "#{APACHE_MIRROR}/lucene/solr/#{SOLR_VERSION}/#{SOLR_FILENAME}" + # change path if it is on testing environment + PLUGIN_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../..") + desc "Download and install Solr+Jetty #{SOLR_VERSION}." task :download do - if File.exists?(Rails.root + 'vendor/plugins/acts_as_solr_reloaded/solr/start.jar') + if File.exists?("#{PLUGIN_ROOT}/solr/start.jar") puts 'Solr already downloaded.' else Dir.chdir '/tmp' do @@ -17,16 +20,16 @@ namespace :solr do sh "tar xzf apache-solr-#{SOLR_VERSION}.tgz" end cd "apache-solr-#{SOLR_VERSION}/example" - cp_r ['../LICENSE.txt', '../NOTICE.txt', 'README.txt', 'etc', 'lib', 'start.jar', 'webapps', 'work'], Rails.root + 'vendor/plugins/acts_as_solr_reloaded/solr', :verbose => true + cp_r ['../LICENSE.txt', '../NOTICE.txt', 'README.txt', 'etc', 'lib', 'start.jar', 'webapps', 'work'], "#{PLUGIN_ROOT}/solr", :verbose => true cd 'solr' - cp_r ['README.txt', 'bin', 'solr.xml'], Rails.root + 'vendor/plugins/acts_as_solr_reloaded/solr/solr', :verbose => true + cp_r ['README.txt', 'bin', 'solr.xml'], "#{PLUGIN_ROOT}/solr/solr", :verbose => true end end end desc 'Remove Solr instalation from the tree.' task :remove do - solr_root = Rails.root + 'vendor/plugins/acts_as_solr_reloaded/solr/' + solr_root = "#{PLUGIN_ROOT}/solr/" rm_r ['README.txt', 'bin', 'solr.xml'].map{ |i| File.join(solr_root, 'solr', i) }, :verbose => true, :force => true rm_r ['LICENSE.txt', 'NOTICE.txt', 'README.txt', 'etc', 'lib', 'start.jar', 'webapps', 'work'].map{ |i| File.join(solr_root, i) }, :verbose => true, :force => true end @@ -36,8 +39,9 @@ namespace :solr do end desc 'Starts Solr. Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.' - task :start => [:download, :environment] do - require File.expand_path("#{File.dirname(__FILE__)}/../../config/solr_environment") + task :start => [:download] do + require File.expand_path(File.dirname(__FILE__) + '/../../config/solr_environment') + FileUtils.mkdir_p(SOLR_LOGS_PATH) FileUtils.mkdir_p(SOLR_DATA_PATH) FileUtils.mkdir_p(SOLR_PIDS_PATH) @@ -73,8 +77,9 @@ namespace :solr do end desc 'Stops Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.' - task :stop => :environment do + task :stop do require File.expand_path("#{File.dirname(__FILE__)}/../../config/solr_environment") + if File.exists?(SOLR_PID_FILE) killed = false File.open(SOLR_PID_FILE, "r") do |f| @@ -95,7 +100,7 @@ namespace :solr do end desc 'Restart Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.' - task :restart => :environment do + task :restart do Rake::Task["solr:stop"].invoke Rake::Task["solr:start"].invoke end @@ -129,7 +134,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..." @@ -148,7 +153,7 @@ namespace :solr do models.each do |model| if clear_first puts "Clearing index for #{model}..." - ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "#{model.solr_configuration[:type_field]}:#{model}")) + ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "#{model.solr_configuration[:type_field]}:\"#{model}\"")) ActsAsSolr::Post.execute(Solr::Request::Commit.new) end diff --git a/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/schema.xml b/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/schema.xml index 44fead4..a47dbcc 100644 --- a/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/schema.xml +++ b/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/schema.xml @@ -31,24 +31,22 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -62,6 +60,7 @@ --> + + - - - - - - - - - - - - - @@ -117,54 +104,74 @@ - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id + text + + + + + + + + + + + - - - - - - diff --git a/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/solrconfig.xml b/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/solrconfig.xml index 27150fe..eadcf59 100644 --- a/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/solrconfig.xml +++ b/vendor/plugins/acts_as_solr_reloaded/solr/solr/conf/solrconfig.xml @@ -776,7 +776,11 @@ nameOfCustomComponent2 --> - + + spellcheck + + + default - name + spell spellchecker + true + true - + + jarowinkler + spell + org.apache.lucene.search.spell.JaroWinklerDistance + spellcheckerJaro + - + + solr.FileBasedSpellChecker + file + spellings.en.txt + UTF-8 + spellcheckerFile +