Lucene Fundamentally, does not support the document update operation, it provides the UpdateDocument method is actually first deleted after the new. In the actual use of the process, found that the method has the following limitations:
1, the set of the term corresponding field must be a string type
That is, the following combinations can perform normally:
Document document = new document ();d ocument. ADD (New Field ("Serviceid", serviceQueryResult.ServiceId.ToString (), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_ norms));d ocument. ADD (New Numericfield ("Shopid", Field.Store.YES, True). Setintvalue (servicequeryresult.shopid));d ocument. ADD (New Field ("ServiceName", Servicequeryresult.servicename, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS)); Writer. Adddocument (document); writer. UpdateDocument (New term ("Serviceid", ServiceQueryResult.ServiceId.ToString ()), document);
If Serviceid is an integer type, it cannot be updated directly with the UpdateDocument method and must be created after deletion, as follows:
Document document = new document ();d ocument. ADD (New Numericfield ("Serviceid", Field.Store.YES, True). Setintvalue (Servicequeryresult.serviceid));d ocument. ADD (New Numericfield ("Shopid", Field.Store.YES, True). Setintvalue (servicequeryresult.shopid));d ocument. ADD (New Field ("ServiceName", Servicequeryresult.servicename, Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS)); Writer. Adddocument (document); writer. Deletedocuments (Numericrangequery.newintrange ("Serviceid", Servicequeryresult.serviceid, Servicequeryresult.serviceid, True, true); writer. Adddocument (document);
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Lucene's UpdateDocument