18 apr 2007 kl. 19.15 skrev jim shirreffs:
The documents I am indexing into Lucene all have an integer unique
ID (21345). This ID is not and will not be in the document context.
But I need to the able to retrieve from Lucene the document ID. I
know the document ID at index time so I can tell the indexer what
the ID is except I do not know how to do that. Reading faq/wiki it
seems that I can define a field called documentID and add that to
the index but I can not find any sample code to do this that I
could use as a guide. If some could show me how to use fields add/
retrieve (assuming that is the correct way to go) I would greatly
appreciate it.
You will have to do something like this (dry-coded and not tested):
List<YourBusinessObject> ybos = ...
IndexWriter iw = ...
for (YourBusinessObject ybo : ybos) {
Document d = new Document();
d.add(new Field("documentID", String.valueOf(ybo.getID()),
Field.Store.YES, Field.Index.YES));
d.add(new Field("title", ybo.getTitle(), Field.Store.NO,
Field.Index.YES));
d.add(new Field("content", ybo.getDescription(), Field.Store.NO,
Field.Index.YES));
iw.add(d);
}
iw.close();
You will now be able to retreive the stored value of field docuemntID
from documents in your index.
Hope this helps.
--
karl
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]