Index: src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java =================================================================== --- src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java (revision 671951) +++ src/test/org/apache/lucene/search/TestMatchAllDocsQuery.java (working copy) @@ -37,6 +37,7 @@ public void testQuery() throws IOException { RAMDirectory dir = new RAMDirectory(); IndexWriter iw = new IndexWriter(dir, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED); + iw.setMaxBufferedDocs(2); // force multi-segment addDoc("one", iw); addDoc("two", iw); addDoc("three four", iw); Index: src/java/org/apache/lucene/search/MatchAllDocsQuery.java =================================================================== --- src/java/org/apache/lucene/search/MatchAllDocsQuery.java (revision 671951) +++ src/java/org/apache/lucene/search/MatchAllDocsQuery.java (working copy) @@ -18,6 +18,7 @@ */ import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.TermDocs; import org.apache.lucene.search.Explanation; import org.apache.lucene.search.Query; import org.apache.lucene.search.Scorer; @@ -27,6 +28,7 @@ import org.apache.lucene.util.ToStringUtils; import java.util.Set; +import java.io.IOException; /** * A query that matches all documents. @@ -39,17 +41,13 @@ } private class MatchAllScorer extends Scorer { - - final IndexReader reader; - int id; - final int maxId; + final TermDocs termDocs; final float score; - MatchAllScorer(IndexReader reader, Similarity similarity, Weight w) { + MatchAllScorer(IndexReader reader, Similarity similarity, Weight w) throws IOException + { super(similarity); - this.reader = reader; - id = -1; - maxId = reader.maxDoc() - 1; + this.termDocs = reader.termDocs(null); score = w.getValue(); } @@ -58,26 +56,19 @@ } public int doc() { - return id; + return termDocs.doc(); } - public boolean next() { - while (id < maxId) { - id++; - if (!reader.isDeleted(id)) { - return true; - } - } - return false; + public boolean next() throws IOException { + return termDocs.next(); } public float score() { return score; } - public boolean skipTo(int target) { - id = target - 1; - return next(); + public boolean skipTo(int target) throws IOException { + return termDocs.skipTo(target); } } @@ -113,7 +104,7 @@ queryWeight *= this.queryNorm; } - public Scorer scorer(IndexReader reader) { + public Scorer scorer(IndexReader reader) throws IOException { return new MatchAllScorer(reader, similarity, this); } Index: src/java/org/apache/lucene/index/FilterIndexReader.java =================================================================== --- src/java/org/apache/lucene/index/FilterIndexReader.java (revision 671951) +++ src/java/org/apache/lucene/index/FilterIndexReader.java (working copy) @@ -198,6 +198,11 @@ return in.termDocs(); } + public TermDocs termDocs(Term term) throws IOException { + ensureOpen(); + return in.termDocs(term); + } + public TermPositions termPositions() throws IOException { ensureOpen(); return in.termPositions(); Index: src/java/org/apache/lucene/index/ParallelReader.java =================================================================== --- src/java/org/apache/lucene/index/ParallelReader.java (revision 671951) +++ src/java/org/apache/lucene/index/ParallelReader.java (working copy) @@ -523,7 +523,12 @@ protected TermDocs termDocs; public ParallelTermDocs() {} - public ParallelTermDocs(Term term) throws IOException { seek(term); } + public ParallelTermDocs(Term term) throws IOException { + if (term == null) + termDocs = readers.isEmpty() ? null : ((IndexReader)readers.get(0)).termDocs(null); + else + seek(term); + } public int doc() { return termDocs.doc(); } public int freq() { return termDocs.freq(); } Index: src/java/org/apache/lucene/index/SegmentReader.java =================================================================== --- src/java/org/apache/lucene/index/SegmentReader.java (revision 671951) +++ src/java/org/apache/lucene/index/SegmentReader.java (working copy) @@ -674,6 +674,13 @@ return (deletedDocs != null && deletedDocs.get(n)); } + public TermDocs termDocs(Term term) throws IOException { + if (term == null) { + return new AllTermDocs(this); + } + return super.termDocs(term); + } + public TermDocs termDocs() throws IOException { ensureOpen(); return new SegmentTermDocs(this); Index: src/java/org/apache/lucene/index/MultiSegmentReader.java =================================================================== --- src/java/org/apache/lucene/index/MultiSegmentReader.java (revision 671951) +++ src/java/org/apache/lucene/index/MultiSegmentReader.java (working copy) @@ -526,7 +526,7 @@ readerTermDocs = new TermDocs[r.length]; } - + public int doc() { return base + current.doc(); } @@ -596,8 +596,6 @@ } private TermDocs termDocs(int i) throws IOException { - if (term == null) - return null; TermDocs result = readerTermDocs[i]; if (result == null) result = readerTermDocs[i] = termDocs(readers[i]); @@ -607,7 +605,7 @@ protected TermDocs termDocs(IndexReader reader) throws IOException { - return reader.termDocs(); + return term==null ? reader.termDocs(null) : reader.termDocs(); } public void close() throws IOException { Index: src/java/org/apache/lucene/index/AllTermDocs.java =================================================================== --- src/java/org/apache/lucene/index/AllTermDocs.java (revision 0) +++ src/java/org/apache/lucene/index/AllTermDocs.java (revision 0) @@ -0,0 +1,86 @@ +/** + * 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.lucene.index; + +import org.apache.lucene.util.BitVector; +import java.io.IOException; + + +class AllTermDocs implements TermDocs { + protected BitVector deletedDocs; + protected int maxDoc; + protected int doc = -1; + + protected AllTermDocs(SegmentReader parent) { + synchronized (parent) { + this.deletedDocs = parent.deletedDocs; + } + this.maxDoc = parent.maxDoc(); + } + + public void seek(Term term) throws IOException { + if (term==null) { + doc = -1; + } else { + throw new UnsupportedOperationException(); + } + } + + public void seek(TermEnum termEnum) throws IOException { + throw new UnsupportedOperationException(); + } + + public int doc() { + return doc; + } + + public int freq() { + return 1; + } + + public boolean next() throws IOException { + return skipTo(doc+1); + } + + public int read(int[] docs, int[] freqs) throws IOException { + final int length = docs.length; + int i = 0; + while (i < length && doc < maxDoc) { + if (deletedDocs == null || !deletedDocs.get(doc)) { + docs[i] = doc; + freqs[i] = 1; + ++i; + } + doc++; + } + return i; + } + + public boolean skipTo(int target) throws IOException { + doc = target; + while (doc < maxDoc) { + if (deletedDocs == null || !deletedDocs.get(doc)) + return true; + doc++; + } + return false; + } + + public void close() throws IOException { + } +} Property changes on: src/java/org/apache/lucene/index/AllTermDocs.java ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + Date Author Id Revision HeadURL Name: svn:eol-style + native Index: contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java =================================================================== --- contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java (revision 671951) +++ contrib/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java (working copy) @@ -842,10 +842,14 @@ public void seek(Term term) { if (DEBUG) System.err.println(".seek: " + term); - Info info = getInfo(term.field()); - current = info == null ? null : info.getPositions(term.text()); - hasNext = (current != null); - cursor = 0; + if (term == null) { + hasNext = true; // term==null means match all docs + } else { + Info info = getInfo(term.field()); + current = info == null ? null : info.getPositions(term.text()); + hasNext = (current != null); + cursor = 0; + } } public void seek(TermEnum termEnum) {