0

SimpleLuceneを使用するコードをいくつか継承しました。SimpleLuceneについてはほとんど知りません。現在、コードはIndexServicetoインデックスエンティティに依存しています。次のコードが使用されます。

using (var indexService = GetIndexService())
{
  indexService.IndexEntities(cachedResults, p =>
  {
    var document = new Document();
    document.Add(new Field("Name", p.Name, Field.Store.YES, Field.Index.NOT_ANALYZED));
    document.Add(new Field("ID", p.ID, Field.Store.YES, Field.Index.NOT_ANALYZED));
    document.Add(new Field("Description", p.Description, Field.Store.YES, Field.Index.NOT_ANALYZED));
    return document;
  });
}

GetIndexServiceインスタンスを返しSimpleLucene.Impl.DirectorySerivceます。このアプローチは、ローカルマシンにインデックスを保存するために使用されました。ただし、これをWindowsAzureストレージBLOBに移動する必要があります。それを行うために、私はhttps://github.com/richorama/AzureDirectoryにあるライブラリに依存しています。

ここに示す例は、を返しますLucene.Net.Index.IndexWriter。そこにあるアプローチでこのオブジェクトを使用する方法がわかりません。タイプは完全に互換性がないようです。私がやりたかったのは、インデックスファイルに別の保存場所を使用することだけでした。これを行う方法はありますか?もしそうなら、どのように。私はここで完全に小川を上っています。ありがとう!

4

1 に答える 1

0

このようIndexEntities見えます:

public int IndexEntities<TEntity>(DirectoryInfo indexLocation, IEnumerable<TEntity> entities, Func<TEntity, Document> converter)
{
    using (var indexer = new IndexWriterWrapper(indexLocation)) {
        int indexCount = 0;
        foreach (TEntity entity in entities) {
            indexer.Writer.AddDocument(converter(entity));
            indexCount++;
        }
        return indexCount;
    }
}

基本的には、IndexWriterを開き、エンティティのリストを反復処理してドキュメントに変換し、ライターを介してインデックスに追加して、カウントを返します。

パッケージからIndexWriterが返されることを示しているので、作成について心配する必要はありません。ドキュメントを作成しているので、マッピングは必要ありません(コンバーターは、渡されたドキュメントにいくつかの変更を加えることができますが、おそらくそうではありません)。また、作成するだけなので、反復やカウントは実際には必要ありません。残っているのは、ドキュメントを追加することだけです。IndexWriter.addDocument(Document)

var writer = //However you get the writer...
var document = new Document();
document.Add(new Field("Name", p.Name, Field.Store.YES, Field.Index.NOT_ANALYZED));
document.Add(new Field("ID", p.ID, Field.Store.YES, Field.Index.NOT_ANALYZED));
document.Add(new Field("Description", p.Description, Field.Store.YES, Field.Index.NOT_ANALYZED));
writer.addDocument(document);
于 2013-01-21T22:34:26.123 に答える