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

Changeset 306

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

#189 - allow for per-document analyzers

Files:

Legend:

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

    r250 r306  
    1717    def index_records(records, offset) 
    1818      batch_time = measure_time { 
    19         records.each { |rec| @index << rec.to_doc if rec.ferret_enabled?(true) } 
     19        records.each { |rec| @index.add_document(rec.to_doc, rec.ferret_analyzer) if rec.ferret_enabled?(true) } 
    2020      }.to_f 
    2121      @work_done = offset.to_f / @model_count * 100.0 if @model_count > 0 
  • trunk/plugin/acts_as_ferret/lib/instance_methods.rb

    r300 r306  
    4949    def ferret_enabled?(is_bulk_index = false) 
    5050      @ferret_disabled.nil? && (is_bulk_index || self.class.ferret_enabled?) 
     51    end 
     52 
     53    # Returns the analyzer to use when adding this record to the index. 
     54    # 
     55    # Override to return a specific analyzer for any record that is to be 
     56    # indexed, i.e. specify a different analyzer based on language. Returns nil 
     57    # by default so the global analyzer (specified with the acts_as_ferret 
     58    # call) is used. 
     59    def ferret_analyzer 
     60      nil 
    5161    end 
    5262 
  • trunk/plugin/acts_as_ferret/lib/local_index.rb

    r301 r306  
    150150    # add record to index 
    151151    # record may be the full AR object, a Ferret document instance or a Hash 
    152     def add(record) 
    153       record = record.to_doc unless Hash === record || Ferret::Document === record 
    154       ferret_index << record 
     152    def add(record, analyzer = nil) 
     153      unless Hash === record || Ferret::Document === record 
     154        analyzer = record.ferret_analyzer 
     155        record = record.to_doc  
     156      end 
     157      ferret_index.add_document(record, analyzer) 
    155158    end 
    156159    alias << add 

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