jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r380766 - /incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
Date Fri, 24 Feb 2006 18:22:44 GMT
Author: mreutegg
Date: Fri Feb 24 10:22:42 2006
New Revision: 380766

URL: http://svn.apache.org/viewcvs?rev=380766&view=rev
Log:
JCR-327: Mixins as supertypes do not appear to be queryable
- query builder did not take primary types into account that have mixin type in question as
supertype.

Modified:
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java?rev=380766&r1=380765&r2=380766&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
Fri Feb 24 10:22:42 2006
@@ -78,16 +78,6 @@
     private static final Logger log = Logger.getLogger(LuceneQueryBuilder.class);
 
     /**
-     * QName for jcr:primaryType
-     */
-    private static QName primaryType = QName.JCR_PRIMARYTYPE;
-
-    /**
-     * QName for jcr:mixinTypes
-     */
-    private static QName mixinTypes = QName.JCR_MIXINTYPES;
-
-    /**
      * Root node of the abstract query tree
      */
     private QueryRootNode root;
@@ -254,24 +244,44 @@
     }
 
     public Object visit(NodeTypeQueryNode node, Object data) {
-        String field = "";
-        List values = new ArrayList();
+
+        List terms = new ArrayList();
         try {
-            values.add(node.getValue().toJCRName(nsMappings));
+            String mixinTypesField = QName.JCR_MIXINTYPES.toJCRName(nsMappings);
+            String primaryTypeField = QName.JCR_PRIMARYTYPE.toJCRName(nsMappings);
+
             NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
             NodeType base = ntMgr.getNodeType(node.getValue().toJCRName(session.getNamespaceResolver()));
+
             if (base.isMixin()) {
-                field = mixinTypes.toJCRName(nsMappings);
+                // search for nodes where jcr:mixinTypes is set to this mixin
+                Term t = new Term(FieldNames.PROPERTIES,
+                        FieldNames.createNamedValue(mixinTypesField,
+                                node.getValue().toJCRName(nsMappings)));
+                terms.add(t);
             } else {
-                field = primaryType.toJCRName(nsMappings);
+                // search for nodes where jcr:primaryType is set to this type
+                Term t = new Term(FieldNames.PROPERTIES,
+                        FieldNames.createNamedValue(primaryTypeField,
+                                node.getValue().toJCRName(nsMappings)));
+                terms.add(t);
             }
+
+            // now search for all node types that are derived from base
             NodeTypeIterator allTypes = ntMgr.getAllNodeTypes();
             while (allTypes.hasNext()) {
                 NodeType nt = allTypes.nextNodeType();
+                // only interested in types that can be used to create nodes
+                if (nt.isMixin()) {
+                    continue;
+                }
                 NodeType[] superTypes = nt.getSupertypes();
                 if (Arrays.asList(superTypes).contains(base)) {
-                    values.add(nsMappings.translatePropertyName(nt.getName(),
-                            session.getNamespaceResolver()));
+                    String ntName = nsMappings.translatePropertyName(nt.getName(),
+                            session.getNamespaceResolver());
+                    Term t = new Term(FieldNames.PROPERTIES,
+                            FieldNames.createNamedValue(primaryTypeField, ntName));
+                    terms.add(t);
                 }
             }
         } catch (IllegalNameException e) {
@@ -284,19 +294,15 @@
         } catch (RepositoryException e) {
             exceptions.add(e);
         }
-        if (values.size() == 0) {
+        if (terms.size() == 0) {
             // exception occured
             return new BooleanQuery();
-        } else if (values.size() == 1) {
-            Term t = new Term(FieldNames.PROPERTIES,
-                    FieldNames.createNamedValue(field, (String) values.get(0)));
-            return new TermQuery(t);
+        } else if (terms.size() == 1) {
+            return new TermQuery((Term) terms.get(0));
         } else {
             BooleanQuery b = new BooleanQuery();
-            for (Iterator it = values.iterator(); it.hasNext();) {
-                Term t = new Term(FieldNames.PROPERTIES,
-                        FieldNames.createNamedValue(field, (String) it.next()));
-                b.add(new TermQuery(t), false, false);
+            for (Iterator it = terms.iterator(); it.hasNext();) {
+                b.add(new TermQuery((Term) it.next()), false, false);
             }
             return b;
         }
@@ -466,7 +472,7 @@
                     // todo this will traverse the whole index, optimize!
                     Query subQuery = null;
                     try {
-                        subQuery = new MatchAllQuery(primaryType.toJCRName(nsMappings));
+                        subQuery = new MatchAllQuery(QName.JCR_PRIMARYTYPE.toJCRName(nsMappings));
                     } catch (NoPrefixDeclaredException e) {
                         // will never happen, prefixes are created when unknown
                     }



Mime
View raw message