Class QueryParserHelper

  • Direct Known Subclasses:
    StandardQueryParser

    public class QueryParserHelper
    extends java.lang.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 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 helper
        syntaxParser - the text parser that will be initially set to this helper
        processor - the query processor that will be initially set to this helper
        builder - the query builder that will be initially set to this helper
        See Also:
        QueryNodeProcessor, SyntaxParser, QueryBuilder, QueryConfigHandler
    • Method Detail

      • setQueryNodeProcessor

        public void setQueryNodeProcessor​(QueryNodeProcessor processor)
        Sets the processor that will be used to process the query node tree. If there is any QueryConfigHandler returned by getQueryConfigHandler(), it will be set on the processor. The argument can be null, 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 be null
        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 be null.
        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 be null.
        Parameters:
        queryBuilder - the query builder used to build something from the query node tree
        See Also:
        getQueryBuilder(), QueryBuilder
      • parse

        public java.lang.Object parse​(java.lang.String query,
                                      java.lang.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 by getSyntaxParser(), the result is a query node tree

             2nd - the query node tree is processed by the processor returned by getQueryNodeProcessor()

             3th - a object is built from the query node tree using the builder returned by getQueryBuilder()
        Parameters:
        query - the query string
        defaultField - 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