jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1025644 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene: LuceneQueryFactory.java join/ChildNodeJoinMerger.java join/DescendantNodeJoinMerger.java join/JoinMerger.java join/SameNodeJoinMerger.java
Date Wed, 20 Oct 2010 16:55:27 GMT
Author: jukka
Date: Wed Oct 20 16:55:27 2010
New Revision: 1025644

URL: http://svn.apache.org/viewvc?rev=1025644&view=rev
Log:
JCR-2715: Improved join query performance

Implement also same, child and descendant node join conditions.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactory.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/ChildNodeJoinMerger.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/DescendantNodeJoinMerger.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinMerger.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SameNodeJoinMerger.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=1025644&r1=1025643&r2=1025644&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 20 16:55:27 2010
@@ -22,7 +22,6 @@ import static org.apache.jackrabbit.spi.
 import static org.apache.lucene.search.BooleanClause.Occur.SHOULD;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -33,22 +32,18 @@ import javax.jcr.nodetype.NodeTypeIterat
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.query.InvalidQueryException;
 import javax.jcr.query.qom.Literal;
-import javax.jcr.query.qom.Selector;
 import javax.jcr.query.qom.StaticOperand;
 
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.queryParser.ParseException;
 import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.Query;
 import org.apache.jackrabbit.core.HierarchyManager;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
-import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.query.qom.BindVariableValueImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.DefaultQOMTreeVisitor;
 import org.apache.jackrabbit.spi.commons.query.qom.JoinConditionImpl;
