Class: Ferret::Analysis::PerFieldAnalyzer

Inherits:
Analyzer
  • Object
show all
Defined in:
lib/acts_as_ferret/ferret_extensions.rb

Overview

PerFieldAnalyzer

This PerFieldAnalyzer is a workaround to a memory leak in ferret 0.11.4. It does basically do the same as the original Ferret::Analysis::PerFieldAnalyzer, but without the leak :)

ferret.davebalmain.com/api/classes/Ferret/Analysis/PerFieldAnalyzer.html

Thanks to Ben from omdb.org for tracking this down and creating this workaround. You can read more about the issue there: blog.omdb-beta.org/2007/7/29/tracking-down-a-memory-leak-in-ferret-0-11-4

Instance Method Summary collapse

Constructor Details

#initialize(default_analyzer = StandardAnalyzer.new) ⇒ PerFieldAnalyzer

Returns a new instance of PerFieldAnalyzer.



18
19
20
21
# File 'lib/acts_as_ferret/ferret_extensions.rb', line 18

def initialize( default_analyzer = StandardAnalyzer.new )
  @analyzers = {}
  @default_analyzer = default_analyzer
end

Instance Method Details

#add_field(field, analyzer) ⇒ Object Also known as: []=



23
24
25
# File 'lib/acts_as_ferret/ferret_extensions.rb', line 23

def add_field( field, analyzer )
  @analyzers[field] = analyzer
end

#token_stream(field, string) ⇒ Object



28
29
30
31
# File 'lib/acts_as_ferret/ferret_extensions.rb', line 28

def token_stream(field, string)
  @analyzers.has_key?(field) ? @analyzers[field].token_stream(field, string) : 
    @default_analyzer.token_stream(field, string)
end