I need to implement an IndexSearcher for Lucene 7 which never returns
any documents.
Is the following implementation suitable for this? The code seems to
work nicely but i am not sure about it.
IndexSearcher noDocsSearcher = new IndexSearcher(new NoDocsReader());
public class NoDocsReader extends LeafReader {
private final static Bits liveDocs = new Bits.MatchNoBits(0);
public NoDocsReader() {
tryIncRef(); //keep reader open
}
@Override
public NumericDocValues getNumericDocValues(final String field)
throws IOException {
return new NumericDocValues() {
@Override
public long longValue() throws IOException {
return 0;
}
@Override
public boolean advanceExact(int target) throws IOException {
return false;
}
@Override
public int docID() {
return 0;
}
@Override
public int nextDoc() throws IOException {
return 0;
}
@Override
public int advance(int target) throws IOException {
return 0;
}
@Override
public long cost() {
return 0;
}
};
}
@Override
public BinaryDocValues getBinaryDocValues(final String field)
throws IOException {
return null;
}
@Override
public SortedDocValues getSortedDocValues(final String field)
throws IOException {
return null;
}
@Override
public SortedNumericDocValues getSortedNumericDocValues(final
String field) throws IOException {
return null;
}
@Override
public SortedSetDocValues getSortedSetDocValues(final String
field) throws IOException {
return null;
}
@Override
public NumericDocValues getNormValues(final String field) throws
IOException {
return null;
}
@Override
public FieldInfos getFieldInfos() {
return new FieldInfos(new FieldInfo[0]);
}
@Override
public Bits getLiveDocs() {
return liveDocs;
}
@Override
public void checkIntegrity() throws IOException {
}
@Override
public Fields getTermVectors(final int docID) throws IOException {
return null;
}
@Override
public int numDocs() {
return 0;
}
@Override
public int maxDoc() {
return 0;
}
@Override
public void document(final int docID, final StoredFieldVisitor
visitor) throws IOException {
}
@Override
protected void doClose() throws IOException {
}
@Override
public boolean hasDeletions() {
return false;
}
@Override
public CacheHelper getCoreCacheHelper() {
return null;
}
@Override
public Terms terms(String field) throws IOException {
return null;
}
@Override
public PointValues getPointValues(String field) throws IOException {
return null;
}
@Override
public LeafMetaData getMetaData() {
return null;
}
@Override
public CacheHelper getReaderCacheHelper() {
return null;
}
}
Thanks
Mitch
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]