1 package org.apache.lucene.store.instantiated;
4 * Copyright 2006 The Apache Software Foundation
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.lucene.index.Term;
20 import org.apache.lucene.index.TermDocs;
23 * A {@link org.apache.lucene.index.TermDocs} navigating an {@link InstantiatedIndexReader}.
25 public class InstantiatedTermDocs
28 private final InstantiatedIndexReader reader;
30 public InstantiatedTermDocs(InstantiatedIndexReader reader) {
34 private int currentDocumentIndex;
35 protected InstantiatedTermDocumentInformation currentDocumentInformation;
36 protected InstantiatedTerm currentTerm;
39 public void seek(Term term) {
40 currentTerm = reader.getIndex().findTerm(term);
41 currentDocumentIndex = -1;
44 public void seek(org.apache.lucene.index.TermEnum termEnum) {
45 seek(termEnum.term());
50 return currentDocumentInformation.getDocument().getDocumentNumber();
54 return currentDocumentInformation.getTermPositions().length;
58 public boolean next() {
59 if (currentTerm != null) {
60 currentDocumentIndex++;
61 if (currentDocumentIndex < currentTerm.getAssociatedDocuments().length) {
62 currentDocumentInformation = currentTerm.getAssociatedDocuments()[currentDocumentIndex];
63 if (reader.isDeleted(currentDocumentInformation.getDocument().getDocumentNumber())) {
69 // mimic SegmentTermDocs
70 currentDocumentIndex = currentTerm.getAssociatedDocuments().length -1;
77 public int read(int[] docs, int[] freqs) {
79 for (i = 0; i < docs.length; i++) {
90 * Skips entries to the first beyond the current whose document number is
91 * greater than or equal to <i>target</i>. <p>Returns true if there is such
92 * an entry. <p>Behaves as if written: <pre>
93 * boolean skipTo(int target) {
97 * } while (target > doc());
101 * This implementation is considerably more efficient than that.
104 public boolean skipTo(int target) {
105 if (currentTerm == null) {
109 if (currentDocumentIndex >= target) {
113 int startOffset = currentDocumentIndex >= 0 ? currentDocumentIndex : 0;
114 int pos = currentTerm.seekCeilingDocumentInformationIndex(target, startOffset);
117 // mimic SegmentTermDocs that positions at the last index
118 currentDocumentIndex = currentTerm.getAssociatedDocuments().length -1;
122 currentDocumentInformation = currentTerm.getAssociatedDocuments()[pos];
123 currentDocumentIndex = pos;
124 if (reader.hasDeletions() && reader.isDeleted(currentDocumentInformation.getDocument().getDocumentNumber())) {
134 public void close() {