Implementation of Update and Delete in Lucene

xiaoxiao2021-03-06  64

Delete is very simple. As long as the INDEX it generates is saved as long as the add record is time, additional indexes are established. Then use the delete () method in the IndexReader class to delete it. DELETE has two implementations: Delete (INT I) and DELETE (Term Term) For the first unused, the recorded index can be given. The second implementation needs to create a Term object. Term T = New Term ("ID", "idValue"); here the ID is the field you join the record, IDValue is the content of the field. The following is a specific implementation method: public int deleteRecords (String Field, string text) {INT delete = 0; try {Directory directory = FSDirectory.getDirectory (file, false); Term term = new Term (field, text); IndexReader reader = IndexReader.open (directory); reader.unlock (directory); // remember where To unlock Delete = Reader.delete (TERM); reader.close (); // Remember to close, otherwise delete will not be synchronized into the index file Directory.close (); // Close Directory} catch (ioException ex)} EX.PrintStackTrace ();} return delete;} Next is the implementation of Update. The version of Lucene does not support direct update. You must find out the record according to the index ID you join, first DELETE is in ADD. Maybe there is more Ok, I think it should be ok, you should be able to add this field. However, I haven't tried it yet. I should be able to be able to reprint if I need to reprint, please indicate the source and the author. Thank you QQ: 221704msn: flyly@yeah.netemail: zhangfl@sports.cn

转载请注明原文地址:https://www.9cbs.com/read-89451.html

New Post(0)