"Go" Delete Lucene index

Source: Internet
Author: User

If you need to remove one or a class of documents from the index, Indexreader provides two methods:

Reader. deletedocument (int docnum)

Reader. Deletedocuments (term).

The former is to delete the document according to the number of the document, DocNum is the number of Lucene when the document enters the index, is in sequence, and the latter is to delete multiple documents that meet a certain condition.

After the Deletedocument or Deletedocuments method is executed, the system generates a *.del file that records the deleted document, but does not physically delete the document. Indexwriter.optimize (); only the actual deletion.

String indexdirstr = "D:\\index";D irectory indexdir = fsdirectory.getdirectory (new File (INDEXDIRSTR)); Indexreader Reader = Indexreader.open (indexdir); Reader.deletedocuments (new term ("id", string.valueof (ID))); Reader.flush (); Reader.close ();

Note that the ID in New term () must be Field.Index.TOKENIZED, or it cannot be deleted if it cannot be searched.

Also note that a problem is that my lucene2.2 version will be deleted after the Indexreader.open error!! Replace with the new version of the lucene2.9 problem solved!

"Go" Delete Lucene index

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.