Michal R
Michal R

Reputation: 125

Lucene: How to construct a date range query programmatically?

Using Lucene 4.2.1 API, I need an equivalent of

+fieldname:[2013-01-17T00:00:00Z TO *]

constructed programmatically.

I peeked at TermRangeQuery and NumericRangeQuery but have not been able to come up with a quick solution.

Upvotes: 2

Views: 6041

Answers (1)

mindas
mindas

Reputation: 26713

This query is no different from a range query, the only difference is that it expects to get the date formatted in Solr format.

You can use Solr's TrieDateField.getRangeQuery to construct this query. Tip: QParser parameter is ignored so you can just skip it.

Upvotes: 1

Related Questions