You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Paul Taylor <pa...@fastmail.fm> on 2009/03/17 17:28:20 UTC

What is the best way to modify a Document object

I am using lucene to index rows in a spreadsheet , each row is a 
Document, and the document indexes 10  fields from the row plus the row 
number used to relate thethe Document to the row number
So when someone modifies one of the 10 fields I am interested in a row I 
have to update the document with the new data

writer = new IndexWriter(directory, analyzer);
Document document = createDocument(row);
writer.updateDocument(new Term(ROW_NUMBER, "" + row), document);
writer.optimize();
writer.close();

Because I can't retrieve the existing Document for a row from a writer I 
recreate the document when one of the values has changed, but this means 
I have to go off and get all the values again even though I am only 
changing one. is there a better way to do this, I thought
that I could retrive the document using an IndexReader and then modify 
it using removeField(),AddField() but there is extra overhead in doing 
in having to create a reader to get the document - so which would be best.

thanks Paul



---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: What is the best way to modify a Document object

Posted by Simon Willnauer <si...@googlemail.com>.
Hi Paul,
If you do not store all the data inside lucene you have to get you
updated data from you spreadsheet again. Even if you would store all
the data you would have to update the document by creating a new one
and adding it to the index using updateDocument(). You can not update
just one single field. If you get a Document from your index calling
removeField() does not have any effect. The add and removeField
methodes only make sense prior to adding a document to an index. These
methods cannot be used to change the content of an existing index! In
order to achieve this, a document has to be deleted from an index and
a new changed version of that document has to be added.

Creating and updating your document from the spreadsheet data is the way to go.

simon




On Tue, Mar 17, 2009 at 5:28 PM, Paul Taylor <pa...@fastmail.fm> wrote:
> I am using lucene to index rows in a spreadsheet , each row is a Document,
> and the document indexes 10  fields from the row plus the row number used to
> relate thethe Document to the row number
> So when someone modifies one of the 10 fields I am interested in a row I
> have to update the document with the new data
>
> writer = new IndexWriter(directory, analyzer);
> Document document = createDocument(row);
> writer.updateDocument(new Term(ROW_NUMBER, "" + row), document);
> writer.optimize();
> writer.close();
>
> Because I can't retrieve the existing Document for a row from a writer I
> recreate the document when one of the values has changed, but this means I
> have to go off and get all the values again even though I am only changing
> one. is there a better way to do this, I thought
> that I could retrive the document using an IndexReader and then modify it
> using removeField(),AddField() but there is extra overhead in doing in
> having to create a reader to get the document - so which would be best.
>
> thanks Paul
>
>
>
> ---------------------------------------------------------------------
> 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