Class CommonGramsQueryFilter
java.lang.Object
org.apache.lucene.util.AttributeSource
org.apache.lucene.analysis.TokenStream
org.apache.lucene.analysis.TokenFilter
org.apache.lucene.analysis.commongrams.CommonGramsQueryFilter
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Unwrappable<TokenStream>
Wrap a CommonGramsFilter optimizing phrase queries by only returning single words when they are
not a member of a bigram.
Example:
- query input to CommonGramsFilter: "the rain in spain falls mainly"
- output of CommomGramsFilter/input to CommonGramsQueryFilter: |"the, "the-rain"|"rain" "rain-in"|"in, "in-spain"|"spain"|"falls"|"mainly"
- output of CommonGramsQueryFilter:"the-rain", "rain-in" ,"in-spain", "falls", "mainly"
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.util.AttributeSource
AttributeSource.State
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private final PositionIncrementAttribute
private final PositionLengthAttribute
private AttributeSource.State
private String
private final TypeAttribute
Fields inherited from class org.apache.lucene.analysis.TokenFilter
input
Fields inherited from class org.apache.lucene.analysis.TokenStream
DEFAULT_TOKEN_ATTRIBUTE_FACTORY
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new CommonGramsQueryFilter based on the provided CommomGramsFilter -
Method Summary
Modifier and TypeMethodDescriptionboolean
Output bigrams whenever possible to optimize queries.boolean
Convenience method to check if the current type is a gram typevoid
reset()
This method is called by a consumer before it begins consumption usingTokenStream.incrementToken()
.Methods inherited from class org.apache.lucene.analysis.TokenFilter
close, end, unwrap
Methods inherited from class org.apache.lucene.util.AttributeSource
addAttribute, addAttributeImpl, captureState, clearAttributes, cloneAttributes, copyTo, endAttributes, equals, getAttribute, getAttributeClassesIterator, getAttributeFactory, getAttributeImplsIterator, hasAttribute, hasAttributes, hashCode, reflectAsString, reflectWith, removeAllAttributes, restoreState, toString
-
Field Details
-
typeAttribute
-
posIncAttribute
-
posLengthAttribute
-
previous
-
previousType
-
exhausted
private boolean exhausted
-
-
Constructor Details
-
CommonGramsQueryFilter
Constructs a new CommonGramsQueryFilter based on the provided CommomGramsFilter- Parameters:
input
- CommonGramsFilter the QueryFilter will use
-
-
Method Details
-
reset
Description copied from class:TokenFilter
This method is called by a consumer before it begins consumption usingTokenStream.incrementToken()
.Resets this stream to a clean state. Stateful implementations must implement this method so that they can be reused, just as if they had been created fresh.
If you override this method, always call
super.reset()
, otherwise some internal state will not be correctly reset (e.g.,Tokenizer
will throwIllegalStateException
on further usage).NOTE: The default implementation chains the call to the input TokenStream, so be sure to call
super.reset()
when overriding this method.- Overrides:
reset
in classTokenFilter
- Throws:
IOException
-
incrementToken
Output bigrams whenever possible to optimize queries. Only output unigrams when they are not a member of a bigram. Example:- input: "the rain in spain falls mainly"
- output:"the-rain", "rain-in" ,"in-spain", "falls", "mainly"
- Specified by:
incrementToken
in classTokenStream
- Returns:
- false for end of stream; true otherwise
- Throws:
IOException
-
isGramType
public boolean isGramType()Convenience method to check if the current type is a gram type- Returns:
true
if the current type is a gram type,false
otherwise
-