2

私はasp .net mvcアプリケーションでLucene.Net + SimpleLuceneを使用しています。データベースから索引を作成する際に問題があります。インデックスがうまく作成され始めるように見えるが、私が得るすべては、0と1キロバイトのサイズの5つのファイルです:Lucene.Netは空のインデックスを作成します

 
_0.fdt    0KB 
_0.fdx    0KB 
segment.gen  1KB 
segments_1   1KB 
write.lock   0KB 

私はインデックスを作成したいから、そのようなモデルがあります:

public class Feed : BaseEntity 
{ 

    public virtual string Address { get; set; } 

    public virtual string Title { get; set; } 

    public virtual string Description { get; set; } 

    public virtual bool IsExported { get; set; } 

    public virtual DateTime LastUpdateTime { get; set; } 

    public virtual int UserId { get; set; } 

    public virtual User User { get; set; } 

    public virtual ICollection<FeedPost> Posts { get; set; } 

    public virtual ICollection<Tag> Tags { get; set; } 

    public virtual Filter Filter { get; set; } 
} 
をIIndexDefinitionとIResultDefinition:私はLuceneのライブラリからの二つ必要なインタフェースを実装している

0123:

public class FeedIndexDefinition : IIndexDefinition<Feed> 
{ 
    public Document Convert(Feed entity) 
    { 
     var document = new Document(); 
     document.Add(new Field("id", entity.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); 
     document.Add(new Field("description", entity.Description, Field.Store.YES, Field.Index.ANALYZED)); 
     document.Add(new Field("title", entity.Title, Field.Store.YES, Field.Index.ANALYZED)); 
     return document; 
    } 

    public Term GetIndex(Feed entity) 
    { 
     return new Term("id", entity.Id.ToString()); 
    } 
} 


public class SearchResultDefinition : IResultDefinition<Feed> 
{ 
    public Feed Convert(Document document) 
    { 
     Guid id = Guid.Parse(document.GetValue<String>("id")); 
     var context = new UnitOfWork(); 
     Feed feed = context.FeedRepository.GetById(id); 
     return feed; 
    } 
} 

インデックスはこのように行われます

private static readonly UnitOfWork Context = new UnitOfWork(); 
    public static void IndexAllFeeds() 
    { 
     var indexWriter = new DirectoryIndexWriter(new DirectoryInfo(IndexPath), true); 
     var feeds = Context.FeedRepository.Get().AsEnumerable(); 
     var indexService = new IndexService(indexWriter); 
     IEnumerable<Feed> array = feeds.ToList(); 
     indexService.IndexWriter.IndexOptions.OptimizeIndex = true; 
     indexService.IndexEntities(array, new FeedIndexDefinition()); 
    } 

そしてここでは、検索

public FeedQuery Search(string keywords) 
    { 
     if(!String.IsNullOrEmpty(keywords)) 
     { 
      String[] fields = {"title", "description"}; 
      var parser = new MultiFieldQueryParser(
       Lucene.Net.Util.Version.LUCENE_29, 
       fields, 
       new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)); 
      Query q = parser.Parse(keywords); 
      this.AddQuery(q); 
     } 
     return this; 
    } 

を実行するクエリを作成し、最終的にここに誰かができる場合の結果

private static IEnumerable<Feed> SearchUserFeeds(string keywords) 
    { 
     keywords = "title5 description5 title4 description4 title3 description3"; 
     IEnumerable<Feed> searchResults; 
     var indexSearcher = new DirectoryIndexSearcher(new DirectoryInfo(LuceneHelper.IndexPath)); 
     using (var searchService = new SearchService(indexSearcher)) 
     { 
      var query = new FeedQuery().Search(keywords); 
      searchResults = searchService.SearchIndex(query.Query, new SearchResultDefinition()).Results; 
     } 
     return searchResults; 
    } 

を見つける必要があり、コントローラのメソッドである方法であり、私が感謝する問題に私を指摘する。

答えて

1

IndexWriterが閉じられていない、またはフラッシュされていない間は、OKです。

これはライターを閉じた後に、インデックスの凝視がある場合 - という名前のサードパーティ製のJavaツールlukeall

+0

でインデックスを検討してみてくださいしかし、私は)(Closeメソッドのフラッシュの任意の種類()内はありません。私のindexWriterまたはindexServiceオブジェクト – RomanKapitonov

+0

間違いなくそれはClose()とDispose()を持っています –

+0

そうです。最初に気づかなかった。ご協力いただきありがとうございます。 – RomanKapitonov

関連する問題