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

root/trunk/demo/app/models/comment.rb

Revision 337, 1.7 kB (checked in by jk, 6 months ago)

remove obsolete comment

Line 
1
2 class PlainAsciiAnalyzer < ::Ferret::Analysis::Analyzer
3   include ::Ferret::Analysis
4   def token_stream(field, str)
5         StopFilter.new(
6           StandardTokenizer.new(str) ,
7           ["fax", "gsm"]
8         )
9     # raise #<<<----- is never executed when uncommented !!
10   end
11 end
12
13
14 class Comment < ActiveRecord::Base
15   belongs_to :parent, :class_name => 'Content', :foreign_key => :parent_id
16  
17   # simplest case: just index all fields of this model:
18   # acts_as_ferret
19  
20   # use the :additional_fields property to specify fields you intend
21   # to add in addition to those fields from your database table (which will be
22   # autodiscovered by acts_as_ferret)
23   # the :ignore flag tells aaf to not try to set this field's value itself (we
24   # do this in our custom to_doc method)
25   acts_as_ferret( :if => Proc.new { |comment| comment.do_index? },
26                   :fields => {
27                     :content => { :store => :yes },
28                     :author  => { },
29                     :added   => { :index => :untokenized, :store => :yes, :ignore => true },
30                     :aliased => { :via => :content }
31                   }, :ferret => { :analyzer => Ferret::Analysis::StandardAnalyzer.new(['fax', 'gsm', 'the', 'or']) } )
32                   #}, :ferret => { :analyzer => PlainAsciiAnalyzer.new(['fax', 'gsm', 'the', 'or']) } )
33
34   def do_index?
35     self.content !~ /do not index/
36   end
37
38   # you can override the default to_doc method
39   # to customize what gets into your index.
40   def to_doc
41     # doc now has all the fields of our model instance, we
42     # just add another field to it:
43     doc = super
44     # add a field containing the current time
45     doc[:added] = Time.now.to_i.to_s
46     return doc
47   end
48 end
Note: See TracBrowser for help on using the browser.

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