Directory lock error with Lucene.Net usage in an ASP.NET MVC site

后端 未结 6 2188
陌清茗
陌清茗 2021-02-13 21:29

I\'m building an ASP.NET MVC site where I want to use Lucene.Net for search. I\'ve already built a SearchController and all of its methods, but I\'m getting an error at runtime

6条回答
  •  死守一世寂寞
    2021-02-13 21:42

    try
    {
        writer = new IndexWriter(directory, new StandardAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
    }
    
    catch (LockObtainFailedException ex)
    {
         DirectoryInfo indexDirInfo = new DirectoryInfo(directory);
         FSDirectory indexFSDir = FSDirectory.Open(indexDirInfo, new Lucene.Net.Store.SimpleFSLockFactory(indexDirInfo));
         IndexWriter.Unlock(indexFSDir);
         writer = new IndexWriter(directory, new StandardAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
    }
    

提交回复
热议问题