I use the following statement to index a date:
luceneDoc.add(new NumericField(key).setLongValue(date.getTime()));
I also use statements as follows to add text properties:
luceneDoc.add(new Field(key, value, Field.Store.YES, Field.Index.ANALYZED));
Then I perform a text property query:
author:hans
This works perfect. But when I perform a range query, nothing gets returned:
my-date-property:[20100101 TO 20110101]
What am I missing here?
I had a look at the index with Luke, I see all my text property for a document but the date properties only appear in the overview page... maybe that is normal.
I actually DO SEE the date properties if I add it like this:
NumericField field = new NumericField(key, Field.Store.YES, true);
field.setLongValue(date.getTime());
luceneDoc.add(field);
But: the query still does not work! Maybe it only works from Java with the Query Builder? I have not tried out that. But it would be great if the text query would work too. ANY IDEA???
If you want a range query to work with dates in the form of YYYYMMDD, then index your date like this:
String dateString = DateTools.dateToString(date, Resolution.DAY);
luceneDoc.add(new Field(key, dateString, Store.YES, Index.NOT_ANALYZED));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With