Sha256: 4e1fcf9f6452aa74bf2d4d7645f0c2068063d9e83e61df47540534245dcfb527

Contents?: true

Size: 1.69 KB

Versions: 15

Compression:

Stored size: 1.69 KB

Contents

class PlainAsciiAnalyzer < ::Ferret::Analysis::Analyzer
  include ::Ferret::Analysis
  def token_stream(field, str)
        StopFilter.new(
          StandardTokenizer.new(str) ,
          ["fax", "gsm"]
        )
    # raise #<<<----- is never executed when uncommented !!
  end
end


class Comment < ActiveRecord::Base
  belongs_to :parent, :class_name => 'Content', :foreign_key => :parent_id
  
  # simplest case: just index all fields of this model:
  # acts_as_ferret
  
  # use the :additional_fields property to specify fields you intend 
  # to add in addition to those fields from your database table (which will be
  # autodiscovered by acts_as_ferret)
  # the :ignore flag tells aaf to not try to set this field's value itself (we
  # do this in our custom to_doc method)
  acts_as_ferret( :if => Proc.new { |comment| comment.do_index? },
                  :fields => {
                    :content => { :store => :yes },
                    :author  => { },
                    :added   => { :index => :untokenized, :store => :yes, :ignore => true },
                    :aliased => { :via => :content }
                  }, :ferret => { :analyzer => Ferret::Analysis::StandardAnalyzer.new(['fax', 'gsm', 'the', 'or']) } )
                  #}, :ferret => { :analyzer => PlainAsciiAnalyzer.new(['fax', 'gsm', 'the', 'or']) } )

  def do_index?
    self.content !~ /do not index/
  end

  # you can override the default to_doc method 
  # to customize what gets into your index. 
  def to_doc
    # doc now has all the fields of our model instance, we 
    # just add another field to it:
    doc = super
    # add a field containing the current time
    doc[:added] = Time.now.to_i.to_s
    return doc
  end
end

Version data entries

15 entries across 15 versions & 4 rubygems

Version Path
cehoffman-acts_as_ferret-0.4.4 doc/demo/app/models/comment.rb
jkraemer-acts_as_ferret-0.4.4 doc/demo/app/models/comment.rb
acts_as_ferret-0.5.4 doc/demo/app/models/comment.rb
acts_as_ferret-0.5.3 doc/demo/app/models/comment.rb
watson-acts_as_ferret-0.4.8.2 doc/demo/app/models/comment.rb
acts_as_ferret-0.5.2 doc/demo/app/models/comment.rb
acts_as_ferret-0.4.8.2 doc/demo/app/models/comment.rb
acts_as_ferret-0.4.8.1 doc/demo/app/models/comment.rb
acts_as_ferret-0.5.1 doc/demo/app/models/comment.rb
acts_as_ferret-0.5 doc/demo/app/models/comment.rb
acts_as_ferret-0.4.8.rails3 doc/demo/app/models/comment.rb
acts_as_ferret-0.4.8 doc/demo/app/models/comment.rb
acts_as_ferret-0.4.7 doc/demo/app/models/comment.rb
acts_as_ferret-0.4.6 doc/demo/app/models/comment.rb
acts_as_ferret-0.4.4 doc/demo/app/models/comment.rb