Ok I am still confused.
Looking at the examples to index a document I would do something like the
following:
Document document = new Document();
document.add(Field.UnStored("article", article));
document.add(Field.Text("comments", comments));
Analyzer analyzer = new StandardAnalyzer();
IndexWriter writer = new IndexWriter(indexDirectory, analyzer, false);
writer.addDocument(document);
writer.optimize();
writer.close();
Now lets say that the comments can change and when they do I want to update
that document to contain the newly updated comments.
So I would have to go back and check my index to see if that book already
exists.
Query q = new QueryParser("article", analyzer).parse(querystr);
int hitsPerPage = 10;
IndexSearcher searcher = new IndexSearcher(index);
TopDocCollector collector = new TopDocCollector(hitsPerPage);
searcher.search(q, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
if (hits!= null && hits.length > 0) {
// ?
// Then this already exists and I just want to update the comments section
}
Does that make sense? Am I going about this wrong?
Billy
________________________________________
From: Tim Williams [[email protected]]
Sent: Friday, April 17, 2009 6:05 PM
To: [email protected]
Subject: Re: IndexWriter update method
On Fri, Apr 17, 2009 at 7:27 PM, Newman, Billy <[email protected]> wrote:
> I am looking for info on how to use the IndexWriter.update method. A short
> example of how to add a document and then later update would
> be very helpful. I get lost because I can add a document with just the
> document, but I need a document and a Term. I am not really sure
> what a Term is since I did not use a Term to create the document nor do I see
> it in any of the examples of searching/adding.
When you index the document, add an ID field that is unique. Then
when you go to update the document the "Term" will be the ID of the
document you wish to update. For example, you might add a URL as the
unique ID, then to update it might look something like:
writer.update(new Term("id","http://apache.org/lucene/index.htm"), doc)
--tim
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
This e-mail and any files transmitted with it may be proprietary and are
intended solely for the use of the individual or entity to whom they are
addressed. If you have received this e-mail in error please notify the sender.
Please note that any views or opinions presented in this e-mail are solely
those of the author and do not necessarily represent those of ITT Corporation.
The recipient should check this e-mail and any attachments for the presence of
viruses. ITT accepts no liability for any damage caused by any virus
transmitted by this e-mail.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]