Package org.apache.lucene.search.suggest.document

# Class CompletionAnalyzer

java.lang.Object
org.apache.lucene.analysis.Analyzer
org.apache.lucene.analysis.AnalyzerWrapper
org.apache.lucene.search.suggest.document.CompletionAnalyzer

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`

public final class CompletionAnalyzer extends AnalyzerWrapper
Wraps an `Analyzer` to provide additional completion-only tuning (e.g. preserving token separators, preserving position increments while converting a token stream to an automaton)

Can be used to index `SuggestField` and `ContextSuggestField` and as a query analyzer to `PrefixCompletionQuery` amd `FuzzyCompletionQuery`

NOTE: In most cases, index and query analyzer should have same values for `preservePositionIncrements()` and `preserveSep()`

Since:
  5.1.0
WARNING: This API is experimental and might change in incompatible ways in the next release.

## Nested Class Summary

## Nested classes/interfaces inherited from class org.apache.lucene.analysis.Analyzer

`Analyzer.ReuseStrategy, Analyzer.TokenStreamComponents`

## Field Summary

### Fields inherited from class org.apache.lucene.analysis.Analyzer

`GLOBAL_REUSE_STRATEGY, PER_FIELD_REUSE_STRATEGY`

## Constructor Summary

Constructors
Constructor
Description
`CompletionAnalyzer(Analyzer analyzer)`
Calls `CompletionAnalyzer(org.apache.lucene.analysis.Analyzer, boolean, boolean, int)` preserving token separation, position increments and no limit on graph expansions
`CompletionAnalyzer(Analyzer analyzer, boolean preserveSep, boolean preservePositionIncrements)`
Calls `CompletionAnalyzer(org.apache.lucene.analysis.Analyzer, boolean, boolean, int)` with no limit on graph expansions
`CompletionAnalyzer(Analyzer analyzer, boolean preserveSep, boolean preservePositionIncrements, int maxGraphExpansions)`
Wraps an analyzer to convert its output token stream to an automaton
`CompletionAnalyzer(Analyzer analyzer, int maxGraphExpansions)`
Calls `CompletionAnalyzer(org.apache.lucene.analysis.Analyzer, boolean, boolean, int)` preserving token separation and position increments

## Method Summary

Modifier and Type
Method
Description
`protected Analyzer`
`getWrappedAnalyzer(String fieldName)`
`boolean`
`preservePositionIncrements()`
Returns true if position increments are preserved when converting the token stream to an automaton
`boolean`
`preserveSep()`
Returns true if separation between tokens are preserved when converting the token stream to an automaton
`protected Analyzer.TokenStreamComponents`
`wrapComponents(String fieldName, Analyzer.TokenStreamComponents components)`

### Methods inherited from class org.apache.lucene.analysis.AnalyzerWrapper

`attributeFactory, createComponents, getOffsetGap, getPositionIncrementGap, initReader, initReaderForNormalization, normalize, wrapReader, wrapReaderForNormalization, wrapTokenStreamForNormalization`

### Methods inherited from class org.apache.lucene.analysis.Analyzer

`close, getReuseStrategy, normalize, tokenStream, tokenStream`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### CompletionAnalyzer

public CompletionAnalyzer(Analyzer analyzer, boolean preserveSep, boolean preservePositionIncrements, int maxGraphExpansions)
Wraps an analyzer to convert its output token stream to an automaton

Parameters:
  `analyzer` - token stream to be converted to an automaton
  `preserveSep` - Preserve separation between tokens when converting to an automaton
  `preservePositionIncrements` - Preserve position increments for tokens when converting to an automaton
  `maxGraphExpansions` - Sets the maximum number of graph expansions of a completion automaton

### CompletionAnalyzer

public CompletionAnalyzer(Analyzer analyzer)
Calls `CompletionAnalyzer(org.apache.lucene.analysis.Analyzer, boolean, boolean, int)` preserving token separation, position increments and no limit on graph expansions

### CompletionAnalyzer

public CompletionAnalyzer(Analyzer analyzer, boolean preserveSep, boolean preservePositionIncrements)
Calls `CompletionAnalyzer(org.apache.lucene.analysis.Analyzer, boolean, boolean, int)` with no limit on graph expansions

### CompletionAnalyzer

public CompletionAnalyzer(Analyzer analyzer, int maxGraphExpansions)
Calls `CompletionAnalyzer(org.apache.lucene.analysis.Analyzer, boolean, boolean, int)` preserving token separation and position increments

## Method Details

### preserveSep

public boolean preserveSep()
Returns true if separation between tokens are preserved when converting the token stream to an automaton

### preservePositionIncrements

public boolean preservePositionIncrements()
Returns true if position increments are preserved when converting the token stream to an automaton

### getWrappedAnalyzer

protected Analyzer getWrappedAnalyzer(String fieldName)

Specified by:
  `getWrappedAnalyzer` in class `AnalyzerWrapper`

### wrapComponents

protected Analyzer.TokenStreamComponents wrapComponents(String fieldName, Analyzer.TokenStreamComponents components)

Overrides:
  `wrapComponents` in class `AnalyzerWrapper`