lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mitchell Stevenson <mitchell.stevenson...@gmail.com>
Subject Implement an IndexSearcher which never returns any documents
Date Sat, 09 Sep 2017 17:40:30 GMT
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: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message