在Lucene 4.9中索引布尔值的最佳方法

时间:2014-08-27 15:33:02

标签: lucene

这个问题之前已被提出并回答(链接如下),但答案已经过时了。

我想使用Lucene使用布尔字段索引文档。前一篇文章中推荐的方式是:

doc.add(new Field(" boolean"," true",Field.Store.NO,Field.Index.NOT_ANALYZED_NO_NORMS));

但是,现在不推荐使用类字段。今天最好的方法是什么?

Which is the best choice to indexing a Boolean value in lucene?

1 个答案:

答案 0 :(得分:1)

doc.add(new Field("boolean","true",Field.Store.NO,Field.Index.NOT_ANALYZED_NO_NORMS));

只需添加一个未经分析的字符串字段,其值为" true"。

StringField这些天应该做同样的伎俩:

doc.add(new StringField("boolean", "true", Store.NO));