How to index a date field in lucene

I am new to lucene. I have to index the date field. I use the following constructor IndexWriterin lucene 3.0.0.

IndexWriter writer = new IndexWriter(FSDirectory.open(indexDir), new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED)

my point of view: Why does he need an analyzer when the date fields are not parsed, and I used indexing Field.Index.NOT_ANALYZED.

+5
source share
1 answer

You can save the date field this way.

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

where f is the file object ...

Now use the above document for the indexer ...

checkout example code comes with lucene ... and the following link ... http://lucene.apache.org/java/2_2_0/api/org/apache/lucene/document/DateTools.html

UPDATE

Field.Index NOT_ANALYZED

, . , . , .

lucene javadoc Field.Index NOT_ANALYZED, , IndexWriter , , .

+10

All Articles