Index: src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java =================================================================== --- src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java (revision 538490) +++ src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java (working copy) @@ -426,30 +426,34 @@ if (relPath != null && (!node.getReferencesProperty() || relPath.getLength() > 1)) { // text search on some child axis Path.PathElement[] elements = relPath.getElements(); - for (int i = elements.length - 1; i >= 0; i--) { - String name = null; - if (!elements[i].getName().equals(RelationQueryNode.STAR_NAME_TEST)) { - name = NameFormat.format(elements[i].getName(), nsMappings);; - } - // join text search with name test - // if path references property that's elements.length - 2 - // if path references node that's elements.length - 1 - if (name != null - && ((node.getReferencesProperty() && i == elements.length - 2) - || (!node.getReferencesProperty() && i == elements.length - 1))) { - Query q = new TermQuery(new Term(FieldNames.LABEL, name)); - BooleanQuery and = new BooleanQuery(); - and.add(q, Occur.MUST); - and.add(context, Occur.MUST); - context = and; - } else if ((node.getReferencesProperty() && i < elements.length - 2) - || (!node.getReferencesProperty() && i < elements.length - 1)) { - // otherwise do a parent axis step - context = new ParentAxisQuery(context, name); + if (elements.length > 0 && elements[0].getName().equals(new QName(QName.NS_DEFAULT_URI, "DESCENDENT_OR_SELF"))) { + context = new ParentAxisQuery(context, null, true); + } else { + for (int i = elements.length - 1; i >= 0; i--) { + String name = null; + if (!elements[i].getName().equals(RelationQueryNode.STAR_NAME_TEST)) { + name = NameFormat.format(elements[i].getName(), nsMappings);; + } + // join text search with name test + // if path references property that's elements.length - 2 + // if path references node that's elements.length - 1 + if (name != null + && ((node.getReferencesProperty() && i == elements.length - 2) + || (!node.getReferencesProperty() && i == elements.length - 1))) { + Query q = new TermQuery(new Term(FieldNames.LABEL, name)); + BooleanQuery and = new BooleanQuery(); + and.add(q, Occur.MUST); + and.add(context, Occur.MUST); + context = and; + } else if ((node.getReferencesProperty() && i < elements.length - 2) + || (!node.getReferencesProperty() && i < elements.length - 1)) { + // otherwise do a parent axis step + context = new ParentAxisQuery(context, name); + } } + // finally select parent + context = new ParentAxisQuery(context, null); } - // finally select parent - context = new ParentAxisQuery(context, null); } return context; } catch (NamespaceException e) { Index: src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java =================================================================== --- src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java (revision 538490) +++ src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java (working copy) @@ -59,6 +59,8 @@ */ private Scorer contextScorer; + private final boolean includeAllParents; + /** * Creates a new ParentAxisQuery based on a * context query. @@ -68,8 +70,13 @@ * selected. */ ParentAxisQuery(Query context, String nameTest) { + this(context, nameTest, false); + } + + ParentAxisQuery(Query context, String nameTest, boolean includeAllParents) { this.contextQuery = context; this.nameTest = nameTest; + this.includeAllParents = includeAllParents; } /** @@ -97,7 +104,7 @@ if (cQuery == contextQuery) { return this; } else { - return new ParentAxisQuery(cQuery, nameTest); + return new ParentAxisQuery(cQuery, nameTest, includeAllParents); } } @@ -286,8 +293,11 @@ contextScorer.score(new HitCollector() { public void collect(int doc, float score) { try { + if (includeAllParents) { + hits.set(doc); + } doc = hResolver.getParent(doc); - if (doc != -1) { + while (doc != -1) { hits.set(doc); if (score != DEFAULT_SCORE.floatValue()) { scores.put(new Integer(doc), new Float(score)); @@ -292,6 +302,9 @@ if (score != DEFAULT_SCORE.floatValue()) { scores.put(new Integer(doc), new Float(score)); } + if (!includeAllParents) + break; + doc = hResolver.getParent(doc); } } catch (IOException e) { ex[0] = e;