Fork me on GitHub
  • API

    Show / Hide Table of Contents

    Class MockAnalyzer

    Analyzer for testing.

    This analyzer is a replacement for Whitespace/Simple/KeywordAnalyzers for unit tests. If you are testing a custom component such as a queryparser or analyzer-wrapper that consumes analysis streams, its a great idea to test it with this analyzer instead. MockAnalyzer has the following behavior:
    • By default, the assertions in MockTokenizer are turned on for extra checks that the consumer is consuming properly. These checks can be disabled with EnableChecks.
    • Payload data is randomly injected into the stream for more thorough testing of payloads.
    Inheritance
    object
    Analyzer
    MockAnalyzer
    Implements
    IDisposable
    Inherited Members
    Analyzer.NewAnonymous(Func<string, TextReader, TokenStreamComponents>)
    Analyzer.NewAnonymous(Func<string, TextReader, TokenStreamComponents>, ReuseStrategy)
    Analyzer.NewAnonymous(Func<string, TextReader, TokenStreamComponents>, Func<string, TextReader, TextReader>)
    Analyzer.NewAnonymous(Func<string, TextReader, TokenStreamComponents>, Func<string, TextReader, TextReader>, ReuseStrategy)
    Analyzer.GetTokenStream(string, TextReader)
    Analyzer.GetTokenStream(string, string)
    Analyzer.Strategy
    Analyzer.Dispose()
    Analyzer.GLOBAL_REUSE_STRATEGY
    Analyzer.PER_FIELD_REUSE_STRATEGY
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Lucene.Net.Analysis
    Assembly: Lucene.Net.TestFramework.dll
    Syntax
    public sealed class MockAnalyzer : Analyzer, IDisposable

    Constructors

    MockAnalyzer(Random)

    Create a Whitespace-lowercasing analyzer with no stopwords removal.

    Calls MockAnalyzer(random, MockTokenizer.WHITESPACE, true, MockTokenFilter.EMPTY_STOPSET, false).
    Declaration
    public MockAnalyzer(Random random)
    Parameters
    Type Name Description
    Random random
    See Also
    MockTokenizer

    MockAnalyzer(Random, CharacterRunAutomaton, bool)

    Calls MockAnalyzer(random, runAutomaton, lowerCase, MockTokenFilter.EMPTY_STOPSET, false).

    Declaration
    public MockAnalyzer(Random random, CharacterRunAutomaton runAutomaton, bool lowerCase)
    Parameters
    Type Name Description
    Random random
    CharacterRunAutomaton runAutomaton
    bool lowerCase
    See Also
    MockTokenizer

    MockAnalyzer(Random, CharacterRunAutomaton, bool, CharacterRunAutomaton)

    Creates a new MockAnalyzer.

    Declaration
    public MockAnalyzer(Random random, CharacterRunAutomaton runAutomaton, bool lowerCase, CharacterRunAutomaton filter)
    Parameters
    Type Name Description
    Random random

    Random for payloads behavior

    CharacterRunAutomaton runAutomaton

    DFA describing how tokenization should happen (e.g. [a-zA-Z]+)

    bool lowerCase

    true if the tokenizer should lowercase terms

    CharacterRunAutomaton filter

    DFA describing how terms should be filtered (set of stopwords, etc)

    See Also
    MockTokenizer

    Properties

    EnableChecks

    Toggle consumer workflow checking: if your test consumes tokenstreams normally you should leave this enabled.

    Declaration
    public bool EnableChecks { get; set; }
    Property Value
    Type Description
    bool
    See Also
    MockTokenizer

    MaxTokenLength

    Toggle maxTokenLength for MockTokenizer.

    Declaration
    public int MaxTokenLength { get; set; }
    Property Value
    Type Description
    int
    See Also
    MockTokenizer

    Methods

    CreateComponents(string, TextReader)

    Creates a new Lucene.Net.Analysis.TokenStreamComponents instance for this analyzer.

    Declaration
    protected override TokenStreamComponents CreateComponents(string fieldName, TextReader reader)
    Parameters
    Type Name Description
    string fieldName

    the name of the fields content passed to the Lucene.Net.Analysis.TokenStreamComponents sink as a reader

    TextReader reader

    the reader passed to the Lucene.Net.Analysis.Tokenizer constructor

    Returns
    Type Description
    TokenStreamComponents

    the Lucene.Net.Analysis.TokenStreamComponents for this analyzer.

    Overrides
    Analyzer.CreateComponents(string, TextReader)
    See Also
    MockTokenizer

    GetOffsetGap(string)

    Get the offset gap between tokens in fields if several fields with the same name were added.

    Declaration
    public override int GetOffsetGap(string fieldName)
    Parameters
    Type Name Description
    string fieldName

    Currently not used, the same offset gap is returned for each field.

    Returns
    Type Description
    int
    Overrides
    Analyzer.GetOffsetGap(string)
    See Also
    MockTokenizer

    GetPositionIncrementGap(string)

    Invoked before indexing a Lucene.Net.Index.IIndexableField instance if terms have already been added to that field. This allows custom analyzers to place an automatic position increment gap between Lucene.Net.Index.IIndexableField 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 Lucene.Net.Index.IIndexableField instances, are in successive positions, allowing exact Lucene.Net.Search.PhraseQuery matches, for instance, across Lucene.Net.Index.IIndexableField instance boundaries.

    Declaration
    public override int GetPositionIncrementGap(string fieldName)
    Parameters
    Type Name Description
    string fieldName

    Lucene.Net.Index.IIndexableField name being indexed.

    Returns
    Type Description
    int

    position increment gap, added to the next token emitted from GetTokenStream(string, TextReader). this value must be >= 0.

    Overrides
    Analyzer.GetPositionIncrementGap(string)
    See Also
    MockTokenizer

    SetOffsetGap(int)

    Sets an offset gap which will then be added to the offset when several fields with the same name are indexed

    Declaration
    public void SetOffsetGap(int offsetGap)
    Parameters
    Type Name Description
    int offsetGap
    See Also
    MockTokenizer

    SetPositionIncrementGap(int)

    Analyzer for testing.

    This analyzer is a replacement for Whitespace/Simple/KeywordAnalyzers for unit tests. If you are testing a custom component such as a queryparser or analyzer-wrapper that consumes analysis streams, its a great idea to test it with this analyzer instead. MockAnalyzer has the following behavior:
    • By default, the assertions in MockTokenizer are turned on for extra checks that the consumer is consuming properly. These checks can be disabled with EnableChecks.
    • Payload data is randomly injected into the stream for more thorough testing of payloads.
    Declaration
    public void SetPositionIncrementGap(int positionIncrementGap)
    Parameters
    Type Name Description
    int positionIncrementGap
    See Also
    MockTokenizer

    Implements

    IDisposable

    See Also

    MockTokenizer
    Back to top Copyright © 2024 The Apache Software Foundation, Licensed under the Apache License, Version 2.0
    Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation.
    All other marks mentioned may be trademarks or registered trademarks of their respective owners.