Add throws clause to query factory methods, allowing subclasses to use for rejecting, etc

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150070 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2003-09-30 04:38:36 +00:00
parent 99ffd3cf27
commit 15bcd46829
2 changed files with 38 additions and 18 deletions

View File

@ -93,8 +93,8 @@ public class QueryParser implements QueryParserConstants {
} }
/** Constructs a query parser. /** Constructs a query parser.
* @param field the default field for query terms. * @param f the default field for query terms.
* @param analyzer used to find terms in the query text. * @param a used to find terms in the query text.
*/ */
public QueryParser(String f, Analyzer a) { public QueryParser(String f, Analyzer a) {
this(new FastCharStream(new StringReader(""))); this(new FastCharStream(new StringReader("")));
@ -195,9 +195,12 @@ public class QueryParser implements QueryParserConstants {
clauses.addElement(new BooleanClause(q, required, prohibited)); clauses.addElement(new BooleanClause(q, required, prohibited));
} }
/**
* @exception ParseException throw in overridden method to disallow
*/
protected Query getFieldQuery(String field, protected Query getFieldQuery(String field,
Analyzer analyzer, Analyzer analyzer,
String queryText) { String queryText) throws ParseException {
// Use the analyzer to get all the tokens, and then build a TermQuery, // Use the analyzer to get all the tokens, and then build a TermQuery,
// PhraseQuery, or nothing based on the term count // PhraseQuery, or nothing based on the term count
@ -231,13 +234,16 @@ public class QueryParser implements QueryParserConstants {
} }
} }
/**
* @exception ParseException throw in overridden method to disallow
*/
protected Query getRangeQuery(String field, protected Query getRangeQuery(String field,
Analyzer analyzer, Analyzer analyzer,
String part1, String part1,
String part2, String part2,
boolean inclusive) boolean inclusive) throws ParseException
{ {
boolean isDate = false, isNumber = false; boolean isDate = false;
try { try {
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
@ -270,8 +276,9 @@ public class QueryParser implements QueryParserConstants {
* to join. * to join.
* *
* @return Resulting {@link Query} object. * @return Resulting {@link Query} object.
* @exception ParseException throw in overridden method to disallow
*/ */
protected Query getBooleanQuery(Vector clauses) protected Query getBooleanQuery(Vector clauses) throws ParseException
{ {
BooleanQuery query = new BooleanQuery(); BooleanQuery query = new BooleanQuery();
for (int i = 0; i < clauses.size(); i++) { for (int i = 0; i < clauses.size(); i++) {
@ -299,8 +306,9 @@ public class QueryParser implements QueryParserConstants {
* characters (? or *), but is not simple prefix term * characters (? or *), but is not simple prefix term
* *
* @return Resulting {@link Query} built for the term * @return Resulting {@link Query} built for the term
* @exception ParseException throw in overridden method to disallow
*/ */
protected Query getWildcardQuery(String field, String termStr) protected Query getWildcardQuery(String field, String termStr) throws ParseException
{ {
if (lowercaseWildcardTerms) { if (lowercaseWildcardTerms) {
termStr = termStr.toLowerCase(); termStr = termStr.toLowerCase();
@ -330,8 +338,9 @@ public class QueryParser implements QueryParserConstants {
* (<b>without</b> trailing '*' character!) * (<b>without</b> trailing '*' character!)
* *
* @return Resulting {@link Query} built for the term * @return Resulting {@link Query} built for the term
* @exception ParseException throw in overridden method to disallow
*/ */
protected Query getPrefixQuery(String field, String termStr) protected Query getPrefixQuery(String field, String termStr) throws ParseException
{ {
if (lowercaseWildcardTerms) { if (lowercaseWildcardTerms) {
termStr = termStr.toLowerCase(); termStr = termStr.toLowerCase();
@ -349,8 +358,9 @@ public class QueryParser implements QueryParserConstants {
* @param termStr Term token to use for building term for the query * @param termStr Term token to use for building term for the query
* *
* @return Resulting {@link Query} built for the term * @return Resulting {@link Query} built for the term
* @exception ParseException throw in overridden method to disallow
*/ */
protected Query getFuzzyQuery(String field, String termStr) protected Query getFuzzyQuery(String field, String termStr) throws ParseException
{ {
Term t = new Term(field, termStr); Term t = new Term(field, termStr);
return new FuzzyQuery(t); return new FuzzyQuery(t);

View File

@ -155,8 +155,8 @@ public class QueryParser {
} }
/** Constructs a query parser. /** Constructs a query parser.
* @param field the default field for query terms. * @param f the default field for query terms.
* @param analyzer used to find terms in the query text. * @param a used to find terms in the query text.
*/ */
public QueryParser(String f, Analyzer a) { public QueryParser(String f, Analyzer a) {
this(new FastCharStream(new StringReader(""))); this(new FastCharStream(new StringReader("")));
@ -257,9 +257,12 @@ public class QueryParser {
clauses.addElement(new BooleanClause(q, required, prohibited)); clauses.addElement(new BooleanClause(q, required, prohibited));
} }
/**
* @exception ParseException throw in overridden method to disallow
*/
protected Query getFieldQuery(String field, protected Query getFieldQuery(String field,
Analyzer analyzer, Analyzer analyzer,
String queryText) { String queryText) throws ParseException {
// Use the analyzer to get all the tokens, and then build a TermQuery, // Use the analyzer to get all the tokens, and then build a TermQuery,
// PhraseQuery, or nothing based on the term count // PhraseQuery, or nothing based on the term count
@ -293,13 +296,16 @@ public class QueryParser {
} }
} }
/**
* @exception ParseException throw in overridden method to disallow
*/
protected Query getRangeQuery(String field, protected Query getRangeQuery(String field,
Analyzer analyzer, Analyzer analyzer,
String part1, String part1,
String part2, String part2,
boolean inclusive) boolean inclusive) throws ParseException
{ {
boolean isDate = false, isNumber = false; boolean isDate = false;
try { try {
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
@ -332,8 +338,9 @@ public class QueryParser {
* to join. * to join.
* *
* @return Resulting {@link Query} object. * @return Resulting {@link Query} object.
* @exception ParseException throw in overridden method to disallow
*/ */
protected Query getBooleanQuery(Vector clauses) protected Query getBooleanQuery(Vector clauses) throws ParseException
{ {
BooleanQuery query = new BooleanQuery(); BooleanQuery query = new BooleanQuery();
for (int i = 0; i < clauses.size(); i++) { for (int i = 0; i < clauses.size(); i++) {
@ -361,8 +368,9 @@ public class QueryParser {
* characters (? or *), but is not simple prefix term * characters (? or *), but is not simple prefix term
* *
* @return Resulting {@link Query} built for the term * @return Resulting {@link Query} built for the term
* @exception ParseException throw in overridden method to disallow
*/ */
protected Query getWildcardQuery(String field, String termStr) protected Query getWildcardQuery(String field, String termStr) throws ParseException
{ {
if (lowercaseWildcardTerms) { if (lowercaseWildcardTerms) {
termStr = termStr.toLowerCase(); termStr = termStr.toLowerCase();
@ -392,8 +400,9 @@ public class QueryParser {
* (<b>without</b> trailing '*' character!) * (<b>without</b> trailing '*' character!)
* *
* @return Resulting {@link Query} built for the term * @return Resulting {@link Query} built for the term
* @exception ParseException throw in overridden method to disallow
*/ */
protected Query getPrefixQuery(String field, String termStr) protected Query getPrefixQuery(String field, String termStr) throws ParseException
{ {
if (lowercaseWildcardTerms) { if (lowercaseWildcardTerms) {
termStr = termStr.toLowerCase(); termStr = termStr.toLowerCase();
@ -411,8 +420,9 @@ public class QueryParser {
* @param termStr Term token to use for building term for the query * @param termStr Term token to use for building term for the query
* *
* @return Resulting {@link Query} built for the term * @return Resulting {@link Query} built for the term
* @exception ParseException throw in overridden method to disallow
*/ */
protected Query getFuzzyQuery(String field, String termStr) protected Query getFuzzyQuery(String field, String termStr) throws ParseException
{ {
Term t = new Term(field, termStr); Term t = new Term(field, termStr);
return new FuzzyQuery(t); return new FuzzyQuery(t);