+1 Good idea. I think that there also should be other implementations
for the different primitive types.
Maybe the inclusive or exclusive filtering can be a boolean option?

Martijn

On 23 July 2012 19:37, Smiley, David W. <dsmi...@mitre.org> wrote:
> 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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to