You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Mitchell Stevenson <mi...@gmail.com> on 2017/09/09 17:40:30 UTC

Implement an IndexSearcher which never returns any documents

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


Re: Implement an IndexSearcher which never returns any documents

Posted by Mitchell Stevenson <mi...@gmail.com>.
thx, great solution

2017-09-11 17:55 GMT+02:00 Adrien Grand <jp...@gmail.com>:
> You could create a `new IndexSearcher(new MultiReader());`
>
> Le sam. 9 sept. 2017 à 19:40, Mitchell Stevenson <
> mitchell.stevenson986@gmail.com> a écrit :
>
>> 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
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Implement an IndexSearcher which never returns any documents

Posted by Adrien Grand <jp...@gmail.com>.
You could create a `new IndexSearcher(new MultiReader());`

Le sam. 9 sept. 2017 à 19:40, Mitchell Stevenson <
mitchell.stevenson986@gmail.com> a écrit :

> 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
>
>