Simple Lucene을 사용하는 일부 코드를 상속 받았습니다. Simple Lucene에 대해서는 거의 알지 못합니다. 현재 코드는 색인 엔티티에 IndexService
을 의존합니다. 다음 코드를 사용한다 :Simple Lucene에서 IndexService 사용
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
인스턴스를 반환합니다. 이 방법은 로컬 컴퓨터에 인덱스를 저장하는 데 사용되었습니다. 그러나 이제 이것을 Windows Azure 저장소 블롭으로 옮겨야합니다. 그렇게하기 위해 나는 도서관 (https://github.com/richorama/AzureDirectory)에 의존하고 있습니다.
여기에 표시된 예는 Lucene.Net.Index.IndexWriter
을 반환합니다. 이 방법을 사용하여이 객체를 사용하는 방법을 알지 못합니다. 유형이 완전히 호환되지 않는 것처럼 보입니다. 내가 원했던 것은 인덱스 파일을위한 다른 저장 위치를 사용하는 것이 었습니다. 이것을 할 수있는 방법이 있습니까? 그렇다면, 어떻게. 나는 여기의 작은만의 위로 완전하게있다. 감사! 그것이 기관의 목록을 통해 IndexWriter, 반복을 열고 문서로 변환, 기본적으로
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;
}
}
을하고, 작가를 통해 인덱스에 추가하고,를 반환