I've found the problem.  When Nhibernate.Search creates writer it does not load 
settings for writer appropriately so that writer is always initialized as 
following:

                                               wr.SetMergeFactor(10);

                                               wr.SetMaxMergeDocs(-2147483648);

                                               wr.SetMaxBufferedDocs(10);

After launching sample program (2000 documents, 5000 updates) with these 
parameters I get 250 segments (501 file in index, 7 minutes 30 seconds).  Here 
is a sample program. I wrote it as close as possible to the way 
nhibernate.search uses lucene:

class Program

{

                static string indexDirectory = @"d:\lucene test";

                static string className = "myclass";



                static Document CreateDocument(int id)

                {

                               Document doc = new Document();

                               doc.Add(new Field("type", className, 
Field.Store.YES, Field.Index.UN_TOKENIZED));

                               doc.Add(new Field("id", id.ToString(), 
Field.Store.YES, Field.Index.UN_TOKENIZED));

                               doc.Add(new Field("field", "this is a not very 
long, quite simple string", Field.Store.NO, Field.Index.TOKENIZED));

                               return doc;

                }

                static void Main(string[] args)

                {

                               // create index

                               IndexWriter createWriter = new 
IndexWriter(indexDirectory, new WhitespaceAnalyzer(), true);

                               createWriter.Close();

                               // adding 2000 documents and update one of them 
5000 times

                               for (int i = 0; i < 5000; i++)

                               {

                                               // removing document from index

                                               Term term = new Term("id", "0");

                                               IndexReader indexReader = 
IndexReader.Open(indexDirectory);

                                               TermDocs docs = 
indexReader.TermDocs(term);

                                               while (docs.Next())

                                               {

                                                               int n = 
docs.Doc();

                                                               if 
(className.Equals(indexReader.Document(n).Get("type")))

                                                                              
indexReader.DeleteDocument(n);

                                               }

                                               docs.Close();

                                               indexReader.Close();

// adding documents to index

                                               IndexWriter wr = new 
IndexWriter(indexDirectory, new WhitespaceAnalyzer(), false);

                                               
wr.AddDocument(CreateDocument(0));

                                               if (i < 2000)

                                               {

                                                               
wr.AddDocument(CreateDocument(i));

                                               }

                                               wr.Close();

                               }

                }

}

After setting MaxMergeDocs to 10000 I get 11 segments (23 files, 1 minute 12 
seconds)with looks closer to the truth. But still should not there be 10 
segments?

Reply via email to