adhg
adhg

Reputation: 10863

lucene 5.3 how to add date to your fields

In previous version of lucene, one could do this:

Document doc = new Document();
doc.add(new Field("file_modified",
DateTools.timeToString(file.lastModified(), DateTools.Resolution.MINUTE),
Field.Store.YES, Field.Index.NOT_ANALYZED));

and store the date for which a file was modified (so later you can search by the date). At the moment, I'm using lucene 5.3 and couldn't figure it out how to do the same? The above code is deprecated (no more new Field nor Field.Index.NOT_ANALYZED)

Upvotes: 1

Views: 1035

Answers (1)

adhg
adhg

Reputation: 10863

The result for this is using LongField example to solve the problem:

            long modified = file.lastModified();
            doc.add(new LongField(FILE_MODIFIED, modified, Field.Store.YES));

Upvotes: 2

Related Questions