【问题标题】:Error creating lucene index in Azure Blob with Azuredirectory使用 Azuredirectory 在 Azure Blob 中创建 lucene 索引时出错
【发布时间】:2016-08-09 07:11:45
【问题描述】:

我一直在努力让它发挥作用。 这就是我想要实现的目标:

  1. 使用 lucene.Net 实现搜索功能
  2. 在 azure 上托管此内容

问题:

我使用本教程 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)"
  }
}

提前谢谢,我真的很迷茫我做错了什么。

【问题讨论】:

    标签: c# azure lucene azure-blob-storage lucene.net


    【解决方案1】:

    请删除以下代码

         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;
                }
            }
    

    【讨论】:

    • 抱歉,这周我很忙。今晚我会试试这个,如果有效,请标记答案。
    猜你喜欢
    • 2020-03-03
    • 2010-11-19
    • 1970-01-01
    • 2014-10-07
    • 2017-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-19
    相关资源
    最近更新 更多