otis 2003/03/01 18:41:44 Modified: src/java/org/apache/lucene/queryParser QueryParser.jj Log: - Made a few private method protected, gave authors credit, moved all instance/class variables to the top, corrected grammar, made code style more uniform. Revision Changes Path 1.28 +70 -58 jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParser.jj Index: QueryParser.jj =================================================================== RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/queryParser/QueryParser.jj,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- QueryParser.jj 2 Mar 2003 01:36:38 -0000 1.27 +++ QueryParser.jj 2 Mar 2003 02:41:44 -0000 1.28 @@ -106,9 +106,37 @@ * </p> * * @author Brian Goetz + * @author Peter Halacsy + * @author Tatu Saloranta */ public class QueryParser { + + private static final int CONJ_NONE = 0; + private static final int CONJ_AND = 1; + private static final int CONJ_OR = 2; + + private static final int MOD_NONE = 0; + private static final int MOD_NOT = 10; + private static final int MOD_REQ = 11; + + public static final int DEFAULT_OPERATOR_OR = 0; + public static final int DEFAULT_OPERATOR_AND = 1; + + /** The actual operator that parser uses to combine query terms */ + private int operator = DEFAULT_OPERATOR_OR; + + /** + * Whether terms of wildcard and prefix queries are to be automatically + * lower-cased or not. Default is <code>true</code>. + */ + boolean lowercaseWildcardTerms = true; + + Analyzer analyzer; + String field; + int phraseSlop = 0; + + /** Parses a query string, returning a [EMAIL PROTECTED] org.apache.lucene.search.Query}. * @param query the query string to be parsed. * @param field the default field for query terms. @@ -126,15 +154,6 @@ } } - Analyzer analyzer; - String field; - int phraseSlop = 0; - /** - * Whether terms of wildcard and prefix queries are to be automatically - * lower-cased or not. Default is <code>true</code>. - */ - boolean lowercaseWildcardTerms = true; - /** Constructs a query parser. * @param field the default field for query terms. * @param analyzer used to find terms in the query text. @@ -156,17 +175,20 @@ return Query(field); } - /** Sets the default slop for phrases. If zero, then exact phrase matches - are required. Zero by default. */ - public void setPhraseSlop(int s) { phraseSlop = s; } - /** Gets the default slop for phrases. */ - public int getPhraseSlop() { return phraseSlop; } - - public static final int DEFAULT_OPERATOR_OR = 0; - public static final int DEFAULT_OPERATOR_AND = 1; + /** + * Sets the default slop for phrases. If zero, then exact phrase matches + * are required. Default value is zero. + */ + public void setPhraseSlop(int phraseSlop) { + this.phraseSlop = phraseSlop; + } - /** The actual operator that parser uses to combine query terms */ - private int operator = DEFAULT_OPERATOR_OR; + /** + * Gets the default slop for phrases. + */ + public int getPhraseSlop() { + return phraseSlop; + } /** * Sets the boolean operator of the QueryParser. @@ -181,18 +203,18 @@ } public int getOperator() { - return this.operator; + return operator; } - public void setLowercaseWildcardTerms(boolean b) { - owercaseWildcardTerms = b; + public void setLowercaseWildcardTerms(boolean lowercaseWildcardTerms) { + this.lowercaseWildcardTerms = lowercaseWildcardTerms; } public boolean getLowercaseWildcardTerms() { return lowercaseWildcardTerms; } - private void addClause(Vector clauses, int conj, int mods, Query q) { + protected void addClause(Vector clauses, int conj, int mods, Query q) { boolean required, prohibited; // If this term is introduced by AND, make the preceding term required, @@ -219,7 +241,6 @@ return; if (operator == DEFAULT_OPERATOR_OR) { - // THIS IS THE ORIGINAL CODE // We set REQUIRED if we're introduced by AND or +; PROHIBITED if // introduced by NOT or -; make sure not to set both. prohibited = (mods == MOD_NOT); @@ -228,7 +249,6 @@ required = true; } } else { - // THIS CODE ADDED BY PETER HALACSY // We set PROHIBITED if we're introduced by NOT or -; We set REQUIRED // if not PROHIBITED and not introduced by OR prohibited = (mods == MOD_NOT); @@ -237,9 +257,9 @@ clauses.addElement(new BooleanClause(q, required, prohibited)); } - private Query getFieldQuery(String field, - Analyzer analyzer, - String queryText) { + protected Query getFieldQuery(String field, + Analyzer analyzer, + String queryText) { // Use the analyzer to get all the tokens, and then build a TermQuery, // PhraseQuery, or nothing based on the term count @@ -273,11 +293,11 @@ } } - private Query getRangeQuery(String field, - Analyzer analyzer, - String part1, - String part2, - boolean inclusive) + protected Query getRangeQuery(String field, + Analyzer analyzer, + String part1, + String part2, + boolean inclusive) { boolean isDate = false, isNumber = false; @@ -302,7 +322,7 @@ } /** - * Factory method for generating query, given set of clauses. + * Factory method for generating query, given a set of clauses. * By default creates a boolean query composed of clauses passed in. * * Can be overridden by extending classes, to modify query being @@ -329,18 +349,18 @@ * that has just a single * character at the end) *<p> * Depending on settings, prefix term may be lower-cased - * automatically. It will not go through the default analyzer, - * however, since normal analyzers are unlikely to work properly + * automatically. It will not go through the default Analyzer, + * however, since normal Analyzers are unlikely to work properly * with wildcard templates. *<p> * Can be overridden by extending classes, to provide custom handling for - * wild card queries (which may be necessary due to missing analyzer calls) + * wildcard queries, which may be necessary due to missing analyzer calls. * * @param field Name of the field query will use. * @param termStr Term token that contains one or more wild card * characters (? or *), but is not simple prefix term * - * @return Resulting query build for the term + * @return Resulting [EMAIL PROTECTED] Query} built for the term */ protected Query getWildcardQuery(String field, String termStr) { @@ -353,25 +373,25 @@ /** * Factory method for generating a query (similar to - * (@link getWildcardQuery}). Called when parser parses an input term - * token that uses prefix notation; that is, contains a single '*' wild - * char character as it's last character. Since this is a special case - * of generic wild card term, and such a query can be optimized easily, - * this usually results in different query object. + * ([EMAIL PROTECTED] getWildcardQuery}). Called when parser parses an input term + * token that uses prefix notation; that is, contains a single '*' wildcard + * character as its last character. Since this is a special case + * of generic wildcard term, and such a query can be optimized easily, + * this usually results in a different query object. *<p> - * Depending on settings, prefix term may be lower-cased - * automatically. It will not go through the default analyzer, - * however, since normal analyzers are unlikely to work properly + * Depending on settings, a prefix term may be lower-cased + * automatically. It will not go through the default Analyzer, + * however, since normal Analyzers are unlikely to work properly * with wildcard templates. *<p> * Can be overridden by extending classes, to provide custom handling for - * wild card queries (which may be necessary due to missing analyzer calls) + * wild card queries, which may be necessary due to missing analyzer calls. * * @param field Name of the field query will use. * @param termStr Term token to use for building term for the query * (<b>without</b> trailing '*' character!) * - * @return Resulting query build for the term + * @return Resulting [EMAIL PROTECTED] Query} built for the term */ protected Query getPrefixQuery(String field, String termStr) { @@ -384,13 +404,13 @@ /** * Factory method for generating a query (similar to - * (@link getWildcardQuery}). Called when parser parses + * ([EMAIL PROTECTED] getWildcardQuery}). Called when parser parses * an input term token that has the fuzzy suffix (~) appended. * * @param field Name of the field query will use. * @param termStr Term token to use for building term for the query * - * @return Resulting query build for the term + * @return Resulting [EMAIL PROTECTED] Query} built for the term */ protected Query getFuzzyQuery(String field, String termStr) { @@ -404,14 +424,6 @@ Query q = qp.parse(args[0]); System.out.println(q.toString("field")); } - - private static final int CONJ_NONE = 0; - private static final int CONJ_AND = 1; - private static final int CONJ_OR = 2; - - private static final int MOD_NONE = 0; - private static final int MOD_NOT = 10; - private static final int MOD_REQ = 11; } PARSER_END(QueryParser)
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]