lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "JMA" <mrj...@comcast.net>
Subject Adding fields to an existing index fails?
Date Fri, 14 Jul 2006 08:09:24 GMT

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: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message