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

Changeset 307

Show
Ignore:
Timestamp:
02/02/08 12:53:01 (8 months ago)
Author:
jk
Message:

#188 - allow for aliased fields

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/demo/app/models/comment.rb

    r265 r307  
    3232                    :content => { :store => :yes }, 
    3333                    :author  => { }, 
    34                     :added   => { :index => :untokenized, :store => :yes, :ignore => true } 
     34                    :added   => { :index => :untokenized, :store => :yes, :ignore => true }, 
     35                    :aliased => { :via => :content } 
    3536                  }, :ferret => { :analyzer => Ferret::Analysis::StandardAnalyzer.new(['fax', 'gsm', 'the', 'or']) } ) 
    3637                  #}, :ferret => { :analyzer => PlainAsciiAnalyzer.new(['fax', 'gsm', 'the', 'or']) } ) 
  • trunk/demo/test/unit/comment_test.rb

    r263 r307  
    2121  def test_class_index_dir 
    2222    assert Comment.aaf_configuration[:index_dir] =~ %r{^#{RAILS_ROOT}/index/test/comment} 
     23  end 
     24 
     25  def test_aliased_field 
     26    res = Comment.find_with_ferret 'aliased:regarding' 
     27    assert_equal 1, res.total_hits 
     28    assert_equal comments(:comment_for_c2), res.first 
    2329  end 
    2430 
  • trunk/plugin/acts_as_ferret/lib/act_methods.rb

    r300 r307  
    223223                              :index       => :yes,  
    224224                              :term_vector => :with_positions_offsets, 
     225                              :via         => field, 
    225226                              :boost       => 1.0 ) 
    226227      options[:term_vector] = :no if options[:index] == :no 
  • trunk/plugin/acts_as_ferret/lib/acts_as_ferret.rb

    r244 r307  
    125125      options = options.dup 
    126126      options.delete(:boost) if options[:boost].is_a?(Symbol) 
     127      options.delete(:via) 
    127128      fi.add_field(field, { :store => :no,  
    128129                            :index => :yes }.update(options))  
  • trunk/plugin/acts_as_ferret/lib/instance_methods.rb

    r306 r307  
    153153 
    154154    def content_for_field_name(field, dynamic_boost = nil) 
    155       field_data = self[field] || self.instance_variable_get("@#{field.to_s}".to_sym) || self.send(field.to_sym) 
     155      ar_field = aaf_configuration[:ferret_fields][field][:via] 
     156      field_data = self.send(ar_field) || self.instance_variable_get("@#{ar_field}") 
    156157      if (dynamic_boost && boost_value = self.send(dynamic_boost)) 
    157158        field_data = Ferret::Field.new(field_data) 
  • trunk/plugin/acts_as_ferret/lib/local_index.rb

    r306 r307  
    5353      models = models.flatten.uniq.map(&:constantize) 
    5454      logger.debug "rebuild index: #{models.inspect}" 
    55       index = Ferret::Index::Index.new(aaf_configuration[:ferret].dup.update(:auto_flush => false,  
     55      index = Ferret::Index::Index.new(aaf_configuration[:ferret].dup.update(:auto_flush => false,  
    5656                                                                             :field_infos => ActsAsFerret::field_infos(models), 
    57                                                                              :create => true)) 
     57                                                                             :create      => true)) 
    5858      index.batch_size = aaf_configuration[:reindex_batch_size] 
    5959      index.logger = logger 
     
    9090      logger.debug "stored_fields: #{stored_fields}" 
    9191      return stored_fields 
     92    end 
     93 
     94    # loads data for fields declared as :lazy from the Ferret document 
     95    def extract_lazy_fields(doc, lazy_fields)  
     96      fields = aaf_configuration[:ferret_fields]  
     97      data = {}  
     98      lazy_fields.each { |field| data[fields[field][:via]] = doc[field] } if lazy_fields  
     99      data  
    92100    end 
    93101 
     
    106114        model = aaf_configuration[:store_class_name] ? doc[:class_name] : aaf_configuration[:class_name] 
    107115        # fetch stored fields if lazy loading 
    108         data = {} 
    109         lazy_fields.each { |field| data[field] = doc[field] } if lazy_fields 
     116        data = extract_lazy_fields(doc, lazy_fields) 
    110117        if block_given? 
    111118          yield model, doc[:id], score, data 
     
    129136        doc = index[hit] 
    130137        # fetch stored fields if lazy loading 
    131         data = {} 
    132         lazy_fields.each { |field| data[field] = doc[field] } if lazy_fields 
     138        data = extract_lazy_fields(doc, lazy_fields) 
    133139        raise "':store_class_name => true' required for multi_search to work" if doc[:class_name].blank? 
    134140        if block_given? 

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