Click here to Skip to main content
15,887,332 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I am using lucene.net 3.0.3.0 to search data in a web site. I have used following method to create index

C#
public static void AppendIndex(string IndexPath, string Contents, string ParentId, string Title, string SectionId, string Id, string indexId)
{
   string strIndexDir = IndexPath;
   Lucene.Net.Store.Directory indexDir = Lucene.Net.Store.FSDirectory.Open(new System.IO.DirectoryInfo(strIndexDir));
   Lucene.Net.Analysis.Analyzer std = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30); //Version parameter is used for backward compatibility. Stop words can also be passed to avoid indexing certain words
   IndexWriter idxw = new IndexWriter(indexDir, std, System.IO.Directory.GetFiles(IndexPath).Length == 0 ? true : false, IndexWriter.MaxFieldLength.UNLIMITED); //Create an Index writer object.
   Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
   Lucene.Net.Documents.Field indexidText = new Lucene.Net.Documents.Field("indexid", indexId, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NOT_ANALYZED, Lucene.Net.Documents.Field.TermVector.YES);
   doc.Add(indexidText);
   Lucene.Net.Documents.Field idText = new Lucene.Net.Documents.Field("id", Id, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NOT_ANALYZED, Lucene.Net.Documents.Field.TermVector.YES);
   doc.Add(idText);
   Lucene.Net.Documents.Field fldText = new Lucene.Net.Documents.Field("text", Contents, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.ANALYZED, Lucene.Net.Documents.Field.TermVector.YES);
   doc.Add(fldText);
   Lucene.Net.Documents.Field parentid = new Lucene.Net.Documents.Field("parentid", ParentId, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NOT_ANALYZED, Lucene.Net.Documents.Field.TermVector.YES);
   doc.Add(parentid);
   Lucene.Net.Documents.Field title = new Lucene.Net.Documents.Field("title", Title, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.ANALYZED, Lucene.Net.Documents.Field.TermVector.YES);
   doc.Add(title);

   Lucene.Net.Documents.Field sectionid = new Lucene.Net.Documents.Field("sectionid", SectionId, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.NOT_ANALYZED, Lucene.Net.Documents.Field.TermVector.YES);
   doc.Add(sectionid);
   //write the document to the index
   idxw.AddDocument(doc);
   //optimize and close the writer
   idxw.Optimize();
   idxw.Close();
}


It was working fine. However suddenly I am getting the following exception


System.IO.IOException: background merge hit exception: _132h:C25025 _132i:c1->_132i into _132j [optimize]
[mergeDocStores] ---> Lucene.Net.Index.CorruptIndexException: docs out of order (21371 <= 21371 )
at Lucene.Net.Index.IndexWriter.HandleMergeException(Exception t, OneMerge merge)
at Lucene.Net.Index.IndexWriter.Merge(OneMerge merge)
at Lucene.Net.Index.ConcurrentMergeScheduler.DoMerge(OneMerge merge)
at Lucene.Net.Index.ConcurrentMergeScheduler.MergeThread.Run()
--- End of inner exception stack trace ---
at Lucene.Net.Index.IndexWriter.Optimize(Int32 maxNumSegments, Boolean doWait)
at Lucene.Net.Index.IndexWriter.Optimize(Boolean doWait)
at Lucene.Net.Index.IndexWriter.Optimize()
at Index.AppendIndex(String IndexPath, String Contents, String ParentId, String Title, String SectionId, String Id, String indexId)
in e:\Apllication\Apllication\PMS\App_Code\Index.cs:line 43
at ProfarmaOfCase.btnNext_Click(Object sender, EventArgs e)
in e:\Apllication\Apllication\PMS\ProfarmaOfCase.aspx.cs:line 76

what might be go wrong ?
Posted
Comments
raju@shekhar 4-Feb-15 2:20am    
If i comment 2nd last line from the code then it doesn't throw exception.
//optimize and close the writer
//idxw.Optimize();
idxw.Close();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900