我一直在拉着我的头发试图让它发挥作用。 这就是我想要实现的目标:
问题:
我使用本教程Lucene.Net ultra fast search for MVC or WebForms site => made easy!开始使用,当我从localdb检索到我的本地磁盘中创建索引文件并随后调用rest方法来执行搜索时,它完美地工作。
现在我正在尝试将部分代码转换为引用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 :(得分:0)
请删除以下代码
if (IndexWriter.IsLocked(_directoryTemp)) IndexWriter.Unlock(_directoryTemp);
删除上面的代码后,它可以工作。这是我身边的截图:
以下是我的代码:
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;
}
}