2012-06-11 23 views
0

我們在整個應用程序中使用SimpleLucene進行搜索。一切正常。我們將應用程序上傳到Azure並且工作正常,但是,每次我做任何更改並且必須重新上傳到Azure時,我都必須重新創建索引以確保它是最新的。我想將Azure索引移到Azure上的Blob存儲中,但是我不知道如何使用SimpleLucene獲取Azure Lucene目錄。示例代碼將不勝感激。如何獲取SimpleLucene.Net以使用Azure

我正在建造像這樣的索引。

var path = @"my path to the index"; 
var indexWriter = new SimpleLucene.Impl.DirectoryIndexWriter(new System.IO.DirectoryInfo(path), true); 
var definitions = GetDefinitions().ToList(); 

using (var indexService = new SimpleLucene.Impl.IndexService(indexWriter)) 
{ 
    try 
    { 
     indexService.IndexEntities(definitions, new DefinitionsIndexDefinition()); 
    } 
    catch { } 
} 

如何從Azure blob存儲中創建indexWriter?我知道有AzureDirectory DLL,我可以使用但它不適用於SimpleLucene

+0

這可能有助於http://code.msdn.microsoft.com/windowsazure/Azure-Library-for-83562538 – Paparazzi

+0

@Blam - 我有這個庫,但我不能讓它與SimpleLucene合作 – fenix2222

回答

1

我會說簡單Lucene可能不是一個很好的選擇用於Windows Azure,因爲我不確定它是否有代碼存儲Windows Azure Blob存儲上的索引。您確定可以保存到Windows Azure Blob存儲上的索引嗎?

我已經直接通過設置Azure的Blob存儲使用Lucene.NET for Windows Azure,您可以使用在Windows Azure的Blob存儲存儲索引

步驟1:配置您的Azure的Blob存儲

<configuration> 
    <appSettings> 
    <!-- azure SETTINGS --> 
    <add key="BlobStorageEndpoint" value="http://YOURACCOUNT.blob.core.windows.net"/> 
    <add key="AccountName" value="YOURACCOUNTNAME"/> 
    <add key="AccountSharedKey" value="YOURACCOUNTKEY"/> 
    </appSettings> 
</configuration> 

第2步:使用IndexWriter在Azure Blob存儲上存儲索引:

AzureDirectory azureDirectory = new AzureDirectory("TestCatalog"); 
IndexWriter indexWriter = new IndexWriter(azureDirectory, new StandardAnalyzer(), true); 
Document doc = new Document(); 
doc.Add(new Field("id", DateTime.Now.ToFileTimeUtc().ToString(), Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO)); 
doc.Add(new Field("Title", 「this is my title」, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO)); 
doc.Add(new Field("Body", 「This is my body」, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO)); 
indexWriter.AddDocument(doc); 
indexWriter.Close(); 

因此,如果您決定使用Lucene.net for Windows Azure,那將是comp aatingly更容易和最好的行動方針。

+0

這段代碼我已經有了。我不得不修改SimpleLucene的實現來使它工作。我認爲它可行,需要做更多的測試。 – fenix2222

+0

SimpleLucene是Lucene.NET的一個不錯的封裝,它有3個下載codeplex只是因爲你不真的從那裏下載它,你從NuGet獲得它有995下載。 – fenix2222

+0

明白了..感謝您的信息。我從來沒有嘗試過使用它。也許你可以先讓Lucene.Net工作,然後嘗試使用SimpleLucene,這可能會幫助你開始。祝你好運!! – AvkashChauhan

相關問題