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
    System.Object
    Lucene.Net.Analysis.Analyzer
    MockAnalyzer
    Implements
    System.IDisposable
    Inherited Members
    Lucene.Net.Analysis.Analyzer.NewAnonymous(System.Func<System.String, System.IO.TextReader, Lucene.Net.Analysis.TokenStreamComponents>)
    Lucene.Net.Analysis.Analyzer.NewAnonymous(System.Func<System.String, System.IO.TextReader, Lucene.Net.Analysis.TokenStreamComponents>, Lucene.Net.Analysis.ReuseStrategy)
    Lucene.Net.Analysis.Analyzer.NewAnonymous(System.Func<System.String, System.IO.TextReader, Lucene.Net.Analysis.TokenStreamComponents>, System.Func<System.String, System.IO.TextReader, System.IO.TextReader>)
    Lucene.Net.Analysis.Analyzer.NewAnonymous(System.Func<System.String, System.IO.TextReader, Lucene.Net.Analysis.TokenStreamComponents>, System.Func<System.String, System.IO.TextReader, System.IO.TextReader>, Lucene.Net.Analysis.ReuseStrategy)
    Lucene.Net.Analysis.Analyzer.GetTokenStream(System.String, System.IO.TextReader)
    Lucene.Net.Analysis.Analyzer.GetTokenStream(System.String, System.String)
    Lucene.Net.Analysis.Analyzer.InitReader(System.String, System.IO.TextReader)
    Lucene.Net.Analysis.Analyzer.Strategy
    Lucene.Net.Analysis.Analyzer.Dispose()
    Lucene.Net.Analysis.Analyzer.Dispose(System.Boolean)
    Lucene.Net.Analysis.Analyzer.GLOBAL_REUSE_STRATEGY
    Lucene.Net.Analysis.Analyzer.PER_FIELD_REUSE_STRATEGY
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Lucene.Net.Analysis
    Assembly: Lucene.Net.TestFramework.dll
    Syntax
    public sealed class MockAnalyzer : Analyzer, IDisposable

    Constructors

    | Improve this Doc View Source

    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
    System.Random random
    | Improve this Doc View Source

    MockAnalyzer(Random, CharacterRunAutomaton, Boolean)

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

    Declaration
    public MockAnalyzer(Random random, CharacterRunAutomaton runAutomaton, bool lowerCase)
    Parameters
    Type Name Description
    System.Random random
    Lucene.Net.Util.Automaton.CharacterRunAutomaton runAutomaton
    System.Boolean lowerCase
    | Improve this Doc View Source

    MockAnalyzer(Random, CharacterRunAutomaton, Boolean, CharacterRunAutomaton)

    Creates a new MockAnalyzer.

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

    Random for payloads behavior

    Lucene.Net.Util.Automaton.CharacterRunAutomaton runAutomaton

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

    System.Boolean lowerCase

    true if the tokenizer should lowercase terms

    Lucene.Net.Util.Automaton.CharacterRunAutomaton filter

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

    Properties

    | Improve this Doc View Source

    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
    System.Boolean
    | Improve this Doc View Source

    MaxTokenLength

    Toggle maxTokenLength for MockTokenizer.

    Declaration
    public int MaxTokenLength { get; set; }
    Property Value
    Type Description
    System.Int32

    Methods

    | Improve this Doc View Source

    CreateComponents(String, TextReader)

    Declaration
    protected override TokenStreamComponents CreateComponents(string fieldName, TextReader reader)
    Parameters
    Type Name Description
    System.String fieldName
    System.IO.TextReader reader
    Returns
    Type Description
    Lucene.Net.Analysis.TokenStreamComponents
    Overrides
    Lucene.Net.Analysis.Analyzer.CreateComponents(System.String, System.IO.TextReader)
    | Improve this Doc View Source

    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
    System.String fieldName

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

    Returns
    Type Description
    System.Int32
    Overrides
    Lucene.Net.Analysis.Analyzer.GetOffsetGap(System.String)
    | Improve this Doc View Source

    GetPositionIncrementGap(String)

    Declaration
    public override int GetPositionIncrementGap(string fieldName)
    Parameters
    Type Name Description
    System.String fieldName
    Returns
    Type Description
    System.Int32
    Overrides
    Lucene.Net.Analysis.Analyzer.GetPositionIncrementGap(System.String)
    | Improve this Doc View Source

    SetOffsetGap(Int32)

    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
    System.Int32 offsetGap
    | Improve this Doc View Source

    SetPositionIncrementGap(Int32)

    Declaration
    public void SetPositionIncrementGap(int positionIncrementGap)
    Parameters
    Type Name Description
    System.Int32 positionIncrementGap

    Implements

    System.IDisposable

    See Also

    MockTokenizer
    • Improve this Doc
    • View Source
    Back to top Copyright © 2021 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.