Index: src/main/java/org/apache/jackrabbit/core/query/lucene/NotQuery.java =================================================================== --- src/main/java/org/apache/jackrabbit/core/query/lucene/NotQuery.java (revision 1357245) +++ src/main/java/org/apache/jackrabbit/core/query/lucene/NotQuery.java (working copy) @@ -139,6 +139,12 @@ public Scorer scorer(IndexReader reader, boolean scoreDocsInOrder, boolean topScorer) throws IOException { contextScorer = context.weight(searcher).scorer(reader, scoreDocsInOrder, topScorer); + if (contextScorer == null) { + // context query does not match any node + // the inverse is to match all nodes + return new MatchAllDocsQuery().createWeight(searcher).scorer( + reader, scoreDocsInOrder, topScorer); + } return new NotQueryScorer(reader); } @@ -185,10 +191,6 @@ if (docNo == NO_MORE_DOCS) { return docNo; } - if (contextScorer == null) { - docNo = NO_MORE_DOCS; - return docNo; - } if (docNo == -1) { // get first doc of context scorer @@ -229,10 +231,6 @@ if (docNo == NO_MORE_DOCS) { return docNo; } - if (contextScorer == null) { - docNo = NO_MORE_DOCS; - return docNo; - } // optimize in the case of an advance to finish. // see https://issues.apache.org/jira/browse/JCR-3091 Index: src/test/java/org/apache/jackrabbit/core/query/ChildAxisQueryTest.java =================================================================== --- src/test/java/org/apache/jackrabbit/core/query/ChildAxisQueryTest.java (revision 1357245) +++ src/test/java/org/apache/jackrabbit/core/query/ChildAxisQueryTest.java (working copy) @@ -253,6 +253,6 @@ + testRootNode.getPath() + "') and not isdescendantnode(a,'" + foo.getPath() + "')"; - executeSQL2Query(sql, new Node[] {}); + executeSQL2Query(sql, new Node[] {foo}); } }