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

Changeset 248

Show
Ignore:
Timestamp:
10/01/07 14:50:29 (1 year ago)
Author:
jk
Message:

add :optimize boolean option to bulk_index

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/demo/test/unit/content_test.rb

    r246 r248  
    2626    ContentBase.find(:all).each { |c| c.destroy } 
    2727    Comment.find(:all).each { |c| c.destroy } 
     28  end 
     29 
     30  def test_include_option 
     31    assert_equal 1, Content.find_with_ferret('description', {}, :include => :comments).size 
    2832  end 
    2933 
     
    181185      assert_equal 6, records.size 
    182186    end 
     187  end 
     188 
     189  def test_bulk_index_no_optimize 
     190    Content.disable_ferret do 
     191      more_contents 
     192    end 
     193 
     194    assert Content.find_with_ferret('title').empty? 
     195    min = Content.find(:all, :order => 'id asc').first.id 
     196    Content.bulk_index(min, min+1, min+2, min+3, min+4, min+6, :optimize => false) 
     197    assert_equal 6, Content.find_with_ferret('title').size 
    183198  end 
    184199 
  • trunk/plugin/acts_as_ferret/lib/class_methods.rb

    r247 r248  
    3838    # indexing jobs i.e. after modifying a lot of records with Ferret disabled. 
    3939    def bulk_index(*ids) 
     40      options = Hash === ids.last ? ids.pop : {} 
    4041      ids = ids.first if ids.size == 1 && ids.first.is_a?(Enumerable) 
    41       aaf_index.bulk_index(ids
     42      aaf_index.bulk_index(ids, options
    4243    end 
    4344 
  • trunk/plugin/acts_as_ferret/lib/ferret_extensions.rb

    r239 r248  
    5555    end 
    5656 
    57     def bulk_index(model, ids) 
     57    def bulk_index(model, ids, options = {}) 
     58      options.reverse_merge! :optimize => true 
    5859      orig_flush = @auto_flush 
    5960      @auto_flush = false 
     
    6465        bulk_indexer.index_records(records, offset) 
    6566      end 
     67      logger.info 'finishing bulk index...' 
    6668      flush 
    67       optimize 
     69      if options[:optimize] 
     70        logger.info 'optimizing...' 
     71        optimize  
     72      end 
    6873      @auto_flush = orig_flush 
    6974    end 
  • trunk/plugin/acts_as_ferret/lib/local_index.rb

    r247 r248  
    6363    end 
    6464 
    65     def bulk_index(ids
    66       ferret_index.bulk_index(aaf_configuration[:class_name].constantize, ids
     65    def bulk_index(ids, options
     66      ferret_index.bulk_index(aaf_configuration[:class_name].constantize, ids, options
    6767    end 
    6868 

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