[英]How to index date field in lucene
I am new to lucene. 我是lucene的新手。 I have to index date field. 我必须索引日期字段。 i am using Following IndexWriter
constructor in lucene 3.0.0. 我在lucene 3.0.0中使用以下IndexWriter
构造函数。
IndexWriter writer = new IndexWriter(FSDirectory.open(indexDir), new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED)
my point is: Why it needs a analyzer when date fields are not analyzed,while indexing I used Field.Index.NOT_ANALYZED
. 我的观点是:为什么在没有分析日期字段时需要分析器,而索引我使用了Field.Index.NOT_ANALYZED
。
You can store date field in this fashion.. 您可以以这种方式存储日期字段。
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 a file object... 其中f是文件对象...
Now use the above document for indexwriter... 现在使用上面的文档作为索引编写者......
checkout the sample code comes with lucene... and the following link... http://lucene.apache.org/java/2_2_0/api/org/apache/lucene/document/DateTools.html 结帐示例代码附带lucene ...以及以下链接... http://lucene.apache.org/java/2_2_0/api/org/apache/lucene/document/DateTools.html
UPDATE UPDATE
Field.Index NOT_ANALYZED
Index the field's value without using an Analyzer, so it can be searched. 不使用分析器索引字段的值,因此可以搜索它。 As no analyzer is used the value will be stored as a single term. 由于不使用分析器,因此该值将存储为单个术语。 This is useful for unique Ids like product numbers. 这对于产品编号等唯一ID非常有用。
As per lucene javadoc you don't need analyzer for fields using Field.Index NOT_ANALYZED
but i think by design the IndexWriter
expects an analyzer as indexing the exact replica of data is not efficient in terms of storage and searching. 根据lucene javadoc,您不需要使用Field.Index NOT_ANALYZED
对字段进行分析,但我认为,根据设计, IndexWriter
期望分析器将数据的精确副本编入索引,这在存储和搜索方面效率不高。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.