Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lucene 4.0 IndexWriter updateDocument for Numeric Term

I just wanted to know how it is possible to to update (delete/insert) a document based on a numeric field. So far I did this:

LuceneManager.updateDocument(writer, new Term("id",  NumericUtils.intToPrefixCoded(sentenceId)), newDoc);

But now with Lucene 4.0 the NumericUtils class has changed to this which I don't really understand. Any help?

like image 892
Daniel Gerber Avatar asked Oct 27 '25 15:10

Daniel Gerber


1 Answers

With Lucene 5.x, this could be solved by code below:

    int id = 1;
    BytesRefBuilder brb = new BytesRefBuilder();
    NumericUtils.intToPrefixCodedBytes(id, 0, brb);
    Term term = new Term("id", brb.get());
    indexWriter.updateDocument(term, doc); // or indexWriter.deleteDocument(term);
like image 111
Jet Yang Avatar answered Oct 29 '25 05:10

Jet Yang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!