Return-Path: X-Original-To: apmail-lucene-java-user-archive@www.apache.org Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7D5F0E16B for ; Fri, 1 Feb 2013 09:43:44 +0000 (UTC) Received: (qmail 34541 invoked by uid 500); 1 Feb 2013 09:43:42 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 34211 invoked by uid 500); 1 Feb 2013 09:43:41 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 34174 invoked by uid 99); 1 Feb 2013 09:43:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Feb 2013 09:43:40 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of ian.lea@gmail.com designates 209.85.212.182 as permitted sender) Received: from [209.85.212.182] (HELO mail-wi0-f182.google.com) (209.85.212.182) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Feb 2013 09:43:35 +0000 Received: by mail-wi0-f182.google.com with SMTP id hn14so349223wib.15 for ; Fri, 01 Feb 2013 01:43:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=JXDnEuCtBZ/5blVrkmyyJChxDHBw4nODnYX7fDBL6ME=; b=OtXoxkyvfAq2Q03KO26ztOoWbZvyavlhrg1+1rC6dXmqkc2sbxUyTnI8iJy3OQNXlI U6YZGOEjWJa/BfCwSBqk0PHTpUCigwhkLCbe/Y3w69vE0lfCcyAnnh6beIatc0OCjOjX a/8vsDVSvaeLsd4bv0OMY/9J9ABrGIU+khLhe2mLMQHqXXi9DAY5hjht482CMX+KokLv 7cgLhMsuUMZhomYvOD/iJvsZJJCt04sAuuY8SG4RVnb/4whi6250SXPen4IUR/Nl8N+8 Ae1NxsnFM7v2tRjfYKm73tCe1n5/Pv8HFoukOZ5pyFodTfOfpOgKaC4R/zAzoLaOUpjN iPDA== X-Received: by 10.180.85.226 with SMTP id k2mr1575599wiz.34.1359711793610; Fri, 01 Feb 2013 01:43:13 -0800 (PST) MIME-Version: 1.0 Received: by 10.194.57.11 with HTTP; Fri, 1 Feb 2013 01:42:53 -0800 (PST) In-Reply-To: References: From: Ian Lea Date: Fri, 1 Feb 2013 09:42:53 +0000 Message-ID: Subject: Re: How to properly use updatedocument in lucene. To: java-user@lucene.apache.org Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Checked: Checked by ClamAV on apache.org There is no way to update without reindexing the entire document. It might be less confusing if the IndexWriter.updateDocument() methods were called maybe replaceDocument() but they're not. It would also help if lucene could reject attempts to pass a Document read from the index to these methods although that's probably easier said than done. Set a "thishasbeenreadfromindex" flag on a Document and check + reject if passed to an update method? With a reset call for those expert cases where people know what they are doing rather than falling into accidental traps. -- Ian. On Fri, Feb 1, 2013 at 6:11 AM, VIGNESH S wrote: > Hi Mike, > > Thanks for your reply.. > > MY Scenario is I am creating Lucene Index with Two Fields > 1.Filename > 2.File Contents > > For Example I initially added fields FileName:-say LuceneInAction.pdf > which is not analysed FileContents:Content of the Book it is analysed > using custom analyzer. > > Now what is the right way to change the only Filename Field to some > other name say LuceneReference.pdf.. > > As for what i understand,only way to get the DocumentId of a term is > using Search Method.. > > I get the new file name from the user..and used Search Method to get > the Doc id and used the updateDocument method to update it with a new > name (LuceneReference.pdf.).. > > IndexWriter writer = new > IndexWriter(csDirectory, new > IndexWriterConfig(Version.LUCENE_36,analyzer)); > writer.updateDocument(new Term(NAME_FIELD, "LuceneReference.docx") > It is not updating the index.. > > is there a way to update index without reindexing the entire document? > > > > Thanks and Regards > Vignesh Srinivasan > > > > > On Thu, Jan 31, 2013 at 5:35 PM, Michael McCandless > wrote: >> It's confusing, but you should never try to re-index a document you >> retrieved from a searcher, because certain index-time details (eg, >> whether a field was tokenized) are not preserved in the stored >> document. >> >> Instead, you should re-build the document yourself, setting the right >> details per-Field, and then re-index that. >> >> Separately, that's the right way to call .updateDocument, but you must >> ensure FILE_NAME_FIELD was indexed for the first document, with the >> value "new1.docx". >> >> Can you include how you indexed the original document? >> >> Mike McCandless >> >> http://blog.mikemccandless.com >> >> On Thu, Jan 31, 2013 at 6:43 AM, VIGNESH S wrote: >>> Hi All, >>> >>> I am having a basic doubt.. >>> >>> I am trying to update a lucene document field with a new value.. >>> >>> The below is my code.. It is not giving any errors and also it is not >>> updating the document with field. >>> >>> Document d = searcher.doc(docId); >>> >>> writer1 = new IndexWriter(csDirectory, new >>> IndexWriterConfig(Version.LUCENE_36,analyzer)); >>> >>> writer1.updateDocument(new Term(FILE_NAME_FIELD,"new1.docx"),d); >>> >>> Please help me in this.. >>> >>> Also Suggest me if there is a better way to updateDocument without >>> using search().. >>> >>> >>> -- >>> Thanks and Regards >>> Vignesh Srinivasan >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org >>> For additional commands, e-mail: java-user-help@lucene.apache.org >>> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org >> For additional commands, e-mail: java-user-help@lucene.apache.org >> > > > > -- > Thanks and Regards > Vignesh Srinivasan > 9739135640 > > --------------------------------------------------------------------- > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org > For additional commands, e-mail: java-user-help@lucene.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org For additional commands, e-mail: java-user-help@lucene.apache.org