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 Luke Shannon <ls...@futurebrand.com> on 2005/02/01 23:28:40 UTC

Combining Documents

Hello;

I have a situation where I need to combine the fields returned from one
document to an existing document.

Is there something in the API for this that I'm missing or is this the best
way:

//add the fields contained in the PDF document to the existing doc Document
Document attachedDoc = LucenePDFDocument.getDocument(attached);
            Enumeration docFields = attachedDoc.fields();
             while (docFields.hasMoreElements()) {
                     doc.add((Field)docFields.nextElement());
              }

Luke



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


Re: Combining Documents

Posted by Miles Barr <mi...@runtime-collective.com>.
On Tue, 2005-02-01 at 17:28 -0500, Luke Shannon wrote:
> I have a situation where I need to combine the fields returned from one
> document to an existing document.
> 
> Is there something in the API for this that I'm missing or is this the best
> way:
> 
> //add the fields contained in the PDF document to the existing doc Document
> Document attachedDoc = LucenePDFDocument.getDocument(attached);
>             Enumeration docFields = attachedDoc.fields();
>              while (docFields.hasMoreElements()) {
>                      doc.add((Field)docFields.nextElement());
>               }

If you're adding fields to an existing document you need to ensure that
all the existing fields are stored. 

Basically what you need to do is:

1. Retrieve the existing document
2. Remove it from the index
3. Add the new fields
4. Add it back to the index

If you don't remove it from the index you'll have two copies, one with
the new fields and one without. 

If the fields in the existing document are not stored then when you add
it back to the index they will be lost.

-- 
Miles Barr <mi...@runtime-collective.com>
Runtime Collective Ltd.

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