aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/plugins')
-rw-r--r--vendor/plugins/acts_as_solr/lib/tasks/database.rake18
-rw-r--r--vendor/plugins/acts_as_solr/lib/tasks/solr.rake58
-rw-r--r--vendor/plugins/acts_as_solr/lib/tasks/test.rake7
-rw-r--r--vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb118
4 files changed, 64 insertions, 137 deletions
diff --git a/vendor/plugins/acts_as_solr/lib/tasks/database.rake b/vendor/plugins/acts_as_solr/lib/tasks/database.rake
deleted file mode 100644
index c02dd3b69..000000000
--- a/vendor/plugins/acts_as_solr/lib/tasks/database.rake
+++ /dev/null
@@ -1,18 +0,0 @@
-require File.dirname(__FILE__) + '/../solr_fixtures'
-
-namespace :db do
- namespace :fixtures do
- desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y"
- task :load => :environment 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|
- ActsAsSolr::SolrFixtures.load(File.basename(fixture_file, '.*'))
- end
- puts "The fixtures loaded have been added to Solr"
- rescue
- end
- end
- end
-end \ No newline at end of file
diff --git a/vendor/plugins/acts_as_solr/lib/tasks/solr.rake b/vendor/plugins/acts_as_solr/lib/tasks/solr.rake
deleted file mode 100644
index d57be7e12..000000000
--- a/vendor/plugins/acts_as_solr/lib/tasks/solr.rake
+++ /dev/null
@@ -1,58 +0,0 @@
-require 'rubygems'
-require 'rake'
-require 'net/http'
-require 'active_record'
-require "#{File.dirname(__FILE__)}/../../config/environment.rb"
-
-namespace :solr do
-
- desc 'Starts Solr. Options accepted: RAILS_ENV=your_env, PORT=XX. Defaults to development if none.'
- task :start do
- begin
- n = Net::HTTP.new('localhost', SOLR_PORT)
- n.request_head('/').value
-
- rescue Net::HTTPServerException #responding
- puts "Port #{SOLR_PORT} in use" and return
-
- rescue Errno::ECONNREFUSED #not responding
- Dir.chdir(SOLR_PATH) do
- pid = fork do
- #STDERR.close
- exec "java -Dsolr.data.dir=solr/data/#{ENV['RAILS_ENV']} -Djetty.port=#{SOLR_PORT} -jar start.jar"
- end
- sleep(5)
- File.open("#{SOLR_PATH}/tmp/#{ENV['RAILS_ENV']}_pid", "w"){ |f| f << pid}
- puts "#{ENV['RAILS_ENV']} Solr started successfully on #{SOLR_PORT}, pid: #{pid}."
- end
- end
- end
-
- desc 'Stops Solr. Specify the environment by using: RAILS_ENV=your_env. Defaults to development if none.'
- task :stop do
- fork do
- file_path = "#{SOLR_PATH}/tmp/#{ENV['RAILS_ENV']}_pid"
- if File.exists?(file_path)
- File.open(file_path, "r") do |f|
- pid = f.readline
- Process.kill('TERM', pid.to_i)
- end
- File.unlink(file_path)
- Rake::Task["solr:destroy_index"].invoke if ENV['RAILS_ENV'] == 'test'
- puts "Solr shutdown successfully."
- else
- puts "Solr is not running. I haven't done anything."
- end
- end
- end
-
- desc 'Remove Solr index'
- task :destroy_index do
- raise "In production mode. I'm not going to delete the index, sorry." if ENV['RAILS_ENV'] == "production"
- if File.exists?("#{SOLR_PATH}/solr/data/#{ENV['RAILS_ENV']}")
- Dir[ SOLR_PATH + "/solr/data/#{ENV['RAILS_ENV']}/index/*"].each{|f| File.unlink(f)}
- Dir.rmdir(SOLR_PATH + "/solr/data/#{ENV['RAILS_ENV']}/index")
- puts "Index files removed under " + ENV['RAILS_ENV'] + " environment"
- end
- end
-end
diff --git a/vendor/plugins/acts_as_solr/lib/tasks/test.rake b/vendor/plugins/acts_as_solr/lib/tasks/test.rake
deleted file mode 100644
index 6bb6cafbf..000000000
--- a/vendor/plugins/acts_as_solr/lib/tasks/test.rake
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'active_record'
-
-namespace :test do
- task :migrate do
- ActiveRecord::Migrator.migrate("test/db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
- end
-end
diff --git a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb
index a0d88f721..4cb3d6a08 100644
--- a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb
+++ b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb
@@ -4,7 +4,7 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: acts_as_xapian.rb,v 1.13 2008-04-29 16:42:11 francis Exp $
+# $Id: acts_as_xapian.rb,v 1.14 2008-04-30 00:37:51 francis Exp $
# TODO:
# Test :eager_load
@@ -192,7 +192,7 @@ module ActsAsXapian
# Initialisation
def ActsAsXapian.init(classname = nil, options = nil)
if not classname.nil?
- # store class and options for use later, when we open the db in late_init
+ # store class and options for use later, when we open the db in readable_init
@@init_values.push([classname,options])
end
@@ -205,64 +205,74 @@ module ActsAsXapian
# XXX this gets made once for each acts_as_xapian. Oh well.
@@stemmer = Xapian::Stem.new('english')
end
- # called only when we *need* to open the db
- def ActsAsXapian.late_init
+
+ # Called only when we *need* to open the db
+ def ActsAsXapian.readable_init
if @@db.nil?
# basic Xapian objects
- @@db = Xapian::Database.new()
@@db = Xapian::Database.new(@@db_path)
@@enquire = Xapian::Enquire.new(@@db)
- # for queries
- @@query_parser = Xapian::QueryParser.new
- @@query_parser.stemmer = @@stemmer
- @@query_parser.stemming_strategy = Xapian::QueryParser::STEM_SOME
- @@query_parser.database = @@db
- @@query_parser.default_op = Xapian::Query::OP_AND
-
- @@terms_by_capital = {}
- @@values_by_number = {}
- @@values_by_prefix = {}
-
- for init_value_pair in @@init_values
- classname = init_value_pair[0]
- options = init_value_pair[1]
-
- # go through the various field types, and tell query parser about them,
- # and error check them - i.e. check for consistency between models
- @@query_parser.add_boolean_prefix("model", "M")
- @@query_parser.add_boolean_prefix("modelid", "I")
- for term in options[:terms]
- raise "Use a single capital letter for term code" if not term[1].match(/^[A-Z]$/)
- raise "M and I are reserved for use as the model/id term" if term[1] == "M" or term[1] == "I"
- raise "model and modelid are reserved for use as the model/id prefixes" if term[2] == "model" or term[2] == "modelid"
- raise "Z is reserved for stemming terms" if term[1] == "Z"
- raise "Already have code '" + term[1] + "' in another model but with different prefix '" + @@terms_by_capital[term[1]] + "'" if @@terms_by_capital.include?(term[1]) && @@terms_by_capital[term[1]] != term[2]
- @@terms_by_capital[term[1]] = term[2]
- @@query_parser.add_boolean_prefix(term[2], term[1])
- end
- for value in options[:values]
- raise "Value index '"+value[1].to_s+"' must be an integer, is " + value[1].class.to_s if value[1].class != 1.class
- raise "Already have value index '" + value[1].to_s + "' in another model but with different prefix '" + @@values_by_number[value[1]].to_s + "'" if @@values_by_number.include?(value[1]) && @@values_by_number[value[1]] != value[2]
-
- # date types are special, mark them so the first model they're seen for
- if !@@values_by_number.include?(value[1])
- if value[3] == :date
- value_range = Xapian::DateValueRangeProcessor.new(value[1])
- elsif value[3] == :string
- value_range = Xapian::StringValueRangeProcessor.new(value[1])
- elsif value[3] == :number
- value_range = Xapian::NumberValueRangeProcessor.new(value[1])
- else
- raise "Unknown value type '" + value[3].to_s + "'"
- end
-
- @@query_parser.add_valuerangeprocessor(value_range)
+ init_query_parser
+ end
+ end
+
+ # Make a new query parser
+ def ActsAsXapian.init_query_parser
+ # for queries
+ @@query_parser = Xapian::QueryParser.new
+ @@query_parser.stemmer = @@stemmer
+ @@query_parser.stemming_strategy = Xapian::QueryParser::STEM_SOME
+ @@query_parser.database = @@db
+ @@query_parser.default_op = Xapian::Query::OP_AND
+
+ @@terms_by_capital = {}
+ @@values_by_number = {}
+ @@values_by_prefix = {}
+ @@value_ranges_store = []
+
+ for init_value_pair in @@init_values
+ classname = init_value_pair[0]
+ options = init_value_pair[1]
+
+ # go through the various field types, and tell query parser about them,
+ # and error check them - i.e. check for consistency between models
+ @@query_parser.add_boolean_prefix("model", "M")
+ @@query_parser.add_boolean_prefix("modelid", "I")
+ for term in options[:terms]
+ raise "Use a single capital letter for term code" if not term[1].match(/^[A-Z]$/)
+ raise "M and I are reserved for use as the model/id term" if term[1] == "M" or term[1] == "I"
+ raise "model and modelid are reserved for use as the model/id prefixes" if term[2] == "model" or term[2] == "modelid"
+ raise "Z is reserved for stemming terms" if term[1] == "Z"
+ raise "Already have code '" + term[1] + "' in another model but with different prefix '" + @@terms_by_capital[term[1]] + "'" if @@terms_by_capital.include?(term[1]) && @@terms_by_capital[term[1]] != term[2]
+ @@terms_by_capital[term[1]] = term[2]
+ @@query_parser.add_boolean_prefix(term[2], term[1])
+ end
+ for value in options[:values]
+ raise "Value index '"+value[1].to_s+"' must be an integer, is " + value[1].class.to_s if value[1].class != 1.class
+ raise "Already have value index '" + value[1].to_s + "' in another model but with different prefix '" + @@values_by_number[value[1]].to_s + "'" if @@values_by_number.include?(value[1]) && @@values_by_number[value[1]] != value[2]
+
+ # date types are special, mark them so the first model they're seen for
+ if !@@values_by_number.include?(value[1])
+ if value[3] == :date
+ value_range = Xapian::DateValueRangeProcessor.new(value[1])
+ elsif value[3] == :string
+ value_range = Xapian::StringValueRangeProcessor.new(value[1])
+ elsif value[3] == :number
+ value_range = Xapian::NumberValueRangeProcessor.new(value[1])
+ else
+ raise "Unknown value type '" + value[3].to_s + "'"
end
- @@values_by_number[value[1]] = value[2]
- @@values_by_prefix[value[2]] = value[1]
+ @@query_parser.add_valuerangeprocessor(value_range)
+
+ # stop it being garbage collected, as
+ # add_valuerangeprocessor ref is outside Ruby's GC
+ @@value_ranges_store.push(value_range)
end
+
+ @@values_by_number[value[1]] = value[2]
+ @@values_by_prefix[value[2]] = value[1]
end
end
end
@@ -306,7 +316,7 @@ module ActsAsXapian
sort_by_ascending = options[:sort_by_ascending] || true
collapse_by_prefix = options[:collapse_by_prefix] || nil
- ActsAsXapian.late_init
+ ActsAsXapian.readable_init
if ActsAsXapian.db.nil?
raise "ActsAsXapian not initialized"
end
@@ -328,7 +338,7 @@ module ActsAsXapian
ActsAsXapian.enquire.sort_by_value_then_relevance!(value, sort_by_ascending)
end
if collapse_by_prefix.nil?
- ActsAsXapian.enquire.collapse_key = nil
+ ActsAsXapian.enquire.collapse_key = Xapian.BAD_VALUENO
else
value = ActsAsXapian.values_by_prefix[collapse_by_prefix]
raise "couldn't find prefix '" + collapse_by_prefix + "'" if value.nil?