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

Changeset 324

Show
Ignore:
Timestamp:
02/18/08 20:36:07 (8 months ago)
Author:
jk
Message:

add :if option to acts_as_ferret method

Files:

Legend:

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

    r321 r324  
    2727  # the :ignore flag tells aaf to not try to set this field's value itself (we 
    2828  # do this in our custom to_doc method) 
    29   acts_as_ferret( :store_class_name => true,  
     29  acts_as_ferret( :if => Proc.new { |comment| comment.do_index? }, 
    3030                  :fields => { 
    3131                    :content => { :store => :yes }, 
     
    3636                  #}, :ferret => { :analyzer => PlainAsciiAnalyzer.new(['fax', 'gsm', 'the', 'or']) } ) 
    3737 
    38   # only index the named fields: 
    39   #acts_as_ferret :fields => [:author, :content ] 
     38  def do_index? 
     39    self.content !~ /do not index/ 
     40  end 
    4041 
    4142  # you can override the default to_doc method  
  • trunk/demo/test/unit/comment_test.rb

    r319 r324  
    1111  def test_truth 
    1212    assert_kind_of Comment, comments(:first) 
     13  end 
     14 
     15  def test_if_option 
     16    c = Comment.new :content => 'do not index' 
     17    c.save 
     18    assert_equal 0, Comment.find_with_ferret('do not index').total_hits 
    1319  end 
    1420 
  • trunk/plugin/acts_as_ferret/lib/act_methods.rb

    r321 r324  
    3131    #                      algorithm if this model uses a non-integer primary key named 
    3232    #                      'id' on MySQL. 
    33     # 
    34     # raise_drb_errors:: Set this to true if you want aaf to raise Exceptions 
    35     #                    in case the DRb server cannot be reached (in other word - behave like 
    36     #                    versions up to 0.4.3). Defaults to false so DRb exceptions 
    37     #                    are logged but not raised. Be sure to set up some 
    38     #                    monitoring so you still detect when your DRb server died for 
    39     #                    whatever reason. 
    4033    # 
    4134    # ferret:: Hash of Options that directly influence the way the Ferret engine works. You  
     
    9891      # update our copy of the global index config with options local to this class 
    9992      aaf_configuration[:class_name] ||= self.name 
     93      aaf_configuration[:if] ||= options[:if] 
    10094 
    10195      # add methods for retrieving field values 
  • trunk/plugin/acts_as_ferret/lib/acts_as_ferret.rb

    r322 r324  
    7373# Kasper Weibel Nielsen-Refs (original author) 
    7474# Jens Kraemer <jk@jkraemer.net> (active maintainer) 
     75# 
     76# 
     77# == Global properties 
     78# 
     79# raise_drb_errors:: Set this to true if you want aaf to raise Exceptions 
     80#                    in case the DRb server cannot be reached (in other word - behave like 
     81#                    versions up to 0.4.3). Defaults to false so DRb exceptions 
     82#                    are logged but not raised. Be sure to set up some 
     83#                    monitoring so you still detect when your DRb server died for 
     84#                    whatever reason. 
     85# 
     86# remote:: Set this to false to force acts_as_ferret into local (non-DRb) mode even if 
     87#          config/ferret_server.yml contains a section for the current RAILS_ENV 
     88#          Usually you won't need to touch this option - just configure DRb for 
     89#          production mode in ferret_server.yml. 
    7590# 
    7691module ActsAsFerret 
  • trunk/plugin/acts_as_ferret/lib/instance_methods.rb

    r320 r324  
    4848    # records you're still safe). 
    4949    def ferret_enabled?(is_bulk_index = false) 
    50       @ferret_disabled.nil? && (is_bulk_index || self.class.ferret_enabled?) 
     50      @ferret_disabled.nil? && (is_bulk_index || self.class.ferret_enabled?) && (aaf_configuration[:if].nil? || aaf_configuration[:if].call(self)) 
    5151    end 
    5252 

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