To edit pages or tickets please login with username/password: aaf/aaf

Changeset 355

Show
Ignore:
Timestamp:
08/11/08 09:22:46 (3 months ago)
Author:
jk
Message:

fix model array handling for find_ids and totalhits methods

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plugin/acts_as_ferret/lib/act_methods.rb

    r327 r355  
    104104      add_fields aaf_configuration[:additional_fields] 
    105105 
    106       # not good at class level, index might get initialized too early 
    107       #if options[:remote] 
    108       #  aaf_index.ensure_index_exists 
    109       #end 
    110106    end 
    111107 
     
    136132 
    137133    def add_fields(field_config) 
    138       # TODO 
    139         #field_config.each do |*args|  
    140         #  define_to_field_method *args 
    141         #end                 
    142134      if field_config.is_a? Hash 
    143135        field_config.each_pair do |field, options| 
  • trunk/plugin/acts_as_ferret/lib/acts_as_ferret.rb

    r353 r355  
    270270  end 
    271271 
    272   # count hits for a query with multiple models 
    273   def self.total_hits(query, models, options = {}) 
    274     find_index(models).total_hits query, options.merge( :models => models ) 
    275   end 
    276  
    277   # find ids of records with multiple models 
    278   # TODO pagination logic? 
    279   def self.find_ids(query, models, options = {}, &block) 
    280     find_index(models).find_ids query, options.merge( :models => models ), &block 
    281   end 
    282  
     272  # count hits for a query 
     273  def self.total_hits(query, models_or_index_name, options = {}) 
     274    options = add_models_to_options_if_necessary options, models_or_index_name 
     275    find_index(models).total_hits query, options 
     276  end 
     277 
     278  # find ids of records 
     279  def self.find_ids(query, models_or_index_name, options = {}, &block) 
     280    options = add_models_to_options_if_necessary options, models_or_index_name 
     281    find_index(models).find_ids query, options, &block 
     282  end 
     283   
     284  # returns an index instance suitable for searching/updating the named index. Will  
     285  # return a read only MultiIndex when multiple model classes are given that do not 
     286  # share the same physical index. 
    283287  def self.find_index(models_or_index_name) 
    284288    case models_or_index_name 
     
    287291    when String 
    288292      get_index models_or_index_name.to_sym 
    289     #when Array 
    290     #  get_index_for models_or_index_name 
    291293    else 
    292294      get_index_for models_or_index_name 
     
    306308    end 
    307309    index = find_index(models_or_index_name) 
    308     multi = (MultiIndex === index or index.shared?) 
     310    multi = (MultiIndexBase === index or index.shared?) 
    309311    unless options[:per_page] 
    310312      options[:limit] ||= ar_options.delete :limit 
     
    557559  protected 
    558560 
     561  def self.add_models_to_options_if_necessary(options, models_or_index_name) 
     562    return options if String === models_or_index_name or Symbol === models_or_index_name 
     563    options.merge(:models => models) 
     564  end 
     565 
    559566  def self.field_config_for(fieldname, options = {}) 
    560567    config = DEFAULT_FIELD_OPTIONS.merge options 

To edit pages or tickets please login with username/password: aaf/aaf