Book Image

Lucene 4 Cookbook

By : Edwood Ng, Vineeth Mohan
Book Image

Lucene 4 Cookbook

By: Edwood Ng, Vineeth Mohan

Overview of this book

Table of Contents (16 chapters)
Lucene 4 Cookbook
About the Authors
About the Reviewers


NumericRangeQuery is similar to NumericRangeFilter, in which you can specify lower bound and upper bound values for matching. To ensure search quality, make sure the numeric type (IntField, FloatField, LongField, and DoubleField) matches between the search and indexed field.

How to do it…

Here is a code snippet to demonstrate NumericRangeQuery:

Query query = NumericRangeQuery.newIntRange("num", 0, 200, true, true);

How it works…

This example will return sentence one and two from our setup. Note that we need to specify a numeric type (newIntRange) when creating a query. It accepts five parameters: name of the field, lower bound, upper bound, inclusive of a lower value, and inclusive of an upper value.