Class QueryParserHelper
- java.lang.Object
-
- org.apache.lucene.queryparser.flexible.core.QueryParserHelper
-
- Direct Known Subclasses:
StandardQueryParser
public class QueryParserHelper extends Object
This class is a helper for the query parser framework, it does all the three query parser phrases at once: text parsing, query processing and query building.It contains methods that allows the user to change the implementation used on the three phases.
- See Also:
QueryNodeProcessor
,SyntaxParser
,QueryBuilder
,QueryConfigHandler
-
-
Constructor Summary
Constructors Constructor Description QueryParserHelper(QueryConfigHandler queryConfigHandler, SyntaxParser syntaxParser, QueryNodeProcessor processor, QueryBuilder builder)
Creates a query parser helper object using the specified configuration, text parser, processor and builder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description QueryBuilder
getQueryBuilder()
Returns the query builder used to build a object from the query node tree.QueryConfigHandler
getQueryConfigHandler()
Returns the query configuration handler, which is used during the query node tree processing.QueryNodeProcessor
getQueryNodeProcessor()
Returns the processor object used to process the query node tree, it returnsnull
if no processor is used.SyntaxParser
getSyntaxParser()
Returns the text parser used to build a query node tree from a query string.Object
parse(String query, String defaultField)
Parses a query string to an object, usually some query object.
In this method the three phases are executed:
1st - the query string is parsed using the text parser returned bygetSyntaxParser()
, the result is a query node tree
2nd - the query node tree is processed by the processor returned bygetQueryNodeProcessor()
3th - a object is built from the query node tree using the builder returned bygetQueryBuilder()
void
setQueryBuilder(QueryBuilder queryBuilder)
The query builder that will be used to build an object from the query node tree.void
setQueryConfigHandler(QueryConfigHandler config)
Sets the query configuration handler that will be used during query processing.void
setQueryNodeProcessor(QueryNodeProcessor processor)
Sets the processor that will be used to process the query node tree.void
setSyntaxParser(SyntaxParser syntaxParser)
Sets the text parser that will be used to parse the query string, it cannot benull
.
-
-
-
Constructor Detail
-
QueryParserHelper
public QueryParserHelper(QueryConfigHandler queryConfigHandler, SyntaxParser syntaxParser, QueryNodeProcessor processor, QueryBuilder builder)
Creates a query parser helper object using the specified configuration, text parser, processor and builder.- Parameters:
queryConfigHandler
- the query configuration handler that will be initially set to this helpersyntaxParser
- the text parser that will be initially set to this helperprocessor
- the query processor that will be initially set to this helperbuilder
- the query builder that will be initially set to this helper- See Also:
QueryNodeProcessor
,SyntaxParser
,QueryBuilder
,QueryConfigHandler
-
-
Method Detail
-
getQueryNodeProcessor
public QueryNodeProcessor getQueryNodeProcessor()
Returns the processor object used to process the query node tree, it returnsnull
if no processor is used.- Returns:
- the actual processor used to process the query node tree,
null
if no processor is used - See Also:
QueryNodeProcessor
,setQueryNodeProcessor(QueryNodeProcessor)
-
setQueryNodeProcessor
public void setQueryNodeProcessor(QueryNodeProcessor processor)
Sets the processor that will be used to process the query node tree. If there is anyQueryConfigHandler
returned bygetQueryConfigHandler()
, it will be set on the processor. The argument can benull
, which means that no processor will be used to process the query node tree.- Parameters:
processor
- the processor that will be used to process the query node tree, this argument can benull
- See Also:
getQueryNodeProcessor()
,QueryNodeProcessor
-
setSyntaxParser
public void setSyntaxParser(SyntaxParser syntaxParser)
Sets the text parser that will be used to parse the query string, it cannot benull
.- Parameters:
syntaxParser
- the text parser that will be used to parse the query string- See Also:
getSyntaxParser()
,SyntaxParser
-
setQueryBuilder
public void setQueryBuilder(QueryBuilder queryBuilder)
The query builder that will be used to build an object from the query node tree. It cannot benull
.- Parameters:
queryBuilder
- the query builder used to build something from the query node tree- See Also:
getQueryBuilder()
,QueryBuilder
-
getQueryConfigHandler
public QueryConfigHandler getQueryConfigHandler()
Returns the query configuration handler, which is used during the query node tree processing. It can benull
.- Returns:
- the query configuration handler used on the query processing,
null
if not query configuration handler is defined - See Also:
QueryConfigHandler
,setQueryConfigHandler(QueryConfigHandler)
-
getQueryBuilder
public QueryBuilder getQueryBuilder()
Returns the query builder used to build a object from the query node tree. The object produced by this builder is returned byparse(String, String)
.- Returns:
- the query builder
- See Also:
setQueryBuilder(QueryBuilder)
,QueryBuilder
-
getSyntaxParser
public SyntaxParser getSyntaxParser()
Returns the text parser used to build a query node tree from a query string. The default text parser instance returned by this method is aSyntaxParser
.- Returns:
- the text parse used to build query node trees.
- See Also:
SyntaxParser
,setSyntaxParser(SyntaxParser)
-
setQueryConfigHandler
public void setQueryConfigHandler(QueryConfigHandler config)
Sets the query configuration handler that will be used during query processing. It can benull
. It's also set to the processor returned bygetQueryNodeProcessor()
.- Parameters:
config
- the query configuration handler used during query processing, it can benull
- See Also:
getQueryConfigHandler()
,QueryConfigHandler
-
parse
public Object parse(String query, String defaultField) throws QueryNodeException
Parses a query string to an object, usually some query object.
In this method the three phases are executed:
1st - the query string is parsed using the text parser returned bygetSyntaxParser()
, the result is a query node tree
2nd - the query node tree is processed by the processor returned bygetQueryNodeProcessor()
3th - a object is built from the query node tree using the builder returned bygetQueryBuilder()
- Parameters:
query
- the query stringdefaultField
- the default field used by the text parser- Returns:
- the object built from the query
- Throws:
QueryNodeException
- if something wrong happens along the three phases
-
-