Developer Forum »
Searching for nodes that fall within a date range
42 posts

I have a node type that has two properties: StartDate and EndDate. How do I add a query to my Lucene query that searches for nodes that fall within this range, i.e. StartDate <= some date <= EndDate.

Are dates serialized into Lucene NumericFields? If so, which format is used for serialization? yyyyMMdd?

Thanks!

-Emil

181 posts

Hi!

The format for date fields in the database is the format you guessed: yyyyMMdd. See this blogpost to see how you could check that out yourself in 2 minutes: http://developer.webnodes.com/developer-tip-luke

To do a Lucene query that finds nodes within a date range, you need to use the TermRangeQuery class from Lucene. Use it like you use a BooleanQuery with Webnodes (set the range query object to the custom query property on IndexQuery).

The constructor signature is pretty self explanatory (see below), but if you need a complete example, let me know, and I'll create it:

TermRangeQuery query = new TermRangeQuery("date", lowerDate, upperDate, includeLower, includeUpper);
42 posts

Excellent. Just what I needed :)

Just one more question. If I wanted to look up a document in Luke, how do I go about finding the document number in Luke? E.g. in Webnodes I have a node with id 3747. I was able to locate it in Luke with id Doc. #363.

181 posts

In the search tab in Luke, there is a textbox with the label "Enter search term here". To find a document based on the node id, just type in "NodeId:3", without the quotes. In this case 3 is the node id.

42 posts

Thank you!

1