lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruce Ritchie <>
Subject Re: RE : DateFilter.Before/After
Date Mon, 15 Sep 2003 13:45:56 GMT

Erik Hatcher wrote:

> Also, regarding DateFilter.... would it be reasonable to apply the same 
> bitset caching that QueryFilter uses?
> what about a CachingFilterWrapper implementation that implements Filter 
> and the QueryFilter-like caching, and passes through to another filter 
> for the actual gathering of the bitset?

I would suggest *not* using caching inside of filters provided by lucene but rather provide
wrapper to do the caching. The reason is that some applications really don't want the libraries
use to be a source of concern for memory usage. i.e. if I search for a string using 10,000
date filters (an extreme example, but possible) I want the ability to control how those bitsets
going to be cached. Yes, I realize that a weakhashmap can and is used by the QueryFilter however
think it's best if the client application does the caching as only it is best suited to know
should and should not be cached. It's dead simple for the client app to just do the lookup
of the 
filter against a key in the hashmap.

I use the following - it's simple and effective.

public class CachedFilter extends Filter {
     BitSet bits;
     Filter filter;

     public CachedFilter(Filter filter) {
         this.filter = filter;
         this.bits = null;

     public BitSet bits(IndexReader reader) throws IOException {
         if (bits != null) {
             return bits;

         bits = filter.bits(reader);
         return bits;


Bruce Ritchie

View raw message