2016-08-09 72 views
1

我一直在拉我的頭髮,試圖讓它工作。 這就是我想要實現:使用Azuredirectory在Azure Blob中創建lucene索引時出錯

  1. 使用lucene.Net搜索功能
  2. 主機這在Azure上

問題:

我用這個教程Lucene.Net ultra fast search for MVC or WebForms site => made easy!到開始,它完美的工作,同時從我的localdb檢索創建索引文件在我的本地磁盤,並隨後調用休息方法來執行搜索。

現在我試圖將部分代碼轉換爲引用blob。 使原來是這樣的:

private static string _luceneDir =Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "lucene_index"); 
private static FSDirectory _directoryTemp; 
private static FSDirectory _directory { 
get { 
    if (_directoryTemp == null) _directoryTemp = FSDirectory.Open(new DirectoryInfo(_luceneDir)); 
    if (IndexWriter.IsLocked(_directoryTemp)) IndexWriter.Unlock(_directoryTemp); 
    var lockFilePath = Path.Combine(_luceneDir, "write.lock"); 
    if (File.Exists(lockFilePath)) File.Delete(lockFilePath); 
    return _directoryTemp; 
}} 

我改成了這樣:

private static AzureDirectory azureDirectory = new AzureDirectory(CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")),"SearchCatalog"); 
private static AzureDirectory _directoryTemp; 


     private static AzureDirectory _directory 
     { 
      get 
      { 
       // if (_directoryTemp == null) _directoryTemp = FSDirectory.Open(new DirectoryInfo(_luceneDir)); 
       if (_directoryTemp == null) _directoryTemp = azureDirectory; 
       if (IndexWriter.IsLocked(_directoryTemp)) IndexWriter.Unlock(_directoryTemp); 
       return _directoryTemp; 
      } 
     } 

我帶走了最後兩行,因爲我不知道如何讓Azure中的blobl存儲的文件路徑,從我的理解來看它是不可能的。

現在發生的是blob中的容器被創建,但索引文件沒有被創建,並且我得到一個http 404錯誤。 詳細錯誤:

{ 
    "Message": "An error has occurred.", 
    "ExceptionMessage": "The remote server returned an error: (404) Not Found.", 
    "ExceptionType": "Microsoft.WindowsAzure.Storage.StorageException", 
    "StackTrace": " at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)\r\n at Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetBlobReferenceFromServer(StorageUri blobUri, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)\r\n at Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.GetBlobReferenceFromServer(String blobName, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)\r\n at Lucene.Net.Store.Azure.AzureLock.IsLocked()\r\n at Lucene.Net.Index.IndexWriter.IsLocked(Directory directory)\r\n at brickandmortarv1.Models.LuceneSearch.get__directory()\r\n at brickandmortarv1.Models.LuceneSearch.AddUpdateLuceneIndex(IEnumerable`1 products)\r\n at brickandmortarv1.Controllers.LuceneController.Get(String searchterm)\r\n at lambda_method(Closure , Object , Object[])\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()", 
    "InnerException": { 
    "Message": "An error has occurred.", 
    "ExceptionMessage": "The remote server returned an error: (404) Not Found.", 
    "ExceptionType": "System.Net.WebException", 
    "StackTrace": " at System.Net.HttpWebRequest.GetResponse()\r\n at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext)" 
    } 
} 

在此先感謝,真的很失去我做錯了什麼。

回答

0

請刪除下面的代碼

 if (IndexWriter.IsLocked(_directoryTemp)) IndexWriter.Unlock(_directoryTemp); 

除去上面的代碼後,它的工作原理。下面是在我身邊工作的截圖:

enter image description here

以下是我的代碼:

private static AzureDirectory azureDirectory = new AzureDirectory(CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=jastorage1;AccountKey=***"),"sample" 

     private static AzureDirectory _directoryTemp; 
     private static AzureDirectory _directory 
     { 
      get 
      { 
       // if (_directoryTemp == null) _directoryTemp = FSDirectory.Open(new DirectoryInfo(_luceneDir)); 
       if (_directoryTemp == null) _directoryTemp = azureDirectory; 
       // if (IndexWriter.IsLocked(_directoryTemp)) IndexWriter.Unlock(_directoryTemp); 
       _directoryTemp.ClearLock("write.lock"); 
       return _directoryTemp; 
      } 
     } 
+0

道歉,這個星期我忙了。我今晚試試這個,如果它有效,請給出答案。 –