I have an existing index.  I want to add new fields to each document in the 
index.  
Ideally I would do it in-place on the same index, but let's assume I can create 
a new, separate index.
Easy I thought:

<code>
IndexReader reader = IndexReader.open(originalIndex);
int maxdocs = reader.maxDoc();

IndexWriter  writer = new IndexWriter("indexWithMoreFields", new 
StandardAnalyzer(), true);

for (int i=0; i<maxdocs; i++) {
   Document d = reader.document(i);
                                                
   Field f = new Field("extraField", text_for_extra_field, true, true, true);
   d.add(f);                    
   writer.addDocument(d);
}
writer.close();
reader.close();
</code>

- This is not working two ways:
1) Not all documents in the original index appear be copied
2) Some of the fields from the original index are dropped when copying the 
document

Now I figure it has something to do with the original index not "storing" all 
the original fields (indexed, tokenized, not stored) and perhaps this is not 
the proper way to loop through an index, so I can understand that my approach 
is incorrect.  However, this seems like something that would be very common.  I 
do not want to reindex every document from scratch again just to add a field.

Help please.

Thanks,
JMA


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to