### Home Classes Methods

### In Files

- ext/r_analysis.c

### Parent

Ferret::Analysis::Analyzer

### Methods

- ::new
- #[]=
- #add_field
- #token_stream

### Files

- MIT-LICENSE
- README
- TODO
- TUTORIAL

### Class/Module Index

Quicksearch

- Ferret
- Ferret::Analysis
- Ferret::Analysis::Analyzer
- Ferret::Analysis::AsciiLetterAnalyzer
- Ferret::Analysis::AsciiLetterTokenizer
- Ferret::Analysis::AsciiLowerCaseFilter
- Ferret::Analysis::AsciiStandardAnalyzer
- Ferret::Analysis::AsciiStandardTokenizer
- Ferret::Analysis::AsciiWhiteSpaceAnalyzer
- Ferret::Analysis::AsciiWhiteSpaceTokenizer
- Ferret::Analysis::HyphenFilter
- Ferret::Analysis::LetterAnalyzer
- Ferret::Analysis::LetterTokenizer
- Ferret::Analysis::LowerCaseFilter
- Ferret::Analysis::MappingFilter
- Ferret::Analysis::PerFieldAnalyzer
- Ferret::Analysis::RegExpAnalyzer
- Ferret::Analysis::RegExpTokenizer
- Ferret::Analysis::StandardAnalyzer
- Ferret::Analysis::StandardTokenizer
- Ferret::Analysis::StemFilter
- Ferret::Analysis::StopFilter
- Ferret::Analysis::Token
- Ferret::Analysis::TokenStream
- Ferret::Analysis::WhiteSpaceAnalyzer
- Ferret::Analysis::WhiteSpaceTokenizer
- Ferret::BlankSlate
- Ferret::BoostMixin
- Ferret::Browser
- Ferret::Browser::Controller
- Ferret::Browser::Delegator
- Ferret::Browser::DocumentController
- Ferret::Browser::ErrorController
- Ferret::Browser::HelpController
- Ferret::Browser::HomeController
- Ferret::Browser::TermController
- Ferret::Browser::TermVectorController
- Ferret::Browser::ViewHelper
- Ferret::Document
- Ferret::Field
- Ferret::FieldSymbol
- Ferret::FieldSymbolMethods
- Ferret::FileNotFoundError
- Ferret::Index
- Ferret::Index::FieldInfo
- Ferret::Index::FieldInfos
- Ferret::Index::Index
- Ferret::Index::IndexReader
- Ferret::Index::IndexWriter
- Ferret::Index::LazyDoc
- Ferret::Index::LazyDoc::LazyDocData
- Ferret::Index::TermDocEnum
- Ferret::Index::TermEnum
- Ferret::Index::TermVector
- Ferret::Index::TermVector::TVOffsets
- Ferret::Index::TermVector::TVTerm
- Ferret::ParseError
- Ferret::QueryParser
- Ferret::QueryParser::QueryParseException
- Ferret::Search
- Ferret::Search::BooleanQuery
- Ferret::Search::BooleanQuery::BooleanClause
- Ferret::Search::ConstantScoreQuery
- Ferret::Search::Explanation
- Ferret::Search::Filter
- Ferret::Search::FilteredQuery
- Ferret::Search::FuzzyQuery
- Ferret::Search::Hit
- Ferret::Search::MatchAllQuery
- Ferret::Search::MultiSearcher
- Ferret::Search::MultiTermQuery
- Ferret::Search::PhraseQuery
- Ferret::Search::PrefixQuery
- Ferret::Search::Query
- Ferret::Search::QueryFilter
- Ferret::Search::RangeFilter
- Ferret::Search::RangeQuery
- Ferret::Search::Searcher
- Ferret::Search::Sort
- Ferret::Search::SortField
- Ferret::Search::Spans
- Ferret::Search::Spans::SpanFirstQuery
- Ferret::Search::Spans::SpanMultiTermQuery
- Ferret::Search::Spans::SpanNearQuery
- Ferret::Search::Spans::SpanNotQuery
- Ferret::Search::Spans::SpanOrQuery
- Ferret::Search::Spans::SpanPrefixQuery
- Ferret::Search::Spans::SpanTermQuery
- Ferret::Search::TermQuery
- Ferret::Search::TopDocs
- Ferret::Search::TypedRangeFilter
- Ferret::Search::TypedRangeQuery
- Ferret::Search::WildcardQuery
- Ferret::StateError
- Ferret::Store
- Ferret::Store::Directory
- Ferret::Store::FSDirectory
- Ferret::Store::Lock
- Ferret::Store::Lock::LockError
- Ferret::Store::RAMDirectory
- Ferret::Utils
- Ferret::Utils::BitVector
- Ferret::Utils::MultiMapper
- Ferret::Utils::PriorityQueue
- WEBrick
- WEBrick::FerretBrowserHandler
- Date
- DateTime
- FileUtils
- Float
- Integer
- String
- Symbol
- Time

