Class TextIndex.QueryParser

  • Enclosing class:
    TextIndex

    public static class TextIndex.QueryParser
    extends java.lang.Object
    A parser that converts a plain text query string into a query. The query parser recognizes the following syntax, except that a query may also empty without provoking a syntax error:
     query = expression [["|"] query]
     expression = term | "!" term
     term = word | "(" query ")"
     
    where a word is any word to be searched for (and not containing a space or the reserved punctuation marks "|", "!", "(", or ")". The "|" symbol performs and Or query, sequential factors are combined into And queries, "!" applies a Not query to its argument, and parentheses may be used to group the query into subexpressions. Some examples:
    Examples
    Query Find Documents Containing
    apple "apple"
    apple ball both "apple" and "ball"
    apple|ball either "apple" or "ball"
    !apple not "apple"
    !(a|b) neither "a" nor "b"
    a | b c either "a" or both "b" and "c"
    • Constructor Summary

      Constructors 
      Constructor Description
      QueryParser()
      Creates a new query parser.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TextIndex.Query parse​(java.lang.String qs)
      Parses a search expression into an executable query.
      protected java.util.LinkedList<java.lang.String> tokenize​(java.lang.String qs)
      Converts the query string into a list of tokens.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • QueryParser

        public QueryParser()
        Creates a new query parser.
    • Method Detail

      • parse

        public TextIndex.Query parse​(java.lang.String qs)
        Parses a search expression into an executable query.
        Parameters:
        qs - the query to parse
        Returns:
        a parse tree of query nodes that represents the expression
      • tokenize

        protected java.util.LinkedList<java.lang.String> tokenize​(java.lang.String qs)
        Converts the query string into a list of tokens.
        Parameters:
        qs - the query string to tokenize
        Returns:
        a possibly empty list of tokens