Class ComplexPhraseQueryParser

  • All Implemented Interfaces:
    QueryParserConstants, CommonQueryParserConfiguration

    public class ComplexPhraseQueryParser
    extends QueryParser
    QueryParser which permits complex phrase query syntax eg "(john jon jonathan~) peters*".

    Performs potentially multiple passes over Query text to parse any nested logic in PhraseQueries. - First pass takes any PhraseQuery content between quotes and stores for subsequent pass. All other query content is parsed as normal - Second pass parses any stored PhraseQuery content, checking all embedded clauses are referring to the same field and therefore can be rewritten as Span queries. All PhraseQuery clauses are expressed as ComplexPhraseQuery objects

    This could arguably be done in one pass using a new QueryParser but here I am working within the constraints of the existing parser as a base class. This currently simply feeds all phrase content through an analyzer to select phrase terms - any "special" syntax such as * ~ * etc are not given special status

    • Constructor Detail

      • ComplexPhraseQueryParser

        public ComplexPhraseQueryParser​(String f,
                                        Analyzer a)
    • Method Detail

      • setInOrder

        public void setInOrder​(boolean inOrder)
        When inOrder is true, the search terms must exists in the documents as the same order as in query.
        Parameters:
        inOrder - parameter to choose between ordered or un-ordered proximity search
      • getWildcardQuery

        protected Query getWildcardQuery​(String field,
                                         String termStr)
                                  throws ParseException
        Description copied from class: QueryParserBase
        Factory method for generating a query. Called when parser parses an input term token that contains one or more wildcard characters (? and *), but is not a prefix term token (one that has just a single * character at the end)

        Depending on settings, prefix term may be lower-cased automatically. It will not go through the default Analyzer, however, since normal Analyzers are unlikely to work properly with wildcard templates.

        Can be overridden by extending classes, to provide custom handling for wildcard queries, which may be necessary due to missing analyzer calls.

        Overrides:
        getWildcardQuery in class QueryParserBase
        Parameters:
        field - Name of the field query will use.
        termStr - Term token that contains one or more wild card characters (? or *), but is not simple prefix term
        Returns:
        Resulting Query built for the term
        Throws:
        ParseException - throw in overridden method to disallow
      • newRangeQuery

        protected Query newRangeQuery​(String field,
                                      String part1,
                                      String part2,
                                      boolean startInclusive,
                                      boolean endInclusive)
        Description copied from class: QueryParserBase
        Builds a new TermRangeQuery instance
        Overrides:
        newRangeQuery in class QueryParserBase
        Parameters:
        field - Field
        part1 - min
        part2 - max
        startInclusive - true if the start of the range is inclusive
        endInclusive - true if the end of the range is inclusive
        Returns:
        new TermRangeQuery instance