views:

102

answers:

0

-Edit- Important: I updated the code to not use obsoluete functions. Now only the NoSuchDirectoryException issue remains

Edit: NOTE i can bypass the NoSuchDirectoryException by creating the folder in a winform app and copy it. However i still have a LockObtainFailedException issue if i dont shut down properly.

I have an issue with (Lucene.net 2.9.2)[https://svn.apache.org/repos/asf/lucene/lucene.net/tags/]. It throws a lock exception. After poking around i notice these things.

  1. My code below works in an app bit when calling in Application_Start i get a NoSuchDirectoryException.
  2. Not closing the writer (as my code doesnt do below) i WILL get a LockObtainFailedException with the message Lock obtain timed out: SimpleFSLock@<FULL_PATH> from either app or asp.net

These thread hinted when spawning threads they get less permissions then i do (but! my main thread has problems as well...) and one solution is to impersonate IIS. I am using visual studios 2010. I am not sure how full blown it is but my attempt to impersonate it failed.

So my question is how do i have lucene create the directory and not throw an exception if dont close the writer for some reason (such as power going out)?

http://stackoverflow.com/questions/2341163/why-is-my-lucene-index-getting-locked/2499285#2499285
http://stackoverflow.com/questions/1123517/lucene-net-and-i-o-threading-issue/1123981#1123981

    static IndexWriter writer = null;
    static void lucene_init()
    {
        bool create = false;
        //I now use a full path. I still get NoSuchDirectoryException 
        //string dirname = "LuceneIndex_z";
        if (System.IO.Directory.Exists(dirname) == false)
            create = true;

        var directory = FSDirectory.GetDirectory(dirname);
        var analyzer = new StandardAnalyzer();
        writer = new IndexWriter(directory, analyzer, create);
    }