1
我一直在拉我的头发,试图让它工作。 这就是我想要实现:使用Azuredirectory在Azure Blob中创建lucene索引时出错
- 使用lucene.Net搜索功能
- 主机这在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)"
}
}
在此先感谢,真的很失去我做错了什么。
道歉,这个星期我忙了。我今晚试试这个,如果它有效,请给出答案。 –