|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object tribble.search.DocumentQueryFilter
Generic document entry filter.
Interprets simple SQL-like queries to select documents.
The following query syntax is supported: query-expr: or-expr or-expr: and-expr and-expr 'OR' or-expr and-expr: cmp-expr cmp-expr 'AND' not-expr not-expr: cmp-expr 'NOT' not-expr cmp-expr: operand operand ['NOT'] '=' operand operand ['NOT'] '<>' operand operand ['NOT'] '<' operand operand ['NOT'] '<=' operand operand ['NOT'] '<' operand operand ['NOT'] '<=' operand operand ['NOT'] 'CONTAINS' string operand ['NOT'] 'LIKE' text-pattern operand ['NOT'] 'LIKEFILE' filename-pattern operand ['NOT'] 'IN' '(' operand-list ')' operand ['NOT'] 'BETWEEN' operand 'AND' operand operand 'IS' ['NOT'] 'NULL' operand-list: operand operand [','] operand-list operand: '(' or-expr ')' name-expr number date-string name-expr: name string name-expr '.' name name-expr '.' string name-expr '[' operand ']'
A name operand is a document attribute, or one of the following predefined attributes:
name - Document name (string) size - Document length (numeric) date - Document date ("yyyy-mm-dd hh:mm:ss.uuu") age - Document age in milliseconds type - Document type name (string) exists - "Y" if the document exists, "N" otherwise directory - "Y" if the document is a directory, "N" otherwise readable - "Y" if the document is readable, "N" otherwise writable - "Y" if the document is writable, "N" otherwise
Any name operand that is not one of the predefined names above is
assumed to be an attribute that is specific to the implementation of the
document class, and its value is retrieved using the
DocumentI.getAttribute()
method.
Other operands may be the following:
number - Numeric literal 'string' - Character string literal "string" - Character string literal
A date-string is a quoted string containing the following components:
yyyy-mm-dd hh:mm:ss.uuu - Date/time literal yyyy - Year mm - Month dd - Day of the month hh - Hour mm - Minute ss - Second uuu - MillisecondDate/time components may be omitted on the right; any omitted components are assumed to match any value allowed. For example, the date value "2001-09-11 08" matches any date within the range 2001-09-11 08:00:00.000 to 2001-09-11 08:59:59.999.
A text-pattern is composed of normal characters and special pattern-matching characters, which are:
_ - Matches any single character % - Matches zero or more characters \x - Removes the special meaning of x
A filename-pattern is composed of normal characters and special filename pattern-matching characters, which are:
? - Matches any single character * - Matches zero or more characters [abc] - Matches a single character in the set {a,b,c} [a-z] - Matches a single character in the range {a-z} [^a-z] - Matches a single character not in the range {a-z} / - Matches a directory path separator \x - Removes the special meaning of x
DocumentSearcherI
,
DocumentI
,
QueryParser
,
FilenamePattern
Field Summary | |
protected static java.lang.String |
ATTR_AGE
|
protected static java.lang.String |
ATTR_DATE
|
protected static java.lang.String |
ATTR_EXISTS
|
protected static java.lang.String |
ATTR_ISDIR
|
protected static java.lang.String |
ATTR_NAME
|
protected static java.lang.String |
ATTR_READ
|
protected static java.lang.String |
ATTR_SIZE
|
protected static java.lang.String |
ATTR_TYPE
|
protected static java.lang.String |
ATTR_WRITE
|
protected static java.lang.String[] |
ATTRIBUTES
|
protected java.text.SimpleDateFormat |
m_dateFmt
Date format specifier. |
protected QueryExpr |
m_expr
Query expression tree. |
protected long |
m_now
Current date/time (in milliseconds since 1970-01-01). |
protected java.lang.String |
m_query
Query expression. |
Fields inherited from interface tribble.search.DocumentFilterI |
SERIES |
Constructor Summary | |
DocumentQueryFilter(java.lang.String query)
Constructor. |
Method Summary | |
boolean |
accept(DocumentI doc)
Accept or reject a document entry. |
protected int |
compare(DocumentI doc,
java.lang.String attr,
java.lang.String lit)
Compare a document attribute and a literal value. |
protected java.lang.String |
getDocumentAttribute(DocumentI doc,
java.lang.String attr)
Retrieve a named attribute for a document entry. |
protected boolean |
matches(DocumentI doc,
QueryExpr query)
Compare a document entry against a query expression. |
protected QueryExpr |
optimizeExpr(QueryExpr expr)
Optimize a search query expression. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final java.lang.String ATTR_NAME
protected static final java.lang.String ATTR_TYPE
protected static final java.lang.String ATTR_SIZE
protected static final java.lang.String ATTR_DATE
protected static final java.lang.String ATTR_AGE
protected static final java.lang.String ATTR_EXISTS
protected static final java.lang.String ATTR_ISDIR
protected static final java.lang.String ATTR_READ
protected static final java.lang.String ATTR_WRITE
protected static final java.lang.String[] ATTRIBUTES
protected java.lang.String m_query
protected QueryExpr m_expr
protected java.text.SimpleDateFormat m_dateFmt
protected long m_now
Constructor Detail |
public DocumentQueryFilter(java.lang.String query) throws java.text.ParseException
query
- An SQL-like query expression, which specifies the criteria for accepting
documents during a search operation.
See the Query Syntax section for more details.
java.text.ParseException
- Thrown if the query expression is malformed.QueryExpr
,
QueryParser
Method Detail |
public boolean accept(DocumentI doc) throws java.lang.Exception
accept
in interface DocumentFilterI
doc
- A document entry.
java.lang.Exception
- Thrown if the selection criteria are malformed, or if some other error
occurs.DocumentSearcherI.find(tribble.search.DocumentFilterI)
protected QueryExpr optimizeExpr(QueryExpr expr) throws java.lang.Exception
expr
- A search query expression.
java.lang.Exception
- Thrown if the selection criteria are malformed, or if some other error
occurs.DocumentQueryFilter()
protected boolean matches(DocumentI doc, QueryExpr query) throws java.lang.Exception
doc
- A document entry.query
- A query expression tree.
java.lang.Exception
- Thrown if the query criteria are malformed, or if some other error occurs.accept(tribble.search.DocumentI)
protected int compare(DocumentI doc, java.lang.String attr, java.lang.String lit) throws java.lang.Exception
doc
- A document entry.attr
- The name of a document attribute (e.g., "name", "size",
etc.) associated with it.lit
- Literal value to compare the document attribute to.
java.lang.Exception
- Thrown is the document does not have an attribute with the specified name,
or if some other error occurs.protected java.lang.String getDocumentAttribute(DocumentI doc, java.lang.String attr) throws java.lang.Exception
doc
- A document entry.attr
- The name of a document attribute (e.g., "name", "size",
etc.) associated with it.
java.lang.Exception
- Thrown is the document does not have an attribute with the specified name,
or if some other error occurs.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |