lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jim...@apache.org
Subject lucene-solr:master: LUCENE-8479: QueryBuilder#analyzeGraphPhrase now throws TooManyClause exception if the number of expanded path reaches the BooleanQuery#maxClause limit.
Date Thu, 04 Oct 2018 11:05:02 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master 793a677d0 -> 0f100004b


LUCENE-8479: QueryBuilder#analyzeGraphPhrase now throws TooManyClause exception if the number
of expanded path reaches the BooleanQuery#maxClause limit.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/0f100004
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/0f100004
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/0f100004

Branch: refs/heads/master
Commit: 0f100004bcd8ffc15cb5bd9281e1c9a61c17eb86
Parents: 793a677
Author: Jim Ferenczi <jimczi@apache.org>
Authored: Thu Oct 4 13:04:53 2018 +0200
Committer: Jim Ferenczi <jimczi@apache.org>
Committed: Thu Oct 4 13:04:53 2018 +0200

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  7 ++++-
 .../org/apache/lucene/util/QueryBuilder.java    | 10 +++++++
 .../apache/lucene/util/TestQueryBuilder.java    | 29 ++++++++++++++++++++
 3 files changed, 45 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0f100004/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 3f23c1e..ad83ff9 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -181,12 +181,17 @@ Optimizations
 
 ======================= Lucene 7.6.0 =======================
 
-Build
+Build:
 
 * LUCENE-8504: Upgrade forbiddenapis to version 2.6.  (Uwe Schindler)
 
 * LUCENE-8493: Stop publishing insecure .sha1 files with releases (janhoy)
 
+Bug fixes:
+
+* LUCENE-8479: QueryBuilder#analyzeGraphPhrase now throws TooManyClause exception
+  if the number of expanded path reaches the BooleanQuery#maxClause limit. (Jim Ferenczi)
+
 ======================= Lucene 7.5.1 =======================
 
 Bug Fixes:

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0f100004/lucene/core/src/java/org/apache/lucene/util/QueryBuilder.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/util/QueryBuilder.java b/lucene/core/src/java/org/apache/lucene/util/QueryBuilder.java
index 697e3bb..37b7e3e 100644
--- a/lucene/core/src/java/org/apache/lucene/util/QueryBuilder.java
+++ b/lucene/core/src/java/org/apache/lucene/util/QueryBuilder.java
@@ -552,6 +552,7 @@ public class QueryBuilder {
     List<SpanQuery> clauses = new ArrayList<>();
     int[] articulationPoints = graph.articulationPoints();
     int lastState = 0;
+    int maxClauseCount = BooleanQuery.getMaxClauseCount();
     for (int i = 0; i <= articulationPoints.length; i++) {
       int start = lastState;
       int end = -1;
@@ -567,6 +568,9 @@ public class QueryBuilder {
           TokenStream ts = it.next();
           SpanQuery q = createSpanQuery(ts, field);
           if (q != null) {
+            if (queries.size() >= maxClauseCount) {
+              throw new BooleanQuery.TooManyClauses();
+            }
             queries.add(q);
           }
         }
@@ -581,6 +585,9 @@ public class QueryBuilder {
         if (terms.length == 1) {
           queryPos = new SpanTermQuery(terms[0]);
         } else {
+          if (terms.length >= maxClauseCount) {
+            throw new BooleanQuery.TooManyClauses();
+          }
           SpanTermQuery[] orClauses = new SpanTermQuery[terms.length];
           for (int idx = 0; idx < terms.length; idx++) {
             orClauses[idx] = new SpanTermQuery(terms[idx]);
@@ -591,6 +598,9 @@ public class QueryBuilder {
       }
 
       if (queryPos != null) {
+        if (clauses.size() >= maxClauseCount) {
+          throw new BooleanQuery.TooManyClauses();
+        }
         clauses.add(queryPos);
       }
     }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0f100004/lucene/core/src/test/org/apache/lucene/util/TestQueryBuilder.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestQueryBuilder.java b/lucene/core/src/test/org/apache/lucene/util/TestQueryBuilder.java
index fece166..4af077b 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestQueryBuilder.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestQueryBuilder.java
@@ -18,8 +18,10 @@ package org.apache.lucene.util;
 
 
 import java.io.IOException;
+import java.io.Reader;
 
 import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.CannedBinaryTokenStream;
 import org.apache.lucene.analysis.MockAnalyzer;
 import org.apache.lucene.analysis.MockSynonymFilter;
 import org.apache.lucene.analysis.MockTokenizer;
@@ -443,4 +445,31 @@ public class TestQueryBuilder extends LuceneTestCase {
     QueryBuilder builder = new QueryBuilder(analyzer);
     assertNull(builder.createBooleanQuery("field", "whatever"));
   }
+
+  public void testMaxBooleanClause() throws Exception {
+    int size = 34;
+    CannedBinaryTokenStream.BinaryToken[] tokens = new CannedBinaryTokenStream.BinaryToken[size];
+    BytesRef term1 = new BytesRef("ff");
+    BytesRef term2 = new BytesRef("f");
+    for (int i = 0; i < size;) {
+      if (i % 2 == 0) {
+        tokens[i] = new CannedBinaryTokenStream.BinaryToken(term2, 1, 1);
+        tokens[i + 1] = new CannedBinaryTokenStream.BinaryToken(term1, 0, 2);
+        i += 2;
+      } else {
+        tokens[i] = new CannedBinaryTokenStream.BinaryToken(term2, 1, 1);
+        i ++;
+      }
+    }
+    QueryBuilder qb = new QueryBuilder(null);
+    try (TokenStream ts = new CannedBinaryTokenStream(tokens)) {
+      expectThrows(BooleanQuery.TooManyClauses.class, () -> qb.analyzeGraphBoolean("",
ts, BooleanClause.Occur.MUST));
+    }
+    try (TokenStream ts = new CannedBinaryTokenStream(tokens)) {
+      expectThrows(BooleanQuery.TooManyClauses.class, () -> qb.analyzeGraphBoolean("",
ts, BooleanClause.Occur.SHOULD));
+    }
+    try (TokenStream ts = new CannedBinaryTokenStream(tokens)) {
+      expectThrows(BooleanQuery.TooManyClauses.class, () -> qb.analyzeGraphPhrase(ts,
"", 0));
+    }
+  }
 }


Mime
View raw message