You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by cu...@apache.org on 2003/05/29 23:52:15 UTC
cvs commit: jakarta-lucene/src/java/org/apache/lucene/search BooleanQuery.java
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 {@link TermQuery}s or {@link PhraseQuery}s.
*/
public class BooleanQuery extends Query {
+ private static int maxClauseCount = 1024;
+
+ /** Thrown when an attempt is made to add more than {@link
+ * #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 {@link
+ * 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: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org