2012-12-11 157 views
1

我所問的問題具體是因爲我不想使用AzureDirectory項目。我只是自己嘗試一些東西。Lucene.NET和在Azure Blob存儲上存儲數據

cloudStorageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=http;AccountName=xxxx;AccountKey=xxxxx"); 

     blobClient=cloudStorageAccount.CreateCloudBlobClient(); 


     List<CloudBlobContainer> containerList = new List<CloudBlobContainer>(); 
     IEnumerable<CloudBlobContainer> containers = blobClient.ListContainers(); 
     if (containers != null) 
     { 
     foreach (var item in containers) 
     { 
      Console.WriteLine(item.Uri); 
     } 
     } 
     /* Used to test connectivity 
     */ 
     //state the file location of the index 

     string indexLocation = containers.Last().Name.ToString(); 
     Lucene.Net.Store.Directory dir = 
      Lucene.Net.Store.FSDirectory.Open(indexLocation); 

     //create an analyzer to process the text 
     Lucene.Net.Analysis.Analyzer analyzer = new 
     Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30); 

     //create the index writer with the directory and analyzer defined. 

     bool findexExists = Lucene.Net.Index.IndexReader.IndexExists(dir); 

     Lucene.Net.Index.IndexWriter indexWritr = new Lucene.Net.Index.IndexWriter(dir, analyzer,!findexExists, Lucene.Net.Index.IndexWriter.MaxFieldLength.UNLIMITED); 
     //create a document, add in a single field 
     Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document(); 
     string path="D:\\try.html"; 
     TextReader reader = new FilterReader("D:\\try.html"); 
     doc.Add(new Lucene.Net.Documents.Field("url",path,Lucene.Net.Documents.Field.Store.YES,Lucene.Net.Documents.Field.Index.NOT_ANALYZED)); 
     doc.Add(new Lucene.Net.Documents.Field("content",reader.ReadToEnd().ToString(),Lucene.Net.Documents.Field.Store.YES,Lucene.Net.Documents.Field.Index.ANALYZED)); 
     indexWritr.AddDocument(doc); 
     indexWritr.Optimize(); 
     indexWritr.Commit(); 
     indexWritr.Close(); 

現在的問題是,索引完成後,我無法看到容器內創建的任何文件。有人可以幫我嗎?

回答

5

您正在使用FSDirectory,它將把文件寫入本地磁盤。

您正在將它傳遞給blob存儲中的容器列表。 Blob存儲是通過REST API提供的服務,不能直接從文件系統尋址。因此,FSDirectory無法將索引寫入存儲。

的選項有:

  1. 安裝在機器上的VHD磁盤,並存儲在Blob存儲的VHD。有一些關於如何在此處執行此操作的說明:http://blogs.msdn.com/b/avkashchauhan/archive/2011/04/15/mount-a-page-blob-vhd-in-any-windows-azure-vm-outside-any-web-worker-or-vm-role.aspx
  2. 使用您在問題中引用的Azure目錄。我已經重建了AzureDirectory針對最新的存儲SDK:https://github.com/richorama/AzureDirectory
+0

謝謝。你能詳細說明第一件事可以實現嗎?我很無知:( – Mandy

+0

如果我使用AzureDirectory ..它提供了完全控制blob修改? – Mandy

+0

你是什麼意思,完全控制blob修改? –