Class: Ferret::Analysis::Analyzer
- Inherits:
-
Object
- Object
- Ferret::Analysis::Analyzer
- Defined in:
- lib/ferret/analysis/analyzers.rb
Overview
An Analyzer builds TokenStreams, which analyze text. It thus represents a policy for extracting index terms from text.
Typical implementations first build a Tokenizer, which breaks the stream of characters from the Reader into raw Tokens. One or more TokenFilter s may then be applied to the output of the Tokenizer.
The default Analyzer just creates a LowerCaseTokenizer which converts all text to lowercase tokens. See LowerCaseTokenizer for more details.
Direct Known Subclasses
Instance Method Summary collapse
-
#position_increment_gap(field_name) ⇒ Object
Invoked before indexing a Field instance if terms have already been added to that field.
-
#token_stream(field, string) ⇒ Object
Creates a TokenStream which tokenizes all the text in the provided Reader.
Instance Method Details
#position_increment_gap(field_name) ⇒ Object
Invoked before indexing a Field instance if terms have already been added to that field. This allows custom analyzers to place an automatic position increment gap between Field instances using the same field name. The default value position increment gap is 0. With a 0 position increment gap and the typical default token position increment of 1, all terms in a field, including across Field instances, are in successive positions, allowing exact PhraseQuery matches, for instance, across Field instance boundaries.
- field_name
-
Field name being indexed.
- position_increment_gap
-
added to the next token emitted from #token_stream(String,Reader)
34 35 36 |
# File 'lib/ferret/analysis/analyzers.rb', line 34 def position_increment_gap(field_name) return 0 end |
#token_stream(field, string) ⇒ Object
Creates a TokenStream which tokenizes all the text in the provided Reader. Override to allow Analyzer to choose strategy based on document and/or field.
- string
-
the string representing the text in the field
- field
-
name of the field. Not required.
17 18 19 |
# File 'lib/ferret/analysis/analyzers.rb', line 17 def token_stream(field, string) return LowerCaseTokenizer.new(string) end |