lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <luc...@mikemccandless.com>
Subject Re: IndexWriter.flush dose not flush the segmentInfos in Lucene 2.3
Date Tue, 25 Mar 2008 09:21:22 GMT

Do you mean 2.4 (trunk) not 2.3?  In 2.4, flush has been deprecated.   
Instead, you should use commit() to force the changes to be visible  
to a reader.

On 2.3 I believe this works correctly as long as the write is opened  
with autoCommit=true (which your example below is).

Mike

Liu_Chao@emc.com wrote:
> I found that for lucene 2.3, IndexWriter.flush does not flush the  
> segmentInfos.
>
> For example, I create a new index directory and add 10 documents to  
> it:
>
> 	IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(),  
> true);
> 	indexDocs(writer, SOURCE_DIR);//in the source directory, there are  
> 10 documents.
> 	writer.flush();
>
> If the IndexWriter is not closed and then an IndexReader is opened  
> to this index:
>
> 	IndexReader reader = IndexReader.open(INDEX_DIR);
> 	int docNum = reader.numDocs();//docNum = 0
>
> at this time, docNum = 0, the new opened IndexReader cannot see the  
> new added documents.
>
> But if the IndexWriter is closed and then an IndexReader is opened  
> to the Index:
>
> 	writer.close();
> 	IndexReader reader = IndexReader.open(index);
> 	int docNum = reader.numDocs();//docNum = 10
>
> at this time the new opened IndexReader can see the documents added  
> by the IndexWriter.
>
> I think the reason is :
>
> IndexWriter.flush only flushes the data from memory to disk, the  
> metadata of segments segmentInfos is not flushed to the disk.
>
> So that if the IndexWriter is not closed, the new opened  
> IndexReader cannot see the new added documents.
>
> That means what the IndexReader can see is not the segment  
> structure when it is opened but when the last time the IndexWriter  
> is opened.
>
>
> I think it is a bug for new version of lucene 2.3 or at least the  
> behavior is different from lucene 2.1
>
>
> Yours
>
> Liu Chao


---------------------------------------------------------------------
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