public class JsonQueryParser
extends org.apache.lucene.queryparser.flexible.core.QueryParserHelper
To construct a Query
object from a query string, use the
parse(String, String)
method:
JsonQueryParser queryParser = new JsonQueryParser(); Query query = JsonQueryParser.parse("{ \"node\" : { \"query\" : \"aaa\" }}", "defaultField");
To change any configuration before parsing the query string do, for example:
// the query config handler returned byJsonQueryParser
is aJsonQueryConfigHandler
queryParser.getQueryConfigHandler().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 JsonSyntaxParser
.
The query node processor used by this helper is a
JsonQueryNodeProcessorPipeline
.
The builder used by this helper is a JsonQueryTreeBuilder
.
Constructor and Description |
---|
JsonQueryParser() |
Modifier and Type | Method and Description |
---|---|
org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler.Operator |
getDefaultOperator()
Gets implicit operator setting, which will be either
StandardQueryConfigHandler.Operator.AND
or StandardQueryConfigHandler.Operator.OR . |
KeywordQueryParser |
getKeywordQueryParser() |
org.apache.lucene.search.Query |
parse(String query,
String defaultField)
Overrides
QueryParserHelper.parse(String, String) so it casts the
return object to Query . |
void |
setDefaultOperator(org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler.Operator operator)
Sets the boolean operator of the QueryParser.
|
void |
setKeywordQueryParser(KeywordQueryParser keywordParser)
Set the keyword query parser that will be used to parse boolean expressions
found in the JSON query objects.
|
void |
setQueryConfigHandler(org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler config) |
public org.apache.lucene.search.Query parse(String query, String defaultField) throws org.apache.lucene.queryparser.flexible.core.QueryNodeException
QueryParserHelper.parse(String, String)
so it casts the
return object to Query
. For more reference about this method, check
QueryParserHelper.parse(String, String)
.parse
in class org.apache.lucene.queryparser.flexible.core.QueryParserHelper
query
- the query stringdefaultField
- the default field used by the text parserParseException
- if something wrong happens during the query parsingorg.apache.lucene.queryparser.flexible.core.QueryNodeException
public org.apache.lucene.queryparser.flexible.standard.config.StandardQueryConfigHandler.Operator getDefaultOperator()
StandardQueryConfigHandler.Operator.AND
or StandardQueryConfigHandler.Operator.OR
.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
public KeywordQueryParser getKeywordQueryParser()
public void setKeywordQueryParser(KeywordQueryParser keywordParser)
public void setQueryConfigHandler(org.apache.lucene.queryparser.flexible.core.config.QueryConfigHandler config)
setQueryConfigHandler
in class org.apache.lucene.queryparser.flexible.core.QueryParserHelper
Copyright © 2014. All rights reserved.