cutting 2003/05/29 14:52:15 Modified: src/java/org/apache/lucene/search BooleanQuery.java Log: Added a limit to the number of clauses which may be added to a BooleanQuery. The default limit is 1024 clauses. This should stop most OutOfMemoryExceptions by prefix, wildcard and fuzzy queries which run amok. Revision Changes Path 1.15 +25 -2 jakarta-lucene/src/java/org/apache/lucene/search/BooleanQuery.java Index: BooleanQuery.java =================================================================== RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/search/BooleanQuery.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- BooleanQuery.java 7 Feb 2003 18:45:15 -0000 1.14 +++ BooleanQuery.java 29 May 2003 21:52:15 -0000 1.15 @@ -62,6 +62,22 @@ queries, typically [EMAIL PROTECTED] TermQuery}s or [EMAIL PROTECTED] PhraseQuery}s. */ public class BooleanQuery extends Query { + private static int maxClauseCount = 1024; + + /** Thrown when an attempt is made to add more than [EMAIL PROTECTED] + * #getMaxClauseCount()} clauses. */ + public static class TooManyClauses extends RuntimeException {} + + /** Return the maximum number of clauses permitted, 1024 by default. + * Attempts to add more than the permitted number of clauses cause [EMAIL PROTECTED] + * TooManyClauses} to be thrown.*/ + public static int getMaxClauseCount() { return maxClauseCount; } + + /** Set the maximum number of clauses permitted. */ + public static void setMaxClauseCount(int maxClauseCount) { + BooleanQuery.maxClauseCount = maxClauseCount; + } + private Vector clauses = new Vector(); /** Constructs an empty boolean query. */ @@ -78,13 +94,20 @@ </ul> It is an error to specify a clause as both <code>required</code> and <code>prohibited</code>. + * + * @see #getMaxClauseCount() */ public void add(Query query, boolean required, boolean prohibited) { - clauses.addElement(new BooleanClause(query, required, prohibited)); + add(new BooleanClause(query, required, prohibited)); } - /** Adds a clause to a boolean query. */ + /** Adds a clause to a boolean query. + * @see #getMaxClauseCount() + */ public void add(BooleanClause clause) { + if (clauses.size() >= maxClauseCount) + throw new TooManyClauses(); + clauses.addElement(clause); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]