You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by anson <an...@linkclub-staff.com> on 2007/04/09 11:25:57 UTC

How to update index dynamically

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


Re: How to update index dynamically

Posted by anson <an...@linkclub-staff.com>.
Erik, thanks.

U r right. Once excuting the search action, I will check whether this 
IndexReader still works on a current version of the index by 
IndexSearcher#isCurrent(). If not I will open a new IndexSearcher.
And now it works well.

But I want to know that if index update action offen happens, the 
IndexSearcher also need create many times, what influence well be caused 
on my blog system. Have u know something about it.

Best regards.

>After indexing, you have to open a new IndexSearcher to in order to see new
> documents.
>
>	Erik
>
>
>On Apr 9, 2007, at 5:25 AM, anson wrote:
>
>>
>> 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: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>For additional commands, e-mail: java-user-help@lucene.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: How to update index dynamically

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
After indexing, you have to open a new IndexSearcher to in order to  
see new documents.

	Erik


On Apr 9, 2007, at 5:25 AM, anson wrote:

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


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


RE: How to update index dynamically

Posted by Tony Qian <to...@hotmail.com>.
You have to refresh your IndexSearcher periodically.

Tony

>From: anson <an...@linkclub-staff.com>
>Reply-To: java-user@lucene.apache.org
>To: java-user@lucene.apache.org
>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: java-user-unsubscribe@lucene.apache.org
>For additional commands, e-mail: java-user-help@lucene.apache.org
>

_________________________________________________________________
Download Messenger. Join the i’m Initiative. Help make a difference today. 
http://im.live.com/messenger/im/home/?source=TAGHM_APR07


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org