My app generates unique id for each row to index in lucene and save to database. One sutation is if there is and row have the same id,I want to update it,not insert an new row and index.
How to do that?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With