it.unimi.dsi.mg4j.query.parser
Class QueryParser

java.lang.Object
  extended byit.unimi.dsi.mg4j.query.parser.QueryParser
All Implemented Interfaces:
QueryParserConstants

public class QueryParser
extends Object
implements QueryParserConstants

This class is used to parse queries. You are supposed to create a query parser by giving a map that maps index names (called index aliases) to indices (instances of the Index class), and the name of the default index alias to be used. After that, you parse a query by using the parse(String) method.

Since:
0.9
Author:
Paolo Boldi, Sebastiano Vigna

Field Summary
 Token jj_nt
           
 boolean lookingAhead
           
 Token token
           
 QueryParserTokenManager token_source
           
 
Fields inherited from interface it.unimi.dsi.mg4j.query.parser.QueryParserConstants
AND, CLOSE_PAREN, COLON, DEFAULT, EOF, NOT, OPEN_PAREN, OR, QUOTE, SHARP, TILDA, tokenImage, WORD
 
Constructor Summary
QueryParser(Index index)
          Creates a query parser for a single index.
QueryParser(InputStream stream)
           
QueryParser(Map indexMap, String defaultIndex)
          Creates a query parser.
QueryParser(QueryParserTokenManager tm)
           
QueryParser(Reader stream)
           
 
Method Summary
 DocumentIterator andQuery(String indexAlias, boolean dontChange)
          Starting rule for an AND-query (the AND token is optional).
 DocumentIterator atomicQuery(String indexAlias, boolean dontChange)
          Starting rule for an atomic query.
 DocumentIterator atomicSimpleQuery(String indexAlias, boolean dontChange)
          Starting rule for an atomic simple query.
 void disable_tracing()
           
 void enable_tracing()
           
 ParseException generateParseException()
           
 Token getNextToken()
           
 Token getToken(int index)
           
 DocumentIterator parse(String query)
          Parses the given query, returning the corresponding query result.
 DocumentIterator query(String indexAlias, boolean dontChange)
          Starting rule for a OR-query.
 DocumentIterator quotedQuery(String indexAlias, boolean dontChange)
          Starting rule for a quoted query.
 void ReInit(InputStream stream)
           
 void ReInit(QueryParserTokenManager tm)
           
 void ReInit(Reader stream)
           
 DocumentIterator start(String indexAlias, boolean dontChange)
          Starting rule for a query.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

token_source

public QueryParserTokenManager token_source

token

public Token token

jj_nt

public Token jj_nt

lookingAhead

public boolean lookingAhead
Constructor Detail

QueryParser

public QueryParser(Map indexMap,
                   String defaultIndex)
Creates a query parser.

Parameters:
indexMap - a map from strings (index alias) to Index objects.
defaultIndex - the default index alias to be used when parsing the query.

QueryParser

public QueryParser(Index index)
Creates a query parser for a single index.

Parsers created by this constructor allow only nameless access, both in the query and in the interval-iterator methods.

Parameters:
index - the only index for the queries.

QueryParser

public QueryParser(InputStream stream)

QueryParser

public QueryParser(Reader stream)

QueryParser

public QueryParser(QueryParserTokenManager tm)
Method Detail

parse

public DocumentIterator parse(String query)
                       throws ParseException,
                              TokenMgrError,
                              IOException
Parses the given query, returning the corresponding query result.

Parameters:
query - the query to be parsed.
Returns:
the query result.
Throws:
ParseException - if a parse exception has taken place during query parsing.
TokenMgrError - if a tokenization exception has taken place during query parsing.
IOException - if a low-level I/O exception was thrown while trying to read some index.

start

public final DocumentIterator start(String indexAlias,
                                    boolean dontChange)
                             throws ParseException
Starting rule for a query.

Parameters:
indexAlias - the index alias for the default index to be used for the query that is going to be parsed.
dontChange - if true, the query cannot contain index selectors other than indexAlias.
Returns:
the result of the query.
Throws:
ParseException

query

public final DocumentIterator query(String indexAlias,
                                    boolean dontChange)
                             throws ParseException
Starting rule for a OR-query.

Parameters:
indexAlias - the index alias for the default index to be used for the query that is going to be parsed.
dontChange - if true, the query cannot contain index selectors other than indexAlias.
Returns:
the result of the query.
Throws:
ParseException

andQuery

public final DocumentIterator andQuery(String indexAlias,
                                       boolean dontChange)
                                throws ParseException
Starting rule for an AND-query (the AND token is optional).

Parameters:
indexAlias - the index alias for the default index to be used for the query that is going to be parsed.
dontChange - if true, the query cannot contain index selectors other than indexAlias.
Returns:
the result of the query.
Throws:
ParseException

quotedQuery

public final DocumentIterator quotedQuery(String indexAlias,
                                          boolean dontChange)
                                   throws ParseException
Starting rule for a quoted query. Subqueries cannot change index.

Parameters:
indexAlias - the index alias for the default index to be used for the query that is going to be parsed.
dontChange - if true, the query cannot contain index selectors other than indexAlias.
Returns:
the result of the query.
Throws:
ParseException

atomicQuery

public final DocumentIterator atomicQuery(String indexAlias,
                                          boolean dontChange)
                                   throws ParseException
Starting rule for an atomic query. May be either an atomic simple query or a quoted query. It can optionally contain an index selector and a low-pass limit.

Parameters:
indexAlias - the index alias for the default index to be used for the query that is going to be parsed.
dontChange - if true, the query cannot contain index selectors other than indexAlias.
Returns:
the result of the query.
Throws:
ParseException

atomicSimpleQuery

public final DocumentIterator atomicSimpleQuery(String indexAlias,
                                                boolean dontChange)
                                         throws ParseException
Starting rule for an atomic simple query. May be either a word or a query enclosed within parentheses.

Parameters:
indexAlias - the index alias for the default index to be used for the query that is going to be parsed.
dontChange - if true, the query cannot contain index selectors other than indexAlias.
Returns:
the result of the query.
Throws:
ParseException

ReInit

public void ReInit(InputStream stream)

ReInit

public void ReInit(Reader stream)

ReInit

public void ReInit(QueryParserTokenManager tm)

getNextToken

public final Token getNextToken()

getToken

public final Token getToken(int index)

generateParseException

public ParseException generateParseException()

enable_tracing

public final void enable_tracing()

disable_tracing

public final void disable_tracing()