In the spatial utils package I've got a ValueSourceFilter which is a Filter
based on a ValueSource with a minimum and maximum range. It does what you'd
think it does. This seems like something useful in the query module in the
org.apache.lucene.queries.function package. Any opinions? Here is the source,
by the way:
public class ValueSourceFilter extends Filter {
final Filter startingFilter;
final ValueSource source;
final double min;
final double max;
public ValueSourceFilter( Filter startingFilter, ValueSource source, double
min, double max )
{
if (startingFilter == null) {
throw new IllegalArgumentException("please provide a non-null
startingFilter; you can use QueryWrapperFilter(MatchAllDocsQuery) as a no-op
filter");
}
this.startingFilter = startingFilter;
this.source = source;
this.min = min;
this.max = max;
}
@Override
public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs)
throws IOException {
final FunctionValues values = source.getValues( null, context );
return new FilteredDocIdSet(startingFilter.getDocIdSet(context,
acceptDocs)) {
@Override
public boolean match(int doc) {
double val = values.doubleVal( doc );
return val > min && val < max;
}
};
}
}
I would prefer the range check use >= and <=.
~ David