You have to refresh your IndexSearcher periodically.
Tony
From: anson <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: How to update index dynamically
Date: Mon, 09 Apr 2007 18:25:57 +0900
I have build a blog project under tomcat5.5 with Lucene2.0.
And I want to search my blog by full text, but there is somthing wrong:
----------------------------------------------
The project flow:
(1) On tomcat start I wrote a listener to create a index file if the
index is never created.(It's works well)
(2) When I create/update/delete an article on the blog, I wrote a method
to update the index.(It's also works well)
(3) Then I want to search the new/updated article in the front of my
blog page. But I can't get the new article. But when I restart the
tomcat, I can get the new one that I want. Why.
-----------------------------------------------
The index update flow:
(1) Firsrt I delete the old document in index:
IndexReader reader =
IndexReader.open($INDEX_DIRECTORY);
Term term = new Term("INDEX_ID", $entryId);
if (term != null) {
reader.deleteDocuments(term);
}
//finally:
reader.close();
(2) Add the article to the index:
// Get the singleton IndexWriter instance
IndexWriter writer =
IndexManager.getInstance().getIndexWriter();
// add document
// Document() is method of make Lucene document
writer.addDocument(Document($EntryBean));
writer.optimize();
// finally:
writer.close();
Could anybody tell me anything can help me out. Or I made a wrong flow?
Best regards.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
_________________________________________________________________
Download Messenger. Join the im Initiative. Help make a difference today.
http://im.live.com/messenger/im/home/?source=TAGHM_APR07
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]