@@ -150,26 +145,9 @@ public class LuceneQueryFactory {
      * @throws RepositoryException if an error occurs while creating the query.
      */
     public Query create(SelectorImpl selector) throws RepositoryException {
-        return create(ntManager.getNodeType(selector.getNodeTypeName()));
-    }
-
-    private Term createNodeTypeTerm(NodeType type) throws RepositoryException {
-        String field;
-        if (type.isMixin()) {
-            // search for nodes where jcr:mixinTypes is set to this mixin
-            field = mixinTypesField;
-        } else {
-            // search for nodes where jcr:primaryType is set to this type
-            field = primaryTypeField;
-        }
-        String name = nsMappings.translateName(session.getQName(type.getName()));
-        return new Term(PROPERTIES, FieldNames.createNamedValue(field, name));
-    }
-
-    private Query create(NodeType type) throws RepositoryException {
         List<Term> terms = new ArrayList<Term>();
 
-        String name = type.getName();
+        String name = selector.getNodeTypeName();
         NodeTypeIterator allTypes = ntManager.getAllNodeTypes();
         while (allTypes.hasNext()) {
             NodeType nt = allTypes.nextNodeType();
@@ -189,6 +167,19 @@ public class LuceneQueryFactory {
         }
     }
 
+    private Term createNodeTypeTerm(NodeType type) throws RepositoryException {
+        String field;
+        if (type.isMixin()) {
+            // search for nodes where jcr:mixinTypes is set to this mixin
+            field = mixinTypesField;
+        } else {
+            // search for nodes where jcr:primaryType is set to this type
+            field = primaryTypeField;
+        }
+        String name = nsMappings.translateName(session.getQName(type.getName()));
+        return new Term(PROPERTIES, FieldNames.createNamedValue(field, name));
+    }
+
     /**
      * Creates a lucene query for the given QOM full text search.
      *

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/ChildNodeJoinMerger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/ChildNodeJoinMerger.java?rev=1025644&r1=1025643&r2=1025644&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/ChildNodeJoinMerger.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/ChildNodeJoinMerger.java
Wed Oct 20 16:55:27 2010
@@ -16,7 +16,9 @@
  */
 package org.apache.jackrabbit.core.query.lucene.join;
 
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -59,8 +61,20 @@ class ChildNodeJoinMerger extends JoinMe
     @Override
     public List<Constraint> getRightJoinConstraints(List<Row> leftRows)
             throws RepositoryException {
-        // TODO Auto-generated method stub
-        return Collections.emptyList();
+        Set<String> paths = new HashSet<String>();
+        for (Row row : leftRows) {
+            paths.addAll(getLeftValues(row));
+        }
+
+        List<Constraint> constraints = new ArrayList<Constraint>();
+        for (String path: paths) {
+            if (rightSelectors.contains(childSelector)) {
+                constraints.add(factory.childNode(childSelector, path));
+            } else {
+                constraints.add(factory.sameNode(parentSelector, path));
+            }
+        }
+        return constraints;
     }
 
     private Set<String> getValues(Set<String> selectors, Row row)

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/DescendantNodeJoinMerger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/DescendantNodeJoinMerger.java?rev=1025644&r1=1025643&r2=1025644&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/DescendantNodeJoinMerger.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/DescendantNodeJoinMerger.java
Wed Oct 20 16:55:27 2010
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.core.query.lucene.join;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -60,8 +61,21 @@ class DescendantNodeJoinMerger extends J
     @Override
     public List<Constraint> getRightJoinConstraints(List<Row> leftRows)
             throws RepositoryException {
-        // TODO Auto-generated method stub
-        return Collections.emptyList();
+        Set<String> paths = new HashSet<String>();
+        for (Row row : leftRows) {
+            paths.addAll(getLeftValues(row));
+        }
+
+        List<Constraint> constraints = new ArrayList<Constraint>();
+        for (String path : paths) {
+            if (rightSelectors.contains(descendantSelector)) {
+                constraints.add(
+                        factory.descendantNode(descendantSelector, path));
+            } else {
+                constraints.add(factory.sameNode(ancestorSelector, path));
+            }
+        }
+        return constraints;
     }
 
     private Set<String> getValues(Set<String> selectors, Row row)

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinMerger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinMerger.java?rev=1025644&r1=1025643&r2=1025644&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinMerger.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/JoinMerger.java
Wed Oct 20 16:55:27 2010
@@ -47,8 +47,28 @@ import javax.jcr.query.qom.Source;
 import org.apache.jackrabbit.commons.iterator.RowIterable;
 import org.apache.jackrabbit.commons.iterator.RowIteratorAdapter;
 
+/**
+ * A join merger is used by the {@link QueryEngine} class to efficiently
+ * merge together two parts of a join query.
+ * <p>
+ * Each join condition type ({@link EquiJoinCondition equi-} and
+ * {@link SameNodeJoinCondition same}, {@link ChildNodeJoinCondition child}
+ * or {@link DescendantJoinCondition descendant} node joins) has it's own
+ * merger class that extends the functionality of this abstract base class
+ * with functionality specific to that join condition.
+ */
 abstract class JoinMerger {
 
+    /**
+     * Static factory method for creating a merger for the given join.
+     *
+     * @param join join
+     * @param columns columns of the query
+     * @param evaluator operand evaluator
+     * @param factory QOM factory
+     * @return join merger
+     * @throws RepositoryException if the merger can not be created
+     */
     public static JoinMerger getJoinMerger(
             Join join, Map<String, PropertyValue> columns,
             OperandEvaluator evaluator, QueryObjectModelFactory factory)

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SameNodeJoinMerger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SameNodeJoinMerger.java?rev=1025644&r1=1025643&r2=1025644&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SameNodeJoinMerger.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/SameNodeJoinMerger.java
Wed Oct 20 16:55:27 2010
@@ -16,7 +16,9 @@
  */
 package org.apache.jackrabbit.core.query.lucene.join;
 
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -62,8 +64,20 @@ class SameNodeJoinMerger extends JoinMer
     @Override
     public List<Constraint> getRightJoinConstraints(List<Row> leftRows)
             throws RepositoryException {
-        // TODO Auto-generated method stub
-        return Collections.emptyList();
+        Set<String> paths = new HashSet<String>();
+        for (Row row : leftRows) {
+            paths.addAll(getLeftValues(row));
+        }
+
+        List<Constraint> constraints = new ArrayList<Constraint>();
+        for (String path : paths) {
+            if (rightSelectors.contains(selector1)) {
+                constraints.add(factory.sameNode(selector1, path));
+            } else {
+                constraints.add(factory.sameNode(selector2, path));
+            }
+        }
+        return constraints;
     }
 
     private Set<String> getValues(Set<String> selectors, Row row)



Mime
View raw message