org.galagosearch.core.retrieval.query
Class StructuredQuery

java.lang.Object
  extended by org.galagosearch.core.retrieval.query.StructuredQuery

public class StructuredQuery
extends java.lang.Object

Valid query language syntax: #operator:argument(...) term, or term.field, or term.field.field, etc.

Author:
trevor

Constructor Summary
StructuredQuery()
           
 
Method Summary
static Node copy(Traversal traversal, Node tree)
          Copies a query tree using a traversal object.
static java.lang.String decodeEscapes(java.lang.String escapedString)
           
static Node fieldOrNode(java.util.ArrayList<java.lang.String> fieldNames, int offset)
           
static int findEscapedEnd(java.lang.String query, int start)
          Find the end of an escaped query region.
static int findOperatorEnd(java.lang.String query, int start)
          Find the end of an operator.
static int findOperatorExpressionEnd(java.lang.String query, int offset)
           
static java.util.Set<java.lang.String> findQueryTerms(Node queryTree)
           
static int findTextEnd(java.lang.String query, int start)
           
static Node parse(java.lang.String query)
           
static java.util.ArrayList<Node> parseArguments(java.lang.String query, int offset)
          Parses arguments to an operator.
static Node parseOperator(java.lang.String operator, int offset)
          Parses an operator from the string query.
static Node parseTerm(java.lang.String query, int offset)
           
static java.util.ArrayList<java.lang.String> splitOn(java.lang.String text, char delimiter)
          Splits an input string, which may include escapes, into chunks based on a delimiter character.
static java.util.ArrayList<java.lang.String> splitStringRespectingEscapes(java.lang.String query, char split)
           
static void walk(Traversal traversal, Node tree)
          Walks a query tree with a traversal object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StructuredQuery

public StructuredQuery()
Method Detail

copy

public static Node copy(Traversal traversal,
                        Node tree)
                 throws java.lang.Exception
Copies a query tree using a traversal object. Both traversal.beforeNode and traversal.afterNode will be called for every Node object in the query tree. The traversal.beforeNode method will be called with a parent node before any of its children (pre-order), while traversal.afterNode method will be called on the parent after all of its children (post-order). The afterNode method will be called with a new copy of the original node, with the children replaced by new copies. afterNode can either return its parameter or a modified node.

Throws:
java.lang.Exception

walk

public static void walk(Traversal traversal,
                        Node tree)
                 throws java.lang.Exception
Walks a query tree with a traversal object. Both traversal.beforeNode and traversal.afterNode will be called for every Node object in the query tree. The traversal.beforeNode method will be called with a parent node before any of its children (pre-order), while traversal.afterNode method will be called on the parent after all of its children (post-order).

Throws:
java.lang.Exception

splitOn

public static java.util.ArrayList<java.lang.String> splitOn(java.lang.String text,
                                                            char delimiter)
Splits an input string, which may include escapes, into chunks based on a delimiter character. It does not split on delimiters that appear in escaped regions.


parseOperator

public static Node parseOperator(java.lang.String operator,
                                 int offset)

Parses an operator from the string query. This method assumes that operator is a pound sign ('#') followed by some text, followed by an open parentheses. Parsing stops at the parenthesis.

Note that parsing starts at index 0, not at "offset". The offset is used purely for giving parse error information, and represents the offset of the operator string in the larger query string.


findEscapedEnd

public static int findEscapedEnd(java.lang.String query,
                                 int start)
Find the end of an escaped query region. We assume that query.charAt(start) == '@'. The next charater is the boundary symbol for the escaped text. We move forward in the string until we see the boundary symbol again. If the escaped region isn't well formed (that is, there is no initial boundary symbol, or we only see the boundary symbol once), query.length() is returned.


findOperatorEnd

public static int findOperatorEnd(java.lang.String query,
                                  int start)

Find the end of an operator. We assume that query.charAt(start) is a pound sign. We skip forward in the query looking for the end of the operator by looking at parentheses; we know we're done when the parentheses are balanced and we've seen at least one open parenthesis. This method skips over escaped regions.


findTextEnd

public static int findTextEnd(java.lang.String query,
                              int start)

decodeEscapes

public static java.lang.String decodeEscapes(java.lang.String escapedString)

splitStringRespectingEscapes

public static java.util.ArrayList<java.lang.String> splitStringRespectingEscapes(java.lang.String query,
                                                                                 char split)

fieldOrNode

public static Node fieldOrNode(java.util.ArrayList<java.lang.String> fieldNames,
                               int offset)

parseTerm

public static Node parseTerm(java.lang.String query,
                             int offset)

findOperatorExpressionEnd

public static int findOperatorExpressionEnd(java.lang.String query,
                                            int offset)

parseArguments

public static java.util.ArrayList<Node> parseArguments(java.lang.String query,
                                                       int offset)
Parses arguments to an operator. This method can also be used to parse the elements of a query, since terms in a query are implicitly in a #combine operator.

Parameters:
query - The query, or a substring of it, that contains argument text.
offset - The offset into the full query string (offset == 0 if query is the full query).
Returns:
a List of Nodes, which represent the query.

parse

public static Node parse(java.lang.String query)

findQueryTerms

public static java.util.Set<java.lang.String> findQueryTerms(Node queryTree)


Copyright © 2009. All Rights Reserved.