jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1182281 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java test/java/org/apache/jackrabbit/core/query/SQL2TooManyClausesTest.java
Date Wed, 12 Oct 2011 09:28:08 GMT
Author: alexparvulescu
Date: Wed Oct 12 09:28:08 2011
New Revision: 1182281

URL: http://svn.apache.org/viewvc?rev=1182281&view=rev
Log:
JCR-3108 SQL2 ISDESCENDANTNODE can throw BooleanQuery#TooManyClauses if there are too many
matching child nodes

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2TooManyClausesTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java?rev=1182281&r1=1182280&r2=1182281&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java
Wed Oct 12 09:28:08 2011
@@ -451,6 +451,7 @@ public class LuceneQueryFactory {
             DescendantNode dn, JackrabbitIndexSearcher searcher)
             throws RepositoryException, IOException {
         BooleanQuery query = new BooleanQuery();
+        int clauses = 0;
 
         try {
             LinkedList<String> ids = new LinkedList<String>();
@@ -458,10 +459,19 @@ public class LuceneQueryFactory {
             ids.add(ancestor.getIdentifier());
             while (!ids.isEmpty()) {
                 String id = ids.removeFirst();
+                clauses++;
                 Query q = new JackrabbitTermQuery(new Term(FieldNames.PARENT, id));
                 QueryHits hits = searcher.evaluate(q);
                 ScoreNode sn = hits.nextScoreNode();
                 if (sn != null) {
+                    // reset query so it does not overflow because of the max
+                    // clause count condition,
+                    // see JCR-3108
+                    if (clauses == BooleanQuery.getMaxClauseCount()) {
+                        BooleanQuery wrapQ = new BooleanQuery();
+                        wrapQ.add(query, SHOULD);
+                        query = wrapQ;
+                    }
                     query.add(q, SHOULD);
                     do {
                         ids.add(sn.getNodeId().toString());

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2TooManyClausesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2TooManyClausesTest.java?rev=1182281&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2TooManyClausesTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2TooManyClausesTest.java
Wed Oct 12 09:28:08 2011
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.query;
+
+import static javax.jcr.query.Query.JCR_SQL2;
+
+import javax.jcr.Node;
+
+/**
+ * test for the usecases where there could be more than 1024 boolean clauses on
+ * a query and the QueryEngine (usually) has to implement some sort of batching
+ * 
+ * @see {@link org.apache.lucene.search.BooleanQuery$TooManyClauses
+ *      BooleanQuery#TooManyClauses}
+ */
+public class SQL2TooManyClausesTest extends AbstractQueryTest {
+
+    private Node a;
+
+    private Node boys;
+
+    private Node girls;
+
+    private final int nodes = 1100;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        a = testRootNode.addNode("teacher", "nt:unstructured");
+        boys = a.addNode("boys", "nt:unstructured");
+        girls = a.addNode("girls", "nt:unstructured");
+
+        for (int i = 0; i < nodes; i++) {
+            if (i % 2 == 0) {
+                Node n = getOrCreateParent(boys, i).addNode("student" + i,
+                        "nt:unstructured");
+                n.setProperty("sex", "m");
+            } else {
+                Node n = getOrCreateParent(girls, i).addNode("student" + i,
+                        "nt:unstructured");
+                n.setProperty("sex", "f");
+            }
+            if (i % 100 == 0) {
+                superuser.save();
+            }
+        }
+        superuser.save();
+    }
+
+    private Node getOrCreateParent(Node node, int index) throws Exception {
+        String indexAsString = index + "";
+        int len = indexAsString.length();
+        Node n = node;
+        for (int i = 0; i < 3; i++) {
+            String name = "0";
+            if (i < len) {
+                name = indexAsString.charAt(i) + "";
+            }
+            n = n.addNode(name);
+        }
+        return n;
+    }
+
+    /**
+     * JCR-3108
+     */
+    public void testISDESCENDANTNODE() throws Exception {
+        StringBuilder join = new StringBuilder();
+        join.append("SELECT * FROM [nt:unstructured] as students WHERE ");
+        join.append(" (ISDESCENDANTNODE([" + boys.getPath()
+                + "]) OR ISDESCENDANTNODE([" + girls.getPath() + "])) ");
+        join.append(" AND ( CONTAINS(students.sex,'m') OR CONTAINS(students.sex,'f') )");
+        checkResult(qm.createQuery(join.toString(), JCR_SQL2).execute(), nodes);
+
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/SQL2TooManyClausesTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message