Lucene 4.4 Dropping an index based on the INT type field

Source: Internet
Author: User

1, method One, through the term deletion of the term structure is not, the type of int needs to be converted into Lucene Bytesref class.        /** * Delete index file according to commodity ID * @param ID */public void deletedocument (int id) {;        File File = new file ("E://index");        Ikanalyzer Analyzer = new Ikanalyzer ();        Indexwriterconfig indexwriterconfig = new Indexwriterconfig (version.lucene_44, analyzer);        IndexWriter indexwriter = null;        Directory directory;            try {directory = fsdirectory.open (file);     Create IndexWriter indexwriter = new IndexWriter (directory, indexwriterconfig);                    Bytesref bytes = new Bytesref (numericutils.buf_size_int);                    numericutils.inttoprefixcoded (id, 0, bytes);                       Term term = new term (field, bytes);            Indexwriter.deletedocuments (term);                       Indexwriter.close ();            } catch (IOException e) {//TODO auto-generated catch block E.printstacktrace ();                  }         }2. Method two, use numericrangequery/** * To delete index files based on product ID * @param ID */public void deletedocument (int id)        {;        File File = new file ("E://index");        Ikanalyzer Analyzer = new Ikanalyzer ();        Indexwriterconfig indexwriterconfig = new Indexwriterconfig (version.lucene_44, analyzer);                IndexWriter indexwriter = null;        Directory directory;             try {directory = fsdirectory.open (file);     Create IndexWriter indexwriter = new IndexWriter (directory, indexwriterconfig);                         Query numbericrangequery = Numericrangequery.newintrange ("ID", Id-1, Id+1, False, false);             Indexwriter.deletedocuments (Numbericrangequery);                         Indexwriter.close ();             } catch (IOException e) {//TODO auto-generated catch block E.printstacktrace (); }                          }


Lucene 4.4 Dropping an index based on the INT type field

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.