public class KeywordQueryParser
extends org.apache.lucene.queryparser.flexible.standard.StandardQueryParser
To construct a Query
object from a query string, use the
StandardQueryParser.parse(String, String)
method:
KeywordQueryParser queryParser = new KeywordQueryParser();To change any configuration before parsing the query string do, for example:
Query query = queryParser.parse("a : b", "sirenField");
queryParser.getQueryConfigHandler().setDefaultOperator(Operator.AND);or use the setter methods:
queryParser.setDefaultOperator(Operator.AND);
Examples of appropriately formatted queries can be found in the query syntax documentation.
The text parser used by this helper is a KeywordSyntaxParser
. The
BNF grammar of this parser is available here.
The QueryConfigHandler
used by this helper is a
KeywordQueryConfigHandler
.
The query node processor used by this helper is a
KeywordQueryNodeProcessorPipeline
.
The builder used by this helper is a KeywordQueryTreeBuilder
.
Constructor and Description |
---|
KeywordQueryParser()
Constructs a
KeywordQueryParser object. |
Modifier and Type | Method and Description |
---|---|
void |
setAllowFuzzyAndWildcard(boolean allowFuzzyWildcard)
Set to
true to allow fuzzy and wildcard queries. |
void |
setAllowTwig(boolean allowTwig)
Enable or not
TwigQuery |
void |
setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer) |
void |
setDatatypeAnalyzers(Map<String,org.apache.lucene.analysis.Analyzer> dtAnalyzers)
Set the
Map that associates a datatype to its Analyzer . |
void |
setDefaultOperator(org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler.Operator operator)
Sets the boolean operator of the QueryParser.
|
void |
setQNames(Properties qnames)
Set the set of qnames to URI mappings.
|
void |
setRootLevel(int level)
Set the default root level of a
TwigQuery |
String |
toString() |
getAllowLeadingWildcard, getAnalyzer, getDateResolution, getDateResolutionMap, getDefaultOperator, getEnablePositionIncrements, getFieldsBoost, getFuzzyMinSim, getFuzzyPrefixLength, getLocale, getLowercaseExpandedTerms, getMultiFields, getMultiTermRewriteMethod, getNumericConfigMap, getPhraseSlop, getTimeZone, parse, setAllowLeadingWildcard, setDateResolution, setDateResolution, setDateResolutionMap, setDefaultPhraseSlop, setEnablePositionIncrements, setFieldsBoost, setFuzzyMinSim, setFuzzyPrefixLength, setLocale, setLowercaseExpandedTerms, setMultiFields, setMultiTermRewriteMethod, setNumericConfigMap, setPhraseSlop, setTimeZone
public KeywordQueryParser()
KeywordQueryParser
object.public void setDefaultOperator(org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler.Operator operator)
StandardQueryConfigHandler.Operator.OR
) terms without any modifiers are considered optional:
for example capital of Hungary
is equal to
capital OR of OR Hungary
.StandardQueryConfigHandler.Operator.AND
mode terms are considered to be in conjunction: the
above mentioned query is parsed as capital AND of AND Hungary
Default: StandardQueryConfigHandler.Operator.AND
setDefaultOperator
in class org.apache.lucene.queryparser.flexible.standard.StandardQueryParser
public void setQNames(Properties qnames)
Default: null
.
public void setAllowFuzzyAndWildcard(boolean allowFuzzyWildcard)
true
to allow fuzzy and wildcard queries.
Default: true
.
public void setDatatypeAnalyzers(Map<String,org.apache.lucene.analysis.Analyzer> dtAnalyzers)
Map
that associates a datatype to its Analyzer
.
Default:
map.put(XSDDatatype.XSD_STRING, new StandardAnalyzer(Version.LUCENE_40)); map.put(JSONDatatype.JSON_FIELD, new WhitespaceAnalyzer(Version.LUCENE_40));
public void setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
setAnalyzer
in class org.apache.lucene.queryparser.flexible.standard.StandardQueryParser
public void setRootLevel(int level)
TwigQuery
Default: 1
public void setAllowTwig(boolean allowTwig)
TwigQuery
Default: true
public String toString()
toString
in class org.apache.lucene.queryparser.flexible.standard.StandardQueryParser
Copyright © 2014. All rights reserved.