Class CQLParser
java.lang.Object
org.z3950.zing.cql.CQLParser
Compiles CQL strings into parse trees of CQLNode subtypes.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal booleanstatic final intstatic final intstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionThe new parser implements CQL 1.2CQLParser(int compat) The new parser implements a dialect of CQL specified by thecompatargument: V1POINT1 - CQL version 1.1 V1POINT2 - CQL version 1.2 V1POINT1SORT - CQL version 1.1 but including sortby as specified for CQL 1.2.CQLParser(int compat, boolean allowKeywordTerms) Official CQL grammar allows registered keywords like 'and/or/not/sortby/prox' to be used unquoted in terms. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidSimple test-harness for the CQLParser class.Compiles a CQL query.booleanregisterCustomRelation(String relation) Registers custom relation in this parser.booleanunregisterCustomRelation(String relation) Unregisters previously registered custom relation in this instance of the parser.
-
Field Details
-
V1POINT1
public static final int V1POINT1- See Also:
-
V1POINT2
public static final int V1POINT2- See Also:
-
V1POINT1SORT
public static final int V1POINT1SORT- See Also:
-
allowKeywordTerms
public final boolean allowKeywordTerms
-
-
Constructor Details
-
CQLParser
public CQLParser(int compat) The new parser implements a dialect of CQL specified by thecompatargument:- V1POINT1 - CQL version 1.1
- V1POINT2 - CQL version 1.2
- V1POINT1SORT - CQL version 1.1 but including sortby as specified for CQL 1.2.
-
CQLParser
public CQLParser(int compat, boolean allowKeywordTerms) Official CQL grammar allows registered keywords like 'and/or/not/sortby/prox' to be used unquoted in terms. This constructor allows to create an instance of a parser that prohibits this behavior while sacrificing compatibility.- Parameters:
compat- CQL version compatibilityallowKeywordTerms- when false registered keywords are disallowed in unquoted terms
-
CQLParser
public CQLParser()The new parser implements CQL 1.2
-
-
Method Details
-
registerCustomRelation
Registers custom relation in this parser. Note that when a custom relation is registered the parser is no longer strictly compliant with the chosen spec. Custom relations are case-insensitive.- Parameters:
relation-- Returns:
- true if custom relation has not been registered already
-
unregisterCustomRelation
Unregisters previously registered custom relation in this instance of the parser.- Parameters:
relation-- Returns:
- true is relation has been previously registered
-
parse
Compiles a CQL query.The resulting parse tree may be further processed by hand (see the individual node-types' documentation for details on the data structure) or, more often, simply rendered out in the desired form using one of the back-ends.
toCQL()returns a decompiled CQL query equivalent to the one that was compiled in the first place;toXCQL()returns an XML snippet representing the query; andtoPQF()returns the query rendered in Index Data's Prefix Query Format.- Parameters:
cql- The query- Returns:
- A CQLNode object which is the root of a parse tree representing the query.
- Throws:
CQLParseExceptionIOException
-
main
Simple test-harness for the CQLParser class.Reads a CQL query either from its command-line argument, if there is one, or standard input otherwise. So these two invocations are equivalent:
CQLParser 'au=(Kerninghan or Ritchie) and ti=Unix' echo au=(Kerninghan or Ritchie) and ti=Unix | CQLParser
The test-harness parses the supplied query and renders is as XCQL, so that both of the invocations above produce the following output:<triple> <boolean> <value>and</value> </boolean> <triple> <boolean> <value>or</value> </boolean> <searchClause> <index>au</index> <relation> <value>=</value> </relation> <term>Kerninghan</term> </searchClause> <searchClause> <index>au</index> <relation> <value>=</value> </relation> <term>Ritchie</term> </searchClause> </triple> <searchClause> <index>ti</index> <relation> <value>=</value> </relation> <term>Unix</term> </searchClause> </triple>
-