How to set a field to keep a row unique in lucene?

陌路散爱 提交于 2019-11-30 14:33:25

This is exactly the purpose of the IndexWrite#updateDocument method. The first argument is the term that must be unique in your index.

For example,

String id = "42";
Document doc = new Document();
Field field = new Field("id", id, Store.YES, Index.NOT_ANALYZED);
doc.add(field);

indexWriter.updateDocument(new Term("id", id), doc);

will ensure that doc is the only document with id 42 in your index.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!