No matching classes.

# Ferret::Analysis::PerFieldAnalyzer

## Summary

The PerFieldAnalyzer is for use when you want to analyze different fields with different analyzers. With the PerFieldAnalyzer you can specify how you want each field analyzed.

### Example

    # Create a new PerFieldAnalyzer which uses StandardAnalyzer by default
    pfa = PerFieldAnalyzer.new(StandardAnalyzer.new())

    # Use the WhiteSpaceAnalyzer with no lowercasing on the :title field
    pfa[:title] = WhiteSpaceAnalyzer.new(false)

    # Use a custom analyzer on the :created_at field
    pfa[:created_at] = DateAnalyzer.new

### Public Class Methods

new(default_analyzer) → analyzer click to toggle source

Create a new PerFieldAnalyzer specifying the default analyzer to use on all fields that are set specifically.

default_analyzer | analyzer to be used on fields that aren't otherwise specified

    static VALUE
    frb_per_field_analyzer_init(VALUE self, VALUE ranalyzer)
    {
        Analyzer *def = frb_get_cwrapped_analyzer(ranalyzer);
        Analyzer *a = per_field_analyzer_new(def);
        Frt_Wrap_Struct(self, &frb_pfa_mark, &frb_analyzer_free, a);
        object_add(a, self);
        return self;
    }

### Public Instance Methods

add_field(field_name, default_analyzer) → self click to toggle source
per_field_analyzer[field_name] = default_analyzer → self

Set the analyzer to be used on field `field_name`. Note that field_name should be a symbol.

field_name | field we wish to set the analyzer for
analyzer | analyzer to be used on `field_name`

    static VALUE
    frb_per_field_analyzer_add_field(VALUE self, VALUE rfield, VALUE ranalyzer)
    {
        Analyzer *pfa, *a;
        Data_Get_Struct(self, Analyzer, pfa);
        a = frb_get_cwrapped_analyzer(ranalyzer);

        pfa_add_field(pfa, frb_field(rfield), a);
        return self;
    }

add_field(field_name, default_analyzer) → self click to toggle source
per_field_analyzer[field_name] = default_analyzer → self

Set the analyzer to be used on field `field_name`. Note that field_name should be a symbol.

field_name | field we wish to set the analyzer for
analyzer | analyzer to be used on `field_name`

    static VALUE
    frb_per_field_analyzer_add_field(VALUE self, VALUE rfield, VALUE ranalyzer)
    {
        Analyzer *pfa, *a;
        Data_Get_Struct(self, Analyzer, pfa);
        a = frb_get_cwrapped_analyzer(ranalyzer);

        pfa_add_field(pfa, frb_field(rfield), a);
        return self;
    }

token_stream(field_name, input) → token_stream click to toggle source

Create a new TokenStream to tokenize `input`. The TokenStream created will also depend on the `field_name` in the case of the PerFieldAnalyzer.

field_name | name of the field to be tokenized
input | data from the field to be tokenized

    static VALUE
    frb_pfa_analyzer_token_stream(VALUE self, VALUE rfield, VALUE rstring)
    {
        Analyzer *pfa, *a;
        Symbol field = frb_field(rfield);
        GET_A(pfa, self);

        StringValue(rstring);
        a = (Analyzer *)h_get(PFA(pfa)->dict, field);
        if (a == NULL) {
            a = PFA(pfa)->default_a;
        }
        if (a->get_ts == cwa_get_ts) {
            return rb_funcall(CWA(a)->ranalyzer, id_token_stream, 2,
                              FSYM2SYM(field), rb_str_new2(rs2s(rstring)));
        }
        else {
            return get_rb_ts_from_a(a, rfield, rstring);
        }
    }

[Validate]

Generated with the Darkfish Rdoc Generator 2.