class QueryParser {
/** Parses a query string, returning a {@link org.apache.lucene.search.Query}.
* @param query the query string to be parsed.
* @throws ParseException if the parsing fails
*/
public Query parse(String query) throws ParseException {
ReInit(new FastCharStream(new StringReader(query)));
try {
// TopLevelQuery is a Query followed by the end-of-input (EOF)
Query res = TopLevelQuery(field);
return res!=null ? res : new BooleanQuery();
}
catch (ParseException tme) {
// rethrow to include the original query:
throw new ParseException("Cannot parse '" +query+ "': " + tme.getMessage());
}
catch (TokenMgrError tme) {
throw new ParseException("Cannot parse '" +query+ "': " + tme.getMessage());
}
catch (BooleanQuery.TooManyClauses tmc) {
throw new ParseException("Cannot parse '" +query+ "': too many boolean clauses");
}
}
}