public class QueryParser
extends java.lang.Object
Parser class which consists of methods to parse complex queries into a structured tree of query filters. This class will be expanded or extended in the future to handle different syntaxes. The default syntax is described below:
Parsed terms | Interpretation | Top-level filter |
---|---|---|
green | Search all fields for "green" | SearchTerm |
color:green | Search the field named "color" for the value "green" | MatchFilter |
green blue green&blue green AND blue |
search for both green and blue in all fields | TreeClause, with AND flag set to true |
green|blue green OR blue |
search for either green or blue in all fields | TreeClause with AND flag set to false |
green AND (blue OR RED) | Example illustrating use of parenthesis | TreeClause |
color:green OR blue | Search the field named "color" for the value "green", or "blue" in any field | TreeClause, containing a MatchFilter and a SearchTerm |
green^blue | Search for green and blue within a few words of each other. | ProximitySearch |
birthdate:2004-07-23 | Search the field named "birthdate" for the value 2004-07-23 (July 23rd, 2004) | MatchClause |
birthdate:<2006-07-08 | Search the field named "birthdate" for the values before (less than) 2006-07-08 (July 8th, 2006). Greater than/after also supported | RangeClause |
eventdate:2006-08-318T11:30:00Z..2006-08-31T14:30:00Z | Search the field named "eventdate" for the values between 1130am and 230pm on Aug 31st, 2006 | RangeClause |
coordField:10@11.11,22.22 | Search the field named "coordField" for coordinates up to 10 kilometers (the default measurement) from Latitude 11.11 north, 22.22 east. Coordinates specified in decimal degrees, and south and west latitudes specified by negative numbers | GeoClause |
Constructor and Description |
---|
QueryParser() |
Modifier and Type | Method and Description |
---|---|
static void |
main(java.lang.String[] args)
Main method for testing and validating the format of strings passed in
|
TreeClause |
parseQuery(java.lang.String termString)
Parse a query string into a TreeClause.
|
protected java.lang.Object |
parseValue(java.lang.String valueString)
Attempt to parse a particular value into a QueryValue object.
|
public TreeClause parseQuery(java.lang.String termString) throws java.text.ParseException
termString
- the query stringjava.text.ParseException
protected java.lang.Object parseValue(java.lang.String valueString)
valueString
- the string valuepublic static void main(java.lang.String[] args) throws java.text.ParseException, java.io.IOException
args
- command line arguments. Ignoredjava.text.ParseException
- if there is a problem parsing a queryjava.io.IOException
- if there is a problem opening STDIN