the-algorithm/src/java/com/twitter/search/common/query/SingleDocDocIdSetIterator.java
twitter-team ef4c5eb65e Twitter Recommendation Algorithm
Please note we have force-pushed a new initial commit in order to remove some publicly-available Twitter user information. Note that this process may be required in the future.
2023-03-31 17:36:31 -05:00

52 lines
886 B
Java

package com.twitter.search.common.query;
import java.io.IOException;
import org.apache.lucene.search.DocIdSetIterator;
public class SingleDocDocIdSetIterator extends DocIdSetIterator {
// the only docid in the list
private final int doc;
private int docid = -1;
public SingleDocDocIdSetIterator(int doc) {
this.doc = doc;
}
@Override
public int docID() {
return docid;
}
@Override
public int nextDoc() throws IOException {
if (docid == -1) {
docid = doc;
} else {
docid = NO_MORE_DOCS;
}
return docid;
}
@Override
public int advance(int target) throws IOException {
if (docid == NO_MORE_DOCS) {
return docid;
} else if (doc < target) {
docid = NO_MORE_DOCS;
return docid;
} else {
docid = doc;
}
return docid;
}
@Override
public long cost() {
return 1;
}
}