From ad8ab8dfc2ee6fb5e1316500cb357cf971e3f56e Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Fri, 23 May 2008 19:53:58 +0000 Subject: [PATCH] ActionItem129: acts_as_ferret removed --- vendor/plugins/acts_as_ferret/LICENSE | 20 -------------------- vendor/plugins/acts_as_ferret/README | 49 ------------------------------------------------- vendor/plugins/acts_as_ferret/config/ferret_server.yml | 12 ------------ vendor/plugins/acts_as_ferret/init.rb | 22 ---------------------- vendor/plugins/acts_as_ferret/install.rb | 19 ------------------- vendor/plugins/acts_as_ferret/lib/act_methods.rb | 242 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb | 160 ---------------------------------------------------------------------------------------------------------------------------------------------------------------- vendor/plugins/acts_as_ferret/lib/class_methods.rb | 316 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- vendor/plugins/acts_as_ferret/lib/ferret_cap_tasks.rb | 21 --------------------- vendor/plugins/acts_as_ferret/lib/ferret_extensions.rb | 81 --------------------------------------------------------------------------------- vendor/plugins/acts_as_ferret/lib/ferret_result.rb | 36 ------------------------------------ vendor/plugins/acts_as_ferret/lib/ferret_server.rb | 131 ----------------------------------------------------------------------------------------------------------------------------------- vendor/plugins/acts_as_ferret/lib/index.rb | 31 ------------------------------- vendor/plugins/acts_as_ferret/lib/instance_methods.rb | 126 ------------------------------------------------------------------------------------------------------------------------------ vendor/plugins/acts_as_ferret/lib/local_index.rb | 209 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- vendor/plugins/acts_as_ferret/lib/more_like_this.rb | 217 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- vendor/plugins/acts_as_ferret/lib/multi_index.rb | 83 ----------------------------------------------------------------------------------- vendor/plugins/acts_as_ferret/lib/remote_index.rb | 50 -------------------------------------------------- vendor/plugins/acts_as_ferret/lib/shared_index.rb | 14 -------------- vendor/plugins/acts_as_ferret/lib/shared_index_class_methods.rb | 90 ------------------------------------------------------------------------------------------ vendor/plugins/acts_as_ferret/rakefile | 131 ----------------------------------------------------------------------------------------------------------------------------------- vendor/plugins/acts_as_ferret/script/ferret_server | 18 ------------------ vendor/plugins/acts_as_ferret/script/ferret_start | 72 ------------------------------------------------------------------------ vendor/plugins/acts_as_ferret/script/ferret_stop | 26 -------------------------- 24 files changed, 0 insertions(+), 2176 deletions(-) delete mode 100644 vendor/plugins/acts_as_ferret/LICENSE delete mode 100644 vendor/plugins/acts_as_ferret/README delete mode 100644 vendor/plugins/acts_as_ferret/config/ferret_server.yml delete mode 100644 vendor/plugins/acts_as_ferret/init.rb delete mode 100644 vendor/plugins/acts_as_ferret/install.rb delete mode 100644 vendor/plugins/acts_as_ferret/lib/act_methods.rb delete mode 100644 vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb delete mode 100644 vendor/plugins/acts_as_ferret/lib/class_methods.rb delete mode 100644 vendor/plugins/acts_as_ferret/lib/ferret_cap_tasks.rb delete mode 100644 vendor/plugins/acts_as_ferret/lib/ferret_extensions.rb delete mode 100644 vendor/plugins/acts_as_ferret/lib/ferret_result.rb delete mode 100644 vendor/plugins/acts_as_ferret/lib/ferret_server.rb delete mode 100644 vendor/plugins/acts_as_ferret/lib/index.rb delete mode 100644 vendor/plugins/acts_as_ferret/lib/instance_methods.rb delete mode 100644 vendor/plugins/acts_as_ferret/lib/local_index.rb delete mode 100644 vendor/plugins/acts_as_ferret/lib/more_like_this.rb delete mode 100644 vendor/plugins/acts_as_ferret/lib/multi_index.rb delete mode 100644 vendor/plugins/acts_as_ferret/lib/remote_index.rb delete mode 100644 vendor/plugins/acts_as_ferret/lib/shared_index.rb delete mode 100644 vendor/plugins/acts_as_ferret/lib/shared_index_class_methods.rb delete mode 100644 vendor/plugins/acts_as_ferret/rakefile delete mode 100644 vendor/plugins/acts_as_ferret/script/ferret_server delete mode 100755 vendor/plugins/acts_as_ferret/script/ferret_start delete mode 100755 vendor/plugins/acts_as_ferret/script/ferret_stop diff --git a/vendor/plugins/acts_as_ferret/LICENSE b/vendor/plugins/acts_as_ferret/LICENSE deleted file mode 100644 index b07e5a5..0000000 --- a/vendor/plugins/acts_as_ferret/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2006 Kasper Weibel, Jens Kraemer - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/plugins/acts_as_ferret/README b/vendor/plugins/acts_as_ferret/README deleted file mode 100644 index 2b47744..0000000 --- a/vendor/plugins/acts_as_ferret/README +++ /dev/null @@ -1,49 +0,0 @@ -= acts_as_ferret - -This ActiveRecord mixin adds full text search capabilities to any Rails model. - -It is heavily based on the original acts_as_ferret plugin done by -Kasper Weibel and a modified version done by Thomas Lockney, which -both can be found on http://ferret.davebalmain.com/trac/wiki/FerretOnRails - -== Installation - -=== Installation inside your Rails project via script/plugin - -script/plugin install svn://projects.jkraemer.net/acts_as_ferret/trunk/plugin/acts_as_ferret - - -=== System-wide installation with Rubygems - -sudo gem install acts_as_ferret - -To use acts_as_ferret in your project, add the following line to your -project's config/environment.rb: - -require 'acts_as_ferret' - - -== Usage - -include the following in your model class (specifiying the fields you want to get indexed): - -acts_as_ferret :fields => [ :title, :description ] - -now you can use ModelClass.find_by_contents(query) to find instances of your model -whose indexed fields match a given query. All query terms are required by default, -but explicit OR queries are possible. This differs from the ferret default, but -imho is the more often needed/expected behaviour (more query terms result in -less results). - -Please see ActsAsFerret::ActMethods#acts_as_ferret for more information. - -== License - -Released under the MIT license. - -== Authors - -* Kasper Weibel Nielsen-Refs (original author) -* Jens Kraemer (current maintainer) - - diff --git a/vendor/plugins/acts_as_ferret/config/ferret_server.yml b/vendor/plugins/acts_as_ferret/config/ferret_server.yml deleted file mode 100644 index 6522f12..0000000 --- a/vendor/plugins/acts_as_ferret/config/ferret_server.yml +++ /dev/null @@ -1,12 +0,0 @@ -production: - host: ferret.yourdomain.com - port: 9010 - pid_file: log/ferret.pid -development: - host: localhost - port: 9010 - pid_file: log/ferret.pid -test: - host: localhost - port: 9009 - pid_file: log/ferret.pid diff --git a/vendor/plugins/acts_as_ferret/init.rb b/vendor/plugins/acts_as_ferret/init.rb deleted file mode 100644 index 5eca621..0000000 --- a/vendor/plugins/acts_as_ferret/init.rb +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (c) 2006 Kasper Weibel Nielsen-Refs, Thomas Lockney, Jens Krämer -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -require 'acts_as_ferret' - diff --git a/vendor/plugins/acts_as_ferret/install.rb b/vendor/plugins/acts_as_ferret/install.rb deleted file mode 100644 index 2bbbfc6..0000000 --- a/vendor/plugins/acts_as_ferret/install.rb +++ /dev/null @@ -1,19 +0,0 @@ -# acts_as_ferret install script -require 'fileutils' - -def install(file) - puts "Installing: #{file}" - target = File.join(File.dirname(__FILE__), '..', '..', '..', file) - if File.exists?(target) - puts "target #{target} already exists, skipping" - else - FileUtils.cp File.join(File.dirname(__FILE__), file), target - end -end - -install File.join( 'script', 'ferret_start' ) -install File.join( 'script', 'ferret_stop' ) -install File.join( 'config', 'ferret_server.yml' ) - -puts IO.read(File.join(File.dirname(__FILE__), 'README')) - diff --git a/vendor/plugins/acts_as_ferret/lib/act_methods.rb b/vendor/plugins/acts_as_ferret/lib/act_methods.rb deleted file mode 100644 index 56c0f54..0000000 --- a/vendor/plugins/acts_as_ferret/lib/act_methods.rb +++ /dev/null @@ -1,242 +0,0 @@ -module ActsAsFerret #:nodoc: - - # This module defines the acts_as_ferret method and is included into - # ActiveRecord::Base - module ActMethods - - - def reloadable?; false end - - # declares a class as ferret-searchable. - # - # ====options: - # fields:: names all fields to include in the index. If not given, - # all attributes of the class will be indexed. You may also give - # symbols pointing to instance methods of your model here, i.e. - # to retrieve and index data from a related model. - # - # additional_fields:: names fields to include in the index, in addition - # to those derived from the db scheme. use if you want - # to add custom fields derived from methods to the db - # fields (which will be picked by aaf). This option will - # be ignored when the fields option is given, in that - # case additional fields get specified there. - # - # index_dir:: declares the directory where to put the index for this class. - # The default is RAILS_ROOT/index/RAILS_ENV/CLASSNAME. - # The index directory will be created if it doesn't exist. - # - # single_index:: set this to true to let this class use a Ferret - # index that is shared by all classes having :single_index set to true. - # :store_class_name is set to true implicitly, as well as index_dir, so - # don't bother setting these when using this option. the shared index - # will be located in index//shared . - # - # store_class_name:: to make search across multiple models (with either - # single_index or the multi_search method) useful, set - # this to true. the model class name will be stored in a keyword field - # named class_name - # - # reindex_batch_size:: reindexing is done in batches of this size, default is 1000 - # - # ferret:: Hash of Options that directly influence the way the Ferret engine works. You - # can use most of the options the Ferret::I class accepts here, too. Among the - # more useful are: - # - # or_default:: whether query terms are required by - # default (the default, false), or not (true) - # - # analyzer:: the analyzer to use for query parsing (default: nil, - # which means the ferret StandardAnalyzer gets used) - # - # default_field:: use to set one or more fields that are searched for query terms - # that don't have an explicit field list. This list should *not* - # contain any untokenized fields. If it does, you're asking - # for trouble (i.e. not getting results for queries having - # stop words in them). Aaf by default initializes the default field - # list to contain all tokenized fields. If you use :single_index => true, - # you really should set this option specifying your default field - # list (which should be equal in all your classes sharing the index). - # Otherwise you might get incorrect search results and you won't get - # any lazy loading of stored field data. - # - # For downwards compatibility reasons you can also specify the Ferret options in the - # last Hash argument. - def acts_as_ferret(options={}, ferret_options={}) - - # force local mode if running *inside* the Ferret server - somewhere the - # real indexing has to be done after all :-) - # Usually the automatic detection of server mode works fine, however if you - # require your model classes in environment.rb they will get loaded before the - # DRb server is started, so this code is executed too early and detection won't - # work. In this case you'll get endless loops resulting in "stack level too deep" - # errors. - # To get around this, start the server with the environment variable - # FERRET_USE_LOCAL_INDEX set to '1'. - logger.debug "Asked for a remote server ? #{options[:remote].inspect}, ENV[\"FERRET_USE_LOCAL_INDEX\"] is #{ENV["FERRET_USE_LOCAL_INDEX"].inspect}, looks like we are#{ActsAsFerret::Remote::Server.running || ENV['FERRET_USE_LOCAL_INDEX'] ? '' : ' not'} the server" - options.delete(:remote) if ENV["FERRET_USE_LOCAL_INDEX"] || ActsAsFerret::Remote::Server.running - - if options[:remote] && options[:remote] !~ /^druby/ - # read server location from config/ferret_server.yml - options[:remote] = ActsAsFerret::Remote::Config.load("#{RAILS_ROOT}/config/ferret_server.yml")[:uri] rescue nil - end - - if options[:remote] - logger.debug "Will use remote index server which should be available at #{options[:remote]}" - else - logger.debug "Will use local index." - end - - - extend ClassMethods - extend SharedIndexClassMethods if options[:single_index] - - include InstanceMethods - include MoreLikeThis::InstanceMethods - - # AR hooks - after_create :ferret_create - after_update :ferret_update - after_destroy :ferret_destroy - - cattr_accessor :aaf_configuration - - # default config - self.aaf_configuration = { - :index_dir => "#{ActsAsFerret::index_dir}/#{self.name.underscore}", - :store_class_name => false, - :name => self.table_name, - :class_name => self.name, - :single_index => false, - :reindex_batch_size => 1000, - :ferret => {}, # Ferret config Hash - :ferret_fields => {} # list of indexed fields that will be filled later - } - - # merge aaf options with args - aaf_configuration.update(options) if options.is_a?(Hash) - # apply appropriate settings for shared index - if aaf_configuration[:single_index] - aaf_configuration[:index_dir] = "#{ActsAsFerret::index_dir}/shared" - aaf_configuration[:store_class_name] = true - end - - # set ferret default options - aaf_configuration[:ferret].reverse_merge!( :or_default => false, - :handle_parse_errors => true, - :default_field => nil # will be set later on - #:max_clauses => 512, - #:analyzer => Ferret::Analysis::StandardAnalyzer.new, - # :wild_card_downcase => true - ) - - # merge ferret options with those from second parameter hash - aaf_configuration[:ferret].update(ferret_options) if ferret_options.is_a?(Hash) - - unless options[:remote] - ActsAsFerret::ensure_directory aaf_configuration[:index_dir] - aaf_configuration[:index_base_dir] = aaf_configuration[:index_dir] - aaf_configuration[:index_dir] = find_last_index_version(aaf_configuration[:index_dir]) - logger.debug "using index in #{aaf_configuration[:index_dir]}" - end - - # these properties are somewhat vital to the plugin and shouldn't - # be overwritten by the user: - aaf_configuration[:ferret].update( - :key => (aaf_configuration[:single_index] ? [:id, :class_name] : :id), - :path => aaf_configuration[:index_dir], - :auto_flush => true, # slower but more secure in terms of locking problems TODO disable when running in drb mode? - :create_if_missing => true - ) - - if aaf_configuration[:fields] - add_fields(aaf_configuration[:fields]) - else - add_fields(self.new.attributes.keys.map { |k| k.to_sym }) - add_fields(aaf_configuration[:additional_fields]) - end - - # now that all fields have been added, we can initialize the default - # field list to be used by the query parser. - # It will include all content fields *not* marked as :untokenized. - # This fixes the otherwise failing CommentTest#test_stopwords. Basically - # this means that by default only tokenized fields (which is the default) - # will be searched. If you want to search inside the contents of an - # untokenized field, you'll have to explicitly specify it in your query. - # - # Unfortunately this is not very useful with a shared index (see - # http://projects.jkraemer.net/acts_as_ferret/ticket/85) - # You should consider specifying the default field list to search for as - # part of the ferret_options hash in your call to acts_as_ferret. - aaf_configuration[:ferret][:default_field] ||= if aaf_configuration[:single_index] - logger.warn "You really should set the acts_as_ferret :default_field option when using a shared index!" - '*' - else - aaf_configuration[:ferret_fields].keys.select do |f| - aaf_configuration[:ferret_fields][f][:index] != :untokenized - end - end - logger.info "default field list: #{aaf_configuration[:ferret][:default_field].inspect}" - - if options[:remote] - aaf_index.ensure_index_exists - end - end - - - protected - - # find the most recent version of an index - def find_last_index_version(basedir) - # check for versioned index - versions = Dir.entries(basedir).select do |f| - dir = File.join(basedir, f) - File.directory?(dir) && File.file?(File.join(dir, 'segments')) && f =~ /^\d+(_\d+)?$/ - end - if versions.any? - # select latest version - versions.sort! - File.join basedir, versions.last - else - basedir - end - end - - - # helper that defines a method that adds the given field to a ferret - # document instance - def define_to_field_method(field, options = {}) - options.reverse_merge!( :store => :no, - :highlight => :yes, - :index => :yes, - :term_vector => :with_positions_offsets, - :boost => 1.0 ) - options[:term_vector] = :no if options[:index] == :no - aaf_configuration[:ferret_fields][field] = options - define_method("#{field}_to_ferret".to_sym) do - begin - val = content_for_field_name(field) - rescue - logger.warn("Error retrieving value for field #{field}: #{$!}") - val = '' - end - logger.debug("Adding field #{field} with value '#{val}' to index") - val - end - end - - def add_fields(field_config) - if field_config.is_a? Hash - field_config.each_pair do |key,val| - define_to_field_method(key,val) - end - elsif field_config.respond_to?(:each) - field_config.each do |field| - define_to_field_method(field) - end - end - end - - end - -end diff --git a/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb b/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb deleted file mode 100644 index 47c8a99..0000000 --- a/vendor/plugins/acts_as_ferret/lib/acts_as_ferret.rb +++ /dev/null @@ -1,160 +0,0 @@ -# Copyright (c) 2006 Kasper Weibel Nielsen-Refs, Thomas Lockney, Jens Krämer -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -require 'active_support' -require 'active_record' -require 'set' -require 'ferret' - -require 'ferret_extensions' -require 'act_methods' -require 'class_methods' -require 'shared_index_class_methods' -require 'ferret_result' -require 'instance_methods' - -require 'multi_index' -require 'more_like_this' - -require 'index' -require 'local_index' -require 'shared_index' -require 'remote_index' - -require 'ferret_server' - - -# The Rails ActiveRecord Ferret Mixin. -# -# This mixin adds full text search capabilities to any Rails model. -# -# The current version emerged from on the original acts_as_ferret plugin done by -# Kasper Weibel and a modified version done by Thomas Lockney, which both can be -# found on the Ferret Wiki: http://ferret.davebalmain.com/trac/wiki/FerretOnRails. -# -# basic usage: -# include the following in your model class (specifiying the fields you want to get indexed): -# acts_as_ferret :fields => [ :title, :description ] -# -# now you can use ModelClass.find_by_contents(query) to find instances of your model -# whose indexed fields match a given query. All query terms are required by default, but -# explicit OR queries are possible. This differs from the ferret default, but imho is the more -# often needed/expected behaviour (more query terms result in less results). -# -# Released under the MIT license. -# -# Authors: -# Kasper Weibel Nielsen-Refs (original author) -# Jens Kraemer (active maintainer) -# -module ActsAsFerret - - # global Hash containing all multi indexes created by all classes using the plugin - # key is the concatenation of alphabetically sorted names of the classes the - # searcher searches. - @@multi_indexes = Hash.new - def self.multi_indexes; @@multi_indexes end - - # global Hash containing the ferret indexes of all classes using the plugin - # key is the index directory. - @@ferret_indexes = Hash.new - def self.ferret_indexes; @@ferret_indexes end - - - # decorator that adds a total_hits accessor to search result arrays - class SearchResults - attr_reader :total_hits - def initialize(results, total_hits) - @results = results - @total_hits = total_hits - end - def method_missing(symbol, *args, &block) - @results.send(symbol, *args, &block) - end - def respond_to?(name) - self.methods.include?(name) || @results.respond_to?(name) - end - end - - def self.ensure_directory(dir) - FileUtils.mkdir_p dir unless (File.directory?(dir) || File.symlink?(dir)) - end - - # make sure the default index base dir exists. by default, all indexes are created - # under RAILS_ROOT/index/RAILS_ENV - def self.init_index_basedir - index_base = "#{RAILS_ROOT}/index" - @@index_dir = "#{index_base}/#{RAILS_ENV}" - end - - mattr_accessor :index_dir - init_index_basedir - - def self.append_features(base) - super - base.extend(ClassMethods) - end - - # builds a FieldInfos instance for creation of an index containing fields - # for the given model classes. - def self.field_infos(models) - # default attributes for fields - fi = Ferret::Index::FieldInfos.new(:store => :no, - :index => :yes, - :term_vector => :no, - :boost => 1.0) - # primary key - fi.add_field(:id, :store => :yes, :index => :untokenized) - fields = {} - have_class_name = false - models.each do |model| - fields.update(model.aaf_configuration[:ferret_fields]) - # class_name - if !have_class_name && model.aaf_configuration[:store_class_name] - fi.add_field(:class_name, :store => :yes, :index => :untokenized) - have_class_name = true - end - end - fields.each_pair do |field, options| - fi.add_field(field, { :store => :no, - :index => :yes }.update(options)) - end - return fi - end - - def self.close_multi_indexes - # close combined index readers, just in case - # this seems to fix a strange test failure that seems to relate to a - # multi_index looking at an old version of the content_base index. - multi_indexes.each_pair do |key, index| - # puts "#{key} -- #{self.name}" - # TODO only close those where necessary (watch inheritance, where - # self.name is base class of a class where key is made from) - index.close #if key =~ /#{self.name}/ - end - multi_indexes.clear - end - -end - -# include acts_as_ferret method into ActiveRecord::Base -ActiveRecord::Base.extend ActsAsFerret::ActMethods - - diff --git a/vendor/plugins/acts_as_ferret/lib/class_methods.rb b/vendor/plugins/acts_as_ferret/lib/class_methods.rb deleted file mode 100644 index d0b162c..0000000 --- a/vendor/plugins/acts_as_ferret/lib/class_methods.rb +++ /dev/null @@ -1,316 +0,0 @@ -module ActsAsFerret - - module ClassMethods - - # rebuild the index from all data stored for this model. - # This is called automatically when no index exists yet. - # - # When calling this method manually, you can give any additional - # model classes that should also go into this index as parameters. - # Useful when using the :single_index option. - # Note that attributes named the same in different models will share - # the same field options in the shared index. - def rebuild_index(*models) - models << self unless models.include?(self) - aaf_index.rebuild_index models.map(&:to_s) - index_dir = find_last_index_version(aaf_configuration[:index_base_dir]) unless aaf_configuration[:remote] - end - - # runs across all records yielding those to be indexed when the index is rebuilt - def records_for_rebuild(batch_size = 1000) - transaction do - if connection.class.name =~ /Mysql/ && primary_key == 'id' - logger.info "using mysql specific batched find :all" - offset = 0 - while (rows = find :all, :conditions => ["id > ?", offset ], :limit => batch_size).any? - offset = rows.last.id - yield rows, offset - end - else - # sql server adapter won't batch correctly without defined ordering - order = "#{primary_key} ASC" if connection.class.name =~ /SQLServer/ - 0.step(self.count, batch_size) do |offset| - yield find( :all, :limit => batch_size, :offset => offset, :order => order ), offset - end - end - end - end - - # Switches this class to a new index located in dir. - # Used by the DRb server when switching to a new index version. - def index_dir=(dir) - logger.debug "changing index dir to #{dir}" - aaf_configuration[:index_dir] = aaf_configuration[:ferret][:path] = dir - aaf_index.reopen! - logger.debug "index dir is now #{dir}" - end - - # Retrieve the index instance for this model class. This can either be a - # LocalIndex, or a RemoteIndex instance. - # - # Index instances are stored in a hash, using the index directory - # as the key. So model classes sharing a single index will share their - # Index object, too. - def aaf_index - ActsAsFerret::ferret_indexes[aaf_configuration[:index_dir]] ||= create_index_instance - end - - # Finds instances by searching the Ferret index. Terms are ANDed by default, use - # OR between terms for ORed queries. Or specify +:or_default => true+ in the - # +:ferret+ options hash of acts_as_ferret. - # - # == options: - # offset:: first hit to retrieve (useful for paging) - # limit:: number of hits to retrieve, or :all to retrieve - # all results - # lazy:: Array of field names whose contents should be read directly - # from the index. Those fields have to be marked - # +:store => :yes+ in their field options. Give true to get all - # stored fields. Note that if you have a shared index, you have - # to explicitly state the fields you want to fetch, true won't - # work here) - # models:: only for single_index scenarios: an Array of other Model classes to - # include in this search. Use :all to query all models. - # - # +find_options+ is a hash passed on to active_record's find when - # retrieving the data from db, useful to i.e. prefetch relationships with - # :include or to specify additional filter criteria with :conditions. - # - # This method returns a +SearchResults+ instance, which really is an Array that has - # been decorated with a total_hits attribute holding the total number of hits. - # - # Please keep in mind that the number of total hits might be wrong if you specify - # both ferret options and active record find_options that somehow limit the result - # set (e.g. +:num_docs+ and some +:conditions+). - def find_with_ferret(q, options = {}, find_options = {}) - total_hits, result = find_records_lazy_or_not q, options, find_options - logger.debug "Query: #{q}\ntotal hits: #{total_hits}, results delivered: #{result.size}" - return SearchResults.new(result, total_hits) - end - alias find_by_contents find_with_ferret - - - - # Returns the total number of hits for the given query - # To count the results of a multi_search query, specify an array of - # class names with the :models option. - def total_hits(q, options={}) - if models = options[:models] - options[:models] = add_self_to_model_list_if_necessary(models).map(&:to_s) - end - aaf_index.total_hits(q, options) - end - - # Finds instance model name, ids and scores by contents. - # Useful e.g. if you want to search across models or do not want to fetch - # all result records (yet). - # - # Options are the same as for find_by_contents - # - # A block can be given too, it will be executed with every result: - # find_id_by_contents(q, options) do |model, id, score| - # id_array << id - # scores_by_id[id] = score - # end - # NOTE: in case a block is given, only the total_hits value will be returned - # instead of the [total_hits, results] array! - # - def find_id_by_contents(q, options = {}, &block) - deprecated_options_support(options) - aaf_index.find_id_by_contents(q, options, &block) - end - - # requires the store_class_name option of acts_as_ferret to be true - # for all models queried this way. - def multi_search(query, additional_models = [], options = {}, find_options = {}) - result = [] - - if options[:lazy] - logger.warn "find_options #{find_options} are ignored because :lazy => true" unless find_options.empty? - total_hits = id_multi_search(query, additional_models, options) do |model, id, score, data| - result << FerretResult.new(model, id, score, data) - end - else - id_arrays = {} - rank = 0 - total_hits = id_multi_search(query, additional_models, options) do |model, id, score, data| - id_arrays[model] ||= {} - id_arrays[model][id] = [ rank += 1, score ] - end - result = retrieve_records(id_arrays, find_options) - end - - SearchResults.new(result, total_hits) - end - - # returns an array of hashes, each containing :class_name, - # :id and :score for a hit. - # - # if a block is given, class_name, id and score of each hit will - # be yielded, and the total number of hits is returned. - def id_multi_search(query, additional_models = [], options = {}, &proc) - deprecated_options_support(options) - additional_models = add_self_to_model_list_if_necessary(additional_models) - aaf_index.id_multi_search(query, additional_models.map(&:to_s), options, &proc) - end - - - protected - - def add_self_to_model_list_if_necessary(models) - models = [ models ] unless models.is_a? Array - models << self unless models.include?(self) - end - - def find_records_lazy_or_not(q, options = {}, find_options = {}) - if options[:lazy] - logger.warn "find_options #{find_options} are ignored because :lazy => true" unless find_options.empty? - lazy_find_by_contents q, options - else - ar_find_by_contents q, options, find_options - end - end - - def ar_find_by_contents(q, options = {}, find_options = {}) - result_ids = {} - total_hits = find_id_by_contents(q, options) do |model, id, score, data| - # stores ids, index of each id for later ordering of - # results, and score - result_ids[id] = [ result_ids.size + 1, score ] - end - - result = retrieve_records( { self.name => result_ids }, find_options ) - - if find_options[:conditions] - if options[:limit] != :all - # correct result size if the user specified conditions - # wenn conditions: options[:limit] != :all --> ferret-query mit :all wiederholen und select count machen - result_ids = {} - find_id_by_contents(q, options.update(:limit => :all)) do |model, id, score, data| - result_ids[id] = [ result_ids.size + 1, score ] - end - total_hits = count_records( { self.name => result_ids }, find_options ) - else - total_hits = result.length - end - end - - [ total_hits, result ] - end - - def lazy_find_by_contents(q, options = {}) - result = [] - total_hits = find_id_by_contents(q, options) do |model, id, score, data| - result << FerretResult.new(model, id, score, data) - end - [ total_hits, result ] - end - - - def model_find(model, id, find_options = {}) - model.constantize.find(id, find_options) - end - - # retrieves search result records from a data structure like this: - # { 'Model1' => { '1' => [ rank, score ], '2' => [ rank, score ] } - # - # TODO: in case of STI AR will filter out hits from other - # classes for us, but this - # will lead to less results retrieved --> scoping of ferret query - # to self.class is still needed. - # from the ferret ML (thanks Curtis Hatter) - # > I created a method in my base STI class so I can scope my query. For scoping - # > I used something like the following line: - # > - # > query << " role:#{self.class.eql?(Contents) '*' : self.class}" - # > - # > Though you could make it more generic by simply asking - # > "self.descends_from_active_record?" which is how rails decides if it should - # > scope your "find" query for STI models. You can check out "base.rb" in - # > activerecord to see that. - # but maybe better do the scoping in find_id_by_contents... - def retrieve_records(id_arrays, find_options = {}) - result = [] - # get objects for each model - id_arrays.each do |model, id_array| - next if id_array.empty? - begin - model = model.constantize - rescue - raise "Please use ':store_class_name => true' if you want to use multi_search.\n#{$!}" - end - - # check for include association that might only exist on some models in case of multi_search - filtered_include_options = [] - if include_options = find_options[:include] - include_options.each do |include_option| - filtered_include_options << include_option if model.reflections.has_key?(include_option.is_a?(Hash) ? include_option.keys[0].to_sym : include_option.to_sym) - end - end - filtered_include_options=nil if filtered_include_options.empty? - - # fetch - tmp_result = nil - model.send(:with_scope, :find => find_options) do - tmp_result = model.find( :all, :conditions => [ - "#{model.table_name}.#{model.primary_key} in (?)", id_array.keys ], - :include => filtered_include_options ) - end - - # set scores and rank - tmp_result.each do |record| - record.ferret_rank, record.ferret_score = id_array[record.id.to_s] - end - # merge with result array - result.concat tmp_result - end - - # order results as they were found by ferret, unless an AR :order - # option was given - result.sort! { |a, b| a.ferret_rank <=> b.ferret_rank } unless find_options[:order] - return result - end - - def count_records(id_arrays, find_options = {}) - count = 0 - id_arrays.each do |model, id_array| - next if id_array.empty? - begin - model = model.constantize - model.send(:with_scope, :find => find_options) do - count += model.count(:conditions => [ "#{model.table_name}.#{model.primary_key} in (?)", - id_array.keys ]) - end - rescue TypeError - raise "#{model} must use :store_class_name option if you want to use multi_search against it.\n#{$!}" - end - end - count - end - - def deprecated_options_support(options) - if options[:num_docs] - logger.warn ":num_docs is deprecated, use :limit instead!" - options[:limit] ||= options[:num_docs] - end - if options[:first_doc] - logger.warn ":first_doc is deprecated, use :offset instead!" - options[:offset] ||= options[:first_doc] - end - end - - # creates a new Index instance. - def create_index_instance - if aaf_configuration[:remote] - RemoteIndex - elsif aaf_configuration[:single_index] - SharedIndex - else - LocalIndex - end.new(aaf_configuration) - end - - end - -end - diff --git a/vendor/plugins/acts_as_ferret/lib/ferret_cap_tasks.rb b/vendor/plugins/acts_as_ferret/lib/ferret_cap_tasks.rb deleted file mode 100644 index 569c169..0000000 --- a/vendor/plugins/acts_as_ferret/lib/ferret_cap_tasks.rb +++ /dev/null @@ -1,21 +0,0 @@ -# Ferret DRb server Capistrano tasks -# Usage: -# Add require 'vendor/plugins/acts_as_ferret/lib/ferret_cap_tasks' to your -# config/deploy.rb -# call ferret.restart where you restart your Mongrels. -# ferret.stop and ferret.start are available, too. -module FerretCapTasks - def start - run "cd #{current_path}; RAILS_ENV=production script/ferret_start" - end - - def stop - run "cd #{current_path}; RAILS_ENV=production script/ferret_stop" - end - - def restart - stop - start - end -end -Capistrano.plugin :ferret, FerretCapTasks diff --git a/vendor/plugins/acts_as_ferret/lib/ferret_extensions.rb b/vendor/plugins/acts_as_ferret/lib/ferret_extensions.rb deleted file mode 100644 index efffe1d..0000000 --- a/vendor/plugins/acts_as_ferret/lib/ferret_extensions.rb +++ /dev/null @@ -1,81 +0,0 @@ -module Ferret - - - class Index::Index - attr_accessor :batch_size - attr_accessor :logger - - def index_models(models) - models.each { |model| index_model model } - flush - optimize - close - ActsAsFerret::close_multi_indexes - end - - def index_model(model) - @batch_size ||= 0 - work_done = 0 - batch_time = 0 - logger.info "reindexing model #{model.name}" - - model_count = model.count.to_f - model.records_for_rebuild(@batch_size) do |records, offset| - #records = [ records ] unless records.is_a?(Array) - batch_time = measure_time { - records.each { |rec| self << rec.to_doc if rec.ferret_enabled?(true) } - }.to_f - work_done = offset.to_f / model_count * 100.0 if model_count > 0 - remaining_time = ( batch_time / @batch_size ) * ( model_count - offset + @batch_size ) - logger.info "reindex model #{model.name} : #{'%.2f' % work_done}% complete : #{'%.2f' % remaining_time} secs to finish" - end - end - - def measure_time - t1 = Time.now - yield - Time.now - t1 - end - - end - - - # add marshalling support to SortFields - class Search::SortField - def _dump(depth) - to_s - end - - def self._load(string) - case string - when /!/ : Ferret::Search::SortField::DOC_ID_REV - when // : Ferret::Search::SortField::DOC_ID - when '!' : Ferret::Search::SortField::SCORE_REV - when '' : Ferret::Search::SortField::SCORE - when /^(\w+):<(\w+)>(!)?$/ : new($1.to_sym, :type => $2.to_sym, :reverse => !$3.nil?) - else raise "invalid value: #{string}" - end - end - end - - # add marshalling support to Sort - class Search::Sort - def _dump(depth) - to_s - end - - def self._load(string) - # we exclude the last sorting as it is appended by new anyway - if string =~ /^Sort\[(.*?)((!)?)?\]$/ - sort_fields = $1.split(',').map do |value| - value.strip! - Ferret::Search::SortField._load value unless value.blank? - end - new sort_fields.compact - else - raise "invalid value: #{string}" - end - end - end - -end diff --git a/vendor/plugins/acts_as_ferret/lib/ferret_result.rb b/vendor/plugins/acts_as_ferret/lib/ferret_result.rb deleted file mode 100644 index 457926c..0000000 --- a/vendor/plugins/acts_as_ferret/lib/ferret_result.rb +++ /dev/null @@ -1,36 +0,0 @@ -module ActsAsFerret - - # mixed into the FerretResult and AR classes calling acts_as_ferret - module ResultAttributes - # holds the score this record had when it was found via - # acts_as_ferret - attr_accessor :ferret_score - - attr_accessor :ferret_rank - end - - class FerretResult - include ResultAttributes - attr_accessor :id - - def initialize(model, id, score, data = {}) - @model = model.constantize - @id = id - @ferret_score = score - @data = data - end - - def method_missing(method, *args) - if @ar_record || @data[method].nil? - ferret_load_record unless @ar_record - @ar_record.send method, *args - else - @data[method] - end - end - - def ferret_load_record - @ar_record = @model.find(id) - end - end -end diff --git a/vendor/plugins/acts_as_ferret/lib/ferret_server.rb b/vendor/plugins/acts_as_ferret/lib/ferret_server.rb deleted file mode 100644 index b5673f8..0000000 --- a/vendor/plugins/acts_as_ferret/lib/ferret_server.rb +++ /dev/null @@ -1,131 +0,0 @@ -require 'drb' -require 'thread' -require 'yaml' -require 'erb' - - -module ActsAsFerret - - module Remote - - module Config - class << self - DEFAULTS = { - 'host' => 'localhost', - 'port' => '9009' - } - # read connection settings from config file - def load(file = "#{RAILS_ROOT}/config/ferret_server.yml") - config = DEFAULTS.merge(YAML.load(ERB.new(IO.read(file)).result)) - if config = config[RAILS_ENV] - config[:uri] = "druby://#{config['host']}:#{config['port']}" - return config - end - {} - end - end - end - - # This class acts as a drb server listening for indexing and - # search requests from models declared to 'acts_as_ferret :remote => true' - # - # Usage: - # - modify RAILS_ROOT/config/ferret_server.yml to suit your needs. - # - environments for which no section in the config file exists will use - # the index locally (good for unit tests/development mode) - # - run script/ferret_start to start the server: - # RAILS_ENV=production script/ferret_start - # - class Server - - cattr_accessor :running - - def self.start(uri = nil) - ActiveRecord::Base.allow_concurrency = true - ActiveRecord::Base.logger = Logger.new("#{RAILS_ROOT}/log/ferret_server.log") - uri ||= ActsAsFerret::Remote::Config.load[:uri] - DRb.start_service(uri, ActsAsFerret::Remote::Server.new) - self.running = true - end - - def initialize - @logger = ActiveRecord::Base.logger - end - - # handles all incoming method calls, and sends them on to the LocalIndex - # instance of the correct model class. - # - # Calls are not queued atm, so this will block until the call returned. - # - def method_missing(name, *args) - @logger.debug "\#method_missing(#{name.inspect}, #{args.inspect})" - with_class args.shift do |clazz| - begin - clazz.aaf_index.send name, *args - rescue NoMethodError - @logger.debug "no luck, trying to call class method instead" - clazz.send name, *args - end - end - rescue - @logger.error "ferret server error #{$!}\n#{$!.backtrace.join '\n'}" - raise - end - - # make sure we have a versioned index in place, building one if necessary - def ensure_index_exists(class_name) - @logger.debug "DRb server: ensure_index_exists for class #{class_name}" - with_class class_name do |clazz| - dir = clazz.aaf_configuration[:index_dir] - unless File.directory?(dir) && File.file?(File.join(dir, 'segments')) && dir =~ %r{/\d+(_\d+)?$} - rebuild_index(clazz) - end - end - end - - # hides LocalIndex#rebuild_index to implement index versioning - def rebuild_index(clazz, *models) - with_class clazz do |clazz| - models = models.flatten.uniq.map(&:constantize) - models << clazz unless models.include?(clazz) - index = new_index_for(clazz, models) - @logger.debug "DRb server: rebuild index for class(es) #{models.inspect} in #{index.options[:path]}" - index.index_models models - new_version = File.join clazz.aaf_configuration[:index_base_dir], Time.now.utc.strftime('%Y%m%d%H%M%S') - # create a unique directory name (needed for unit tests where - # multiple rebuilds per second may occur) - if File.exists?(new_version) - i = 0 - i+=1 while File.exists?("#{new_version}_#{i}") - new_version << "_#{i}" - end - - File.rename index.options[:path], new_version - clazz.index_dir = new_version - end - end - - - protected - - def with_class(clazz, *args) - clazz = clazz.constantize if String === clazz - yield clazz, *args - end - - def new_index_for(clazz, models) - aaf_configuration = clazz.aaf_configuration - ferret_cfg = aaf_configuration[:ferret].dup - ferret_cfg.update :auto_flush => false, - :create => true, - :field_infos => ActsAsFerret::field_infos(models), - :path => File.join(aaf_configuration[:index_base_dir], 'rebuild') - returning Ferret::Index::Index.new ferret_cfg do |i| - i.batch_size = aaf_configuration[:reindex_batch_size] - i.logger = @logger - end - end - - end - end -end diff --git a/vendor/plugins/acts_as_ferret/lib/index.rb b/vendor/plugins/acts_as_ferret/lib/index.rb deleted file mode 100644 index 26e39ad..0000000 --- a/vendor/plugins/acts_as_ferret/lib/index.rb +++ /dev/null @@ -1,31 +0,0 @@ -module ActsAsFerret - - # base class for local and remote indexes - class AbstractIndex - - attr_reader :aaf_configuration - attr_accessor :logger - def initialize(aaf_configuration) - @aaf_configuration = aaf_configuration - @logger = Logger.new("#{RAILS_ROOT}/log/ferret_index.log") - end - - class << self - def proxy_method(name, *args) - define_method name do |*args| - @server.send name, model_class_name, *args - end - end - - def index_proxy_method(*names) - names.each do |name| - define_method name do |*args| - @server.send :"index_#{name}", model_class_name, *args - end - end - end - - end - end - -end diff --git a/vendor/plugins/acts_as_ferret/lib/instance_methods.rb b/vendor/plugins/acts_as_ferret/lib/instance_methods.rb deleted file mode 100644 index f83ab28..0000000 --- a/vendor/plugins/acts_as_ferret/lib/instance_methods.rb +++ /dev/null @@ -1,126 +0,0 @@ -module ActsAsFerret #:nodoc: - - module InstanceMethods - include ResultAttributes - - # Returns an array of strings with the matches highlighted. The +query+ can - # either be a String or a Ferret::Search::Query object. - # - # === Options - # - # field:: field to take the content from. This field has - # to have it's content stored in the index - # (:store => :yes in your call to aaf). If not - # given, all stored fields are searched, and the - # highlighted content found in all of them is returned. - # set :highlight => :no in the field options to - # avoid highlighting of contents from a :stored field. - # excerpt_length:: Default: 150. Length of excerpt to show. Highlighted - # terms will be in the centre of the excerpt. - # num_excerpts:: Default: 2. Number of excerpts to return. - # pre_tag:: Default: "". Tag to place to the left of the - # match. - # post_tag:: Default: "". This tag should close the - # +:pre_tag+. - # ellipsis:: Default: "...". This is the string that is appended - # at the beginning and end of excerpts (unless the - # excerpt hits the start or end of the field. You'll - # probably want to change this so a Unicode elipsis - # character. - def highlight(query, options = {}) - self.class.aaf_index.highlight(id, self.class.name, query, options) - end - - # re-eneable ferret indexing after a call to #disable_ferret - def ferret_enable; @ferret_disabled = nil end - - # returns true if ferret indexing is enabled - # the optional parameter will be true if the method is called by rebuild_index, - # and false otherwise. I.e. useful to enable a model only for indexing during - # scheduled reindex runs. - def ferret_enabled?(is_rebuild = false); @ferret_disabled.nil? end - - # Disable Ferret for a specified amount of time. ::once will disable - # Ferret for the next call to #save (this is the default), ::always will - # do so for all subsequent calls. - # To manually trigger reindexing of a record, you can call #ferret_update - # directly. - # - # When given a block, this will be executed without any ferret indexing of - # this object taking place. The optional argument in this case can be used - # to indicate if the object should be indexed after executing the block - # (::index_when_finished). Automatic Ferret indexing of this object will be - # turned on after the block has been executed. If passed ::index_when_true, - # the index will only be updated if the block evaluated not to false or nil. - def disable_ferret(option = :once) - if block_given? - @ferret_disabled = :always - result = yield - ferret_enable - ferret_update if option == :index_when_finished || (option == :index_when_true && result) - result - elsif [:once, :always].include?(option) - @ferret_disabled = option - else - raise ArgumentError.new("Invalid Argument #{option}") - end - end - - # add to index - def ferret_create - if ferret_enabled? - logger.debug "ferret_create/update: #{self.class.name} : #{self.id}" - self.class.aaf_index << self - else - ferret_enable if @ferret_disabled == :once - end - true # signal success to AR - end - alias :ferret_update :ferret_create - - - # remove from index - def ferret_destroy - logger.debug "ferret_destroy: #{self.class.name} : #{self.id}" - begin - self.class.aaf_index.remove self.id, self.class.name - rescue - logger.warn("Could not find indexed value for this object: #{$!}\n#{$!.backtrace}") - end - true # signal success to AR - end - - # turn this instance into a ferret document (which basically is a hash of - # fieldname => value pairs) - def to_doc - logger.debug "creating doc for class: #{self.class.name}, id: #{self.id}" - returning doc = Ferret::Document.new do - # store the id of each item - doc[:id] = self.id - - # store the class name if configured to do so - doc[:class_name] = self.class.name if aaf_configuration[:store_class_name] - - # iterate through the fields and add them to the document - aaf_configuration[:ferret_fields].each_pair do |field, config| - doc[field] = self.send("#{field}_to_ferret") unless config[:ignore] - end - end - end - - def document_number - self.class.aaf_index.document_number(id, self.class.name) - end - - def query_for_record - self.class.aaf_index.query_for_record(id, self.class.name) - end - - def content_for_field_name(field) - self[field] || self.instance_variable_get("@#{field.to_s}".to_sym) || self.send(field.to_sym) - end - - - end - -end diff --git a/vendor/plugins/acts_as_ferret/lib/local_index.rb b/vendor/plugins/acts_as_ferret/lib/local_index.rb deleted file mode 100644 index d678ee2..0000000 --- a/vendor/plugins/acts_as_ferret/lib/local_index.rb +++ /dev/null @@ -1,209 +0,0 @@ -module ActsAsFerret - - class LocalIndex < AbstractIndex - include MoreLikeThis::IndexMethods - - - def initialize(aaf_configuration) - super - ensure_index_exists - end - - def reopen! - if @ferret_index - @ferret_index.close - @ferret_index = nil - end - logger.debug "reopening index at #{aaf_configuration[:ferret][:path]}" - ferret_index - end - - # The 'real' Ferret Index instance - def ferret_index - ensure_index_exists - returning @ferret_index ||= Ferret::Index::Index.new(aaf_configuration[:ferret]) do - @ferret_index.batch_size = aaf_configuration[:reindex_batch_size] - @ferret_index.logger = logger - end - end - - # Checks for the presence of a segments file in the index directory - # Rebuilds the index if none exists. - def ensure_index_exists - logger.debug "LocalIndex: ensure_index_exists at #{aaf_configuration[:index_dir]}" - unless File.file? "#{aaf_configuration[:index_dir]}/segments" - ActsAsFerret::ensure_directory(aaf_configuration[:index_dir]) - close - rebuild_index - end - end - - # Closes the underlying index instance - def close - @ferret_index.close if @ferret_index - rescue StandardError - # is raised when index already closed - ensure - @ferret_index = nil - end - - # rebuilds the index from all records of the model class this index belongs - # to. Arguments can be given in shared index scenarios to name multiple - # model classes to include in the index - def rebuild_index(*models) - models << aaf_configuration[:class_name] unless models.include?(aaf_configuration[:class_name]) - models = models.flatten.uniq.map(&:constantize) - logger.debug "rebuild index: #{models.inspect}" - index = Ferret::Index::Index.new(aaf_configuration[:ferret].dup.update(:auto_flush => false, - :field_infos => ActsAsFerret::field_infos(models), - :create => true)) - index.batch_size = aaf_configuration[:reindex_batch_size] - index.logger = logger - index.index_models models - end - - # Parses the given query string into a Ferret Query object. - def process_query(query) - # work around ferret bug in #process_query (doesn't ensure the - # reader is open) - ferret_index.synchronize do - ferret_index.send(:ensure_reader_open) - original_query = ferret_index.process_query(query) - end - end - - # Total number of hits for the given query. - # To count the results of a multi_search query, specify an array of - # class names with the :models option. - def total_hits(query, options = {}) - index = (models = options.delete(:models)) ? multi_index(models) : ferret_index - index.search(query, options).total_hits - end - - def determine_lazy_fields(options = {}) - stored_fields = options[:lazy] - if stored_fields && !(Array === stored_fields) - stored_fields = aaf_configuration[:ferret_fields].select { |field, config| config[:store] == :yes }.map(&:first) - end - logger.debug "stored_fields: #{stored_fields}" - return stored_fields - end - - # Queries the Ferret index to retrieve model class, id, score and the - # values of any fields stored in the index for each hit. - # If a block is given, these are yielded and the number of total hits is - # returned. Otherwise [total_hits, result_array] is returned. - def find_id_by_contents(query, options = {}) - result = [] - index = ferret_index - logger.debug "query: #{ferret_index.process_query query}" # TODO only enable this for debugging purposes - lazy_fields = determine_lazy_fields options - - total_hits = index.search_each(query, options) do |hit, score| - doc = index[hit] - model = aaf_configuration[:store_class_name] ? doc[:class_name] : aaf_configuration[:class_name] - # fetch stored fields if lazy loading - data = {} - lazy_fields.each { |field| data[field] = doc[field] } if lazy_fields - if block_given? - yield model, doc[:id], score, data - else - result << { :model => model, :id => doc[:id], :score => score, :data => data } - end - end - #logger.debug "id_score_model array: #{result.inspect}" - return block_given? ? total_hits : [total_hits, result] - end - - # Queries multiple Ferret indexes to retrieve model class, id and score for - # each hit. Use the models parameter to give the list of models to search. - # If a block is given, model, id and score are yielded and the number of - # total hits is returned. Otherwise [total_hits, result_array] is returned. - def id_multi_search(query, models, options = {}) - index = multi_index(models) - result = [] - lazy_fields = determine_lazy_fields options - total_hits = index.search_each(query, options) do |hit, score| - doc = index[hit] - # fetch stored fields if lazy loading - data = {} - lazy_fields.each { |field| data[field] = doc[field] } if lazy_fields - raise "':store_class_name => true' required for multi_search to work" if doc[:class_name].blank? - if block_given? - yield doc[:class_name], doc[:id], score, doc, data - else - result << { :model => doc[:class_name], :id => doc[:id], :score => score, :data => data } - end - end - return block_given? ? total_hits : [ total_hits, result ] - end - - ###################################### - # methods working on a single record - # called from instance_methods, here to simplify interfacing with the - # remote ferret server - # TODO having to pass id and class_name around like this isn't nice - ###################################### - - # add record to index - # record may be the full AR object, a Ferret document instance or a Hash - def add(record) - record = record.to_doc unless Hash === record || Ferret::Document === record - ferret_index << record - end - alias << add - - # delete record from index - def remove(id, class_name) - ferret_index.query_delete query_for_record(id, class_name) - end - - # highlight search terms for the record with the given id. - def highlight(id, class_name, query, options = {}) - options.reverse_merge! :num_excerpts => 2, :pre_tag => '', :post_tag => '' - highlights = [] - ferret_index.synchronize do - doc_num = document_number(id, class_name) - if options[:field] - highlights << ferret_index.highlight(query, doc_num, options) - else - query = process_query(query) # process only once - aaf_configuration[:ferret_fields].each_pair do |field, config| - next if config[:store] == :no || config[:highlight] == :no - options[:field] = field - highlights << ferret_index.highlight(query, doc_num, options) - end - end - end - return highlights.compact.flatten[0..options[:num_excerpts]-1] - end - - # retrieves the ferret document number of the record with the given id. - def document_number(id, class_name) - hits = ferret_index.search(query_for_record(id, class_name)) - return hits.hits.first.doc if hits.total_hits == 1 - raise "cannot determine document number from primary key: #{id}" - end - - # build a ferret query matching only the record with the given id - # the class name only needs to be given in case of a shared index configuration - def query_for_record(id, class_name = nil) - Ferret::Search::TermQuery.new(:id, id.to_s) - end - - - protected - - # returns a MultiIndex instance operating on a MultiReader - def multi_index(model_classes) - model_classes.map!(&:constantize) if String === model_classes.first - model_classes.sort! { |a, b| a.name <=> b.name } - key = model_classes.inject("") { |s, clazz| s + clazz.name } - multi_config = aaf_configuration[:ferret].dup - multi_config.delete :default_field # we don't want the default field list of *this* class for multi_searching - ActsAsFerret::multi_indexes[key] ||= MultiIndex.new(model_classes, multi_config) - end - - end - -end diff --git a/vendor/plugins/acts_as_ferret/lib/more_like_this.rb b/vendor/plugins/acts_as_ferret/lib/more_like_this.rb deleted file mode 100644 index 72356c5..0000000 --- a/vendor/plugins/acts_as_ferret/lib/more_like_this.rb +++ /dev/null @@ -1,217 +0,0 @@ -module ActsAsFerret #:nodoc: - - module MoreLikeThis - - module InstanceMethods - - # returns other instances of this class, which have similar contents - # like this one. Basically works like this: find out n most interesting - # (i.e. characteristic) terms from this document, and then build a - # query from those which is run against the whole index. Which terms - # are interesting is decided on variour criteria which can be - # influenced by the given options. - # - # The algorithm used here is a quite straight port of the MoreLikeThis class - # from Apache Lucene. - # - # options are: - # :field_names : Array of field names to use for similarity search (mandatory) - # :min_term_freq => 2, # Ignore terms with less than this frequency in the source doc. - # :min_doc_freq => 5, # Ignore words which do not occur in at least this many docs - # :min_word_length => nil, # Ignore words shorter than this length (longer words tend to - # be more characteristic for the document they occur in). - # :max_word_length => nil, # Ignore words if greater than this len. - # :max_query_terms => 25, # maximum number of terms in the query built - # :max_num_tokens => 5000, # maximum number of tokens to examine in a single field - # :boost => false, # when true, a boost according to the relative score of - # a term is applied to this Term's TermQuery. - # :similarity => 'DefaultAAFSimilarity' # the similarity implementation to use (the default - # equals Ferret's internal similarity implementation) - # :analyzer => 'Ferret::Analysis::StandardAnalyzer' # class name of the analyzer to use - # :append_to_query => nil # proc taking a query object as argument, which will be called after generating the query. can be used to further manipulate the query used to find related documents, i.e. to constrain the search to a given class in single table inheritance scenarios - # ferret_options : Ferret options handed over to find_by_contents (i.e. for limits and sorting) - # ar_options : options handed over to find_by_contents for AR scoping - def more_like_this(options = {}, ferret_options = {}, ar_options = {}) - options = { - :field_names => nil, # Default field names - :min_term_freq => 2, # Ignore terms with less than this frequency in the source doc. - :min_doc_freq => 5, # Ignore words which do not occur in at least this many docs - :min_word_length => 0, # Ignore words if less than this len. Default is not to ignore any words. - :max_word_length => 0, # Ignore words if greater than this len. Default is not to ignore any words. - :max_query_terms => 25, # maximum number of terms in the query built - :max_num_tokens => 5000, # maximum number of tokens to analyze when analyzing contents - :boost => false, - :similarity => 'ActsAsFerret::MoreLikeThis::DefaultAAFSimilarity', # class name of the similarity implementation to use - :analyzer => 'Ferret::Analysis::StandardAnalyzer', # class name of the analyzer to use - :append_to_query => nil, - :base_class => self.class # base class to use for querying, useful in STI scenarios where BaseClass.find_by_contents can be used to retrieve results from other classes, too - }.update(options) - #index.search_each('id:*') do |doc, score| - # puts "#{doc} == #{index[doc][:description]}" - #end - clazz = options[:base_class] - options[:base_class] = clazz.name - query = clazz.aaf_index.build_more_like_this_query(self.id, self.class.name, options) - options[:append_to_query].call(query) if options[:append_to_query] - clazz.find_by_contents(query, ferret_options, ar_options) - end - - end - - module IndexMethods - - # TODO to allow morelikethis for unsaved records, we have to give the - # unsaved record's data to this method. check how this will work out - # via drb... - def build_more_like_this_query(id, class_name, options) - [:similarity, :analyzer].each { |sym| options[sym] = options[sym].constantize.new } - ferret_index.synchronize do # avoid that concurrent writes close our reader - ferret_index.send(:ensure_reader_open) - reader = ferret_index.send(:reader) - term_freq_map = retrieve_terms(id, class_name, reader, options) - priority_queue = create_queue(term_freq_map, reader, options) - create_query(id, class_name, priority_queue, options) - end - end - - protected - - def create_query(id, class_name, priority_queue, options={}) - query = Ferret::Search::BooleanQuery.new - qterms = 0 - best_score = nil - while(cur = priority_queue.pop) - term_query = Ferret::Search::TermQuery.new(cur.field, cur.word) - - if options[:boost] - # boost term according to relative score - # TODO untested - best_score ||= cur.score - term_query.boost = cur.score / best_score - end - begin - query.add_query(term_query, :should) - rescue Ferret::Search::BooleanQuery::TooManyClauses - break - end - qterms += 1 - break if options[:max_query_terms] > 0 && qterms >= options[:max_query_terms] - end - # exclude the original record - query.add_query(query_for_record(id, class_name), :must_not) - return query - end - - - - # creates a term/term_frequency map for terms from the fields - # given in options[:field_names] - def retrieve_terms(id, class_name, reader, options) - raise "more_like_this atm only works on saved records" if id.nil? - document_number = document_number(id, class_name) rescue nil - field_names = options[:field_names] - max_num_tokens = options[:max_num_tokens] - term_freq_map = Hash.new(0) - doc = nil - record = nil - field_names.each do |field| - #puts "field: #{field}" - term_freq_vector = reader.term_vector(document_number, field) if document_number - #if false - if term_freq_vector - # use stored term vector - # puts 'using stored term vector' - term_freq_vector.terms.each do |term| - term_freq_map[term.text] += term.positions.size unless noise_word?(term.text, options) - end - else - # puts 'no stored term vector' - # no term vector stored, but we have stored the contents in the index - # -> extract terms from there - content = nil - if document_number - doc = reader[document_number] - content = doc[field] - end - unless content - # no term vector, no stored content, so try content from this instance - record ||= options[:base_class].constantize.find(id) - content = record.content_for_field_name(field.to_s) - end - puts "have doc: #{doc[:id]} with #{field} == #{content}" - token_count = 0 - - ts = options[:analyzer].token_stream(field, content) - while token = ts.next - break if (token_count+=1) > max_num_tokens - next if noise_word?(token.text, options) - term_freq_map[token.text] += 1 - end - end - end - term_freq_map - end - - # create an ordered(by score) list of word,fieldname,score - # structures - def create_queue(term_freq_map, reader, options) - pq = Array.new(term_freq_map.size) - - similarity = options[:similarity] - num_docs = reader.num_docs - term_freq_map.each_pair do |word, tf| - # filter out words that don't occur enough times in the source - next if options[:min_term_freq] && tf < options[:min_term_freq] - - # go through all the fields and find the largest document frequency - top_field = options[:field_names].first - doc_freq = 0 - options[:field_names].each do |field_name| - freq = reader.doc_freq(field_name, word) - if freq > doc_freq - top_field = field_name - doc_freq = freq - end - end - # filter out words that don't occur in enough docs - next if options[:min_doc_freq] && doc_freq < options[:min_doc_freq] - next if doc_freq == 0 # index update problem ? - - idf = similarity.idf(doc_freq, num_docs) - score = tf * idf - pq << FrequencyQueueItem.new(word, top_field, score) - end - pq.compact! - pq.sort! { |a,b| a.score<=>b.score } - return pq - end - - def noise_word?(text, options) - len = text.length - ( - (options[:min_word_length] > 0 && len < options[:min_word_length]) || - (options[:max_word_length] > 0 && len > options[:max_word_length]) || - (options[:stop_words] && options.include?(text)) - ) - end - - end - - class DefaultAAFSimilarity - def idf(doc_freq, num_docs) - return 0.0 if num_docs == 0 - return Math.log(num_docs.to_f/(doc_freq+1)) + 1.0 - end - end - - - class FrequencyQueueItem - attr_reader :word, :field, :score - def initialize(word, field, score) - @word = word; @field = field; @score = score - end - end - - end -end - diff --git a/vendor/plugins/acts_as_ferret/lib/multi_index.rb b/vendor/plugins/acts_as_ferret/lib/multi_index.rb deleted file mode 100644 index adbfb7b..0000000 --- a/vendor/plugins/acts_as_ferret/lib/multi_index.rb +++ /dev/null @@ -1,83 +0,0 @@ -module ActsAsFerret #:nodoc: - - # this class is not threadsafe - class MultiIndex - - def initialize(model_classes, options = {}) - @model_classes = model_classes - # ensure all models indexes exist - @model_classes.each { |m| m.aaf_index.ensure_index_exists } - default_fields = @model_classes.inject([]) do |fields, c| - fields + [ c.aaf_configuration[:ferret][:default_field] ].flatten - end - @options = { - :default_field => default_fields - }.update(options) - end - - def search(query, options={}) - #puts "querystring: #{query.to_s}" - query = process_query(query) - #puts "parsed query: #{query.to_s}" - searcher.search(query, options) - end - - def search_each(query, options = {}, &block) - query = process_query(query) - searcher.search_each(query, options, &block) - end - - # checks if all our sub-searchers still are up to date - def latest? - return false unless @reader - # segfaults with 0.10.4 --> TODO report as bug @reader.latest? - @sub_readers.each do |r| - return false unless r.latest? - end - true - end - - def searcher - ensure_searcher - @searcher - end - - def doc(i) - searcher[i] - end - alias :[] :doc - - def query_parser - @query_parser ||= Ferret::QueryParser.new(@options) - end - - def process_query(query) - query = query_parser.parse(query) if query.is_a?(String) - return query - end - - def close - @searcher.close if @searcher - @reader.close if @reader - end - - protected - - def ensure_searcher - unless latest? - @sub_readers = @model_classes.map { |clazz| - begin - reader = Ferret::Index::IndexReader.new(clazz.aaf_configuration[:index_dir]) - rescue Exception - raise "error opening #{clazz.aaf_configuration[:index_dir]}: #{$!}" - end - } - close - @reader = Ferret::Index::IndexReader.new(@sub_readers) - @searcher = Ferret::Search::Searcher.new(@reader) - end - end - - end # of class MultiIndex - -end diff --git a/vendor/plugins/acts_as_ferret/lib/remote_index.rb b/vendor/plugins/acts_as_ferret/lib/remote_index.rb deleted file mode 100644 index 30ae3a7..0000000 --- a/vendor/plugins/acts_as_ferret/lib/remote_index.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'drb' -module ActsAsFerret - - # This index implementation connects to a remote ferret server instance. It - # basically forwards all calls to the remote server. - class RemoteIndex < AbstractIndex - - def initialize(config) - @config = config - @ferret_config = config[:ferret] - @server = DRbObject.new(nil, config[:remote]) - end - - def method_missing(method_name, *args) - args.unshift model_class_name - @server.send(method_name, *args) - end - - def find_id_by_contents(q, options = {}, &proc) - total_hits, results = @server.find_id_by_contents(model_class_name, q, options) - block_given? ? yield_results(total_hits, results, &proc) : [ total_hits, results ] - end - - def id_multi_search(query, models, options, &proc) - total_hits, results = @server.id_multi_search(model_class_name, query, models, options) - block_given? ? yield_results(total_hits, results, &proc) : [ total_hits, results ] - end - - # add record to index - def add(record) - @server.add record.class.name, record.to_doc - end - alias << add - - private - - def yield_results(total_hits, results) - results.each do |result| - yield result[:model], result[:id], result[:score], result[:data] - end - total_hits - end - - def model_class_name - @config[:class_name] - end - - end - -end diff --git a/vendor/plugins/acts_as_ferret/lib/shared_index.rb b/vendor/plugins/acts_as_ferret/lib/shared_index.rb deleted file mode 100644 index 21cadfd..0000000 --- a/vendor/plugins/acts_as_ferret/lib/shared_index.rb +++ /dev/null @@ -1,14 +0,0 @@ -module ActsAsFerret - - class SharedIndex < LocalIndex - - # build a ferret query matching only the record with the given id and class - def query_for_record(id, class_name) - returning bq = Ferret::Search::BooleanQuery.new do - bq.add_query(Ferret::Search::TermQuery.new(:id, id.to_s), :must) - bq.add_query(Ferret::Search::TermQuery.new(:class_name, class_name), :must) - end - end - - end -end diff --git a/vendor/plugins/acts_as_ferret/lib/shared_index_class_methods.rb b/vendor/plugins/acts_as_ferret/lib/shared_index_class_methods.rb deleted file mode 100644 index 047b945..0000000 --- a/vendor/plugins/acts_as_ferret/lib/shared_index_class_methods.rb +++ /dev/null @@ -1,90 +0,0 @@ -module ActsAsFerret - - # class methods for classes using acts_as_ferret :single_index => true - module SharedIndexClassMethods - - def find_id_by_contents(q, options = {}, &block) - # add class name scoping to query if necessary - unless options[:models] == :all # search needs to be restricted by one or more class names - options[:models] ||= [] - # add this class to the list of given models - options[:models] << self unless options[:models].include?(self) - # keep original query - original_query = q - - if original_query.is_a? String - model_query = options[:models].map(&:name).join '|' - q << %{ +class_name:"#{model_query}"} - else - q = Ferret::Search::BooleanQuery.new - q.add_query(original_query, :must) - model_query = Ferret::Search::BooleanQuery.new - options[:models].each do |model| - model_query.add_query(Ferret::Search::TermQuery.new(:class_name, model.name), :should) - end - q.add_query(model_query, :must) - end - end - options.delete :models - - super(q, options, &block) - end - - # Overrides the standard find_by_contents for searching a shared index. - # - # please note that records from different models will be fetched in - # separate sql calls, so any sql order_by clause given with - # find_options[:order] will be ignored. - def find_by_contents(q, options = {}, find_options = {}) - if order = find_options.delete(:order) - logger.warn "using a shared index, so ignoring order_by clause #{order}" - end - total_hits, result = find_records_lazy_or_not q, options, find_options - # sort so results have the same order they had when originally retrieved - # from ferret - return SearchResults.new(result, total_hits) - end - - protected - - def ar_find_by_contents(q, options = {}, find_options = {}) - total_hits, id_arrays = collect_results(q, options) - result = retrieve_records(id_arrays, find_options) - result.sort! { |a, b| id_arrays[a.class.name][a.id.to_s].first <=> id_arrays[b.class.name][b.id.to_s].first } - [ total_hits, result ] - end - - def collect_results(q, options = {}) - id_arrays = {} - # get object ids for index hits - rank = 0 - total_hits = find_id_by_contents(q, options) do |model, id, score, data| - id_arrays[model] ||= {} - # store result rank and score - id_arrays[model][id] = [ rank += 1, score ] - end - [ total_hits, id_arrays ] - end - - - # determine all field names in the shared index - # TODO unused -# def single_index_field_names(models) -# @single_index_field_names ||= ( -# searcher = Ferret::Search::Searcher.new(class_index_dir) -# if searcher.reader.respond_to?(:get_field_names) -# (searcher.reader.send(:get_field_names) - ['id', 'class_name']).to_a -# else -# puts <<-END -#unable to retrieve field names for class #{self.name}, please -#consider naming all indexed fields in your call to acts_as_ferret! -# END -# models.map { |m| m.content_columns.map { |col| col.name } }.flatten -# end -# ) -# -# end - - end -end - diff --git a/vendor/plugins/acts_as_ferret/rakefile b/vendor/plugins/acts_as_ferret/rakefile deleted file mode 100644 index e614565..0000000 --- a/vendor/plugins/acts_as_ferret/rakefile +++ /dev/null @@ -1,131 +0,0 @@ -# rakefile for acts_as_ferret. -# use to create a gem or generate rdoc api documentation. -# -# RELEASE creation: -# rake release REL=x.y.z - -require 'rake' -require 'rake/rdoctask' -require 'rake/packagetask' -require 'rake/gempackagetask' -require 'rake/testtask' -require 'rake/contrib/rubyforgepublisher' - -def announce(msg='') - STDERR.puts msg -end - - -PKG_NAME = 'acts_as_ferret' -PKG_VERSION = ENV['REL'] -PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}" -RUBYFORGE_PROJECT = 'actsasferret' -RUBYFORGE_USER = 'jkraemer' - -desc 'Default: run unit tests.' -task :default => :test - -desc 'Test the acts_as_ferret plugin.' -Rake::TestTask.new(:test) do |t| - t.libs << 'lib' - t.pattern = 'test/**/*_test.rb' - t.verbose = true -end - -desc 'Generate documentation for the acts_as_ferret plugin.' -Rake::RDocTask.new(:rdoc) do |rdoc| - rdoc.rdoc_dir = 'html' - rdoc.title = "acts_as_ferret - Ferret based full text search for any ActiveRecord model" - rdoc.options << '--line-numbers' << '--inline-source' - rdoc.options << '--main' << 'README' - rdoc.rdoc_files.include('README', 'LICENSE') - rdoc.template = "#{ENV['template']}.rb" if ENV['template'] - rdoc.rdoc_files.include('lib/**/*.rb') -end - -desc "Publish the API documentation" -task :pdoc => [:rdoc] do - Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, RUBYFORGE_USER).upload -end - -if PKG_VERSION - spec = Gem::Specification.new do |s| - s.name = PKG_NAME - s.version = PKG_VERSION - s.platform = Gem::Platform::RUBY - s.summary = "acts_as_ferret - Ferret based full text search for any ActiveRecord model" - s.files = Dir.glob('**/*', File::FNM_DOTMATCH).reject do |f| - [ /\.$/, /sqlite$/, /\.log$/, /^pkg/, /\.svn/, /\.\w+\.sw.$/, - /^html/, /\~$/, /\/\._/, /\/#/ ].any? {|regex| f =~ regex } - end - #s.files = FileList["{lib,test}/**/*"].to_a + %w(README MIT-LICENSE CHANGELOG) - # s.files.delete ... - s.require_path = 'lib' - s.autorequire = 'acts_as_ferret' - s.has_rdoc = true - # s.test_files = Dir['test/**/*_test.rb'] - s.author = "Jens Kraemer" - s.email = "jk@jkraemer.net" - s.homepage = "http://projects.jkraemer.net/acts_as_ferret" - end - - package_task = Rake::GemPackageTask.new(spec) do |pkg| - pkg.need_tar = true - end - - # Validate that everything is ready to go for a release. - task :prerelease do - announce - announce "**************************************************************" - announce "* Making RubyGem Release #{PKG_VERSION}" - announce "**************************************************************" - announce - # Are all source files checked in? - if ENV['RELTEST'] - announce "Release Task Testing, skipping checked-in file test" - else - announce "Pulling in svn..." - `svk pull .` - announce "Checking for unchecked-in files..." - data = `svk st` - unless data =~ /^$/ - fail "SVK status is not clean ... do you have unchecked-in files?" - end - announce "No outstanding checkins found ... OK" - announce "Pushing to svn..." - `svk push .` - end - end - - - desc "tag the new release" - task :tag => [ :prerelease ] do - reltag = "REL_#{PKG_VERSION.gsub(/\./, '_')}" - reltag << ENV['REUSE'].gsub(/\./, '_') if ENV['REUSE'] - announce "Tagging with [#{PKG_VERSION}]" - if ENV['RELTEST'] - announce "Release Task Testing, skipping tagging" - else - `svn copy -m 'tagging version #{PKG_VERSION}' svn://projects.jkraemer.net/acts_as_ferret/trunk/plugin svn://projects.jkraemer.net/acts_as_ferret/tags/#{PKG_VERSION}` - `svn del -m 'remove old stable' svn://projects.jkraemer.net/acts_as_ferret/tags/stable` - `svn copy -m 'tagging version #{PKG_VERSION} as stable' svn://projects.jkraemer.net/acts_as_ferret/tags/#{PKG_VERSION} svn://projects.jkraemer.net/acts_as_ferret/tags/stable` - end - end - - # Upload release to rubyforge - desc "Upload release to rubyforge" - task :prel => [ :tag, :prerelease, :package ] do - `rubyforge login` - release_command = "rubyforge add_release #{RUBYFORGE_PROJECT} #{PKG_NAME} '#{PKG_VERSION}' pkg/#{PKG_NAME}-#{PKG_VERSION}.gem" - puts release_command - system(release_command) - `rubyforge config #{RUBYFORGE_PROJECT}` - release_command = "rubyforge add_file #{RUBYFORGE_PROJECT} #{PKG_NAME} '#{PKG_VERSION}' pkg/#{PKG_NAME}-#{PKG_VERSION}.tgz" - puts release_command - system(release_command) - end - - desc 'Publish the gem and API docs' - task :release => [:pdoc, :prel ] - -end diff --git a/vendor/plugins/acts_as_ferret/script/ferret_server b/vendor/plugins/acts_as_ferret/script/ferret_server deleted file mode 100644 index 374a22e..0000000 --- a/vendor/plugins/acts_as_ferret/script/ferret_server +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env ruby - -# Ferret DRb server launcher script -# -# Place doc/ferret_server.yml into RAILS_ROOT/config and fit to taste. -# -# Start this script with script/runner and RAILS_ENV set. -# -# to run the unit tests against the drb server, start it with -# RAILS_ENV=test script/runner script/ferret_server -# and run your tests with the AAF_REMOTE environment variable set to a -# non-empty value - - -ActsAsFerret::Remote::Server.start -DRb.thread.join - - diff --git a/vendor/plugins/acts_as_ferret/script/ferret_start b/vendor/plugins/acts_as_ferret/script/ferret_start deleted file mode 100755 index 50e1909..0000000 --- a/vendor/plugins/acts_as_ferret/script/ferret_start +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env ruby -# Ferret DRb server launcher script -# -# Place doc/ferret_server.yml into RAILS_ROOT/config and fit to taste. Start -# it with RAILS_ENV set to the desired environment. -# -# -# To run the demo project's unit tests against the drb server, start it with -# -# RAILS_ENV=test script/ferret_start -# -# and run your tests with the AAF_REMOTE environment variable set to a -# non-empty value: -# -# AAF_REMOTE=true rake -# -# The server writes a log file in log/ferret_server.log, it's -# STDOUT gets redirected to log/ferret_server.out - -ENV['FERRET_USE_LOCAL_INDEX'] = 'true' -require File.dirname(__FILE__) + '/../config/boot' -require RAILS_ROOT + '/config/environment' - - -config = ActsAsFerret::Remote::Config.load -@pid_file = config['pid_file'] - -def write_pid_file - raise "No PID file defined" if @pid_file.blank? - open(@pid_file,"w") {|f| f.write(Process.pid) } -end - -def safefork - tryagain = true - - while tryagain - tryagain = false - begin - if pid = fork - return pid - end - rescue Errno::EWOULDBLOCK - sleep 5 - tryagain = true - end - end -end - -safefork and exit -at_exit do - File.unlink(@pid_file) if @pid_file && File.exists?(@pid_file) && File.read(@pid_file).to_i == Process.pid -end -print "Starting ferret DRb server..." -trap("TERM") { exit(0) } -sess_id = Process.setsid - - -begin - ActsAsFerret::Remote::Server.start - write_pid_file - puts "Done." - STDIN.reopen "/dev/null" # Free file descriptors and - STDOUT.reopen "#{RAILS_ROOT}/log/ferret_server.out", "a" # point them somewhere sensible - STDERR.reopen STDOUT # STDOUT/STDERR should go to a logfile -rescue - $stderr.puts "Error starting ferret DRb server: #{$!}" - $stderr.puts $!.backtrace - exit(1) -end -DRb.thread.join - -# vim:set filetype=ruby: diff --git a/vendor/plugins/acts_as_ferret/script/ferret_stop b/vendor/plugins/acts_as_ferret/script/ferret_stop deleted file mode 100755 index 63b6952..0000000 --- a/vendor/plugins/acts_as_ferret/script/ferret_stop +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env script/runner - -config = ActsAsFerret::Remote::Config.load - -def send_signal(signal, pid_file) - pid = open(pid_file).read.to_i - print "Sending #{signal} to ferret_server with PID #{pid}..." - begin - Process.kill(signal, pid) - rescue Errno::ESRCH - puts "Process does not exist. Not running. Removing stale pid file anyway." - File.unlink(pid_file) - end - - puts "Done." -end - -pid_file = config['pid_file'] -puts "Stopping ferret_server..." -if File.file?(pid_file) - send_signal("TERM", pid_file) -else - puts "no pid file found" -end - -# vim:set filetype=ruby: -- libgit2 0.21.2