2012-05-03 3 views
0

Lucene을 사용하여 IList를 인덱싱하는 지루한 문제가 있습니다. 또한Hibernate Search와 ILene의 Lucene 초기 인덱싱

[ScriptIgnore] //will not serialize 
[IndexedEmbedded(Depth = 1, Prefix = "BookAdditionalInfos_"] 
public virtual IList<BookAdditionalInfo> BookAdditionalInfos { get; set; } 

, 인덱싱 필드 속성에 사용되는 몇 가지 다른 속성 : 인덱싱 엔티티를 표시 한 후

[Field(Index.Tokenized, Store = Store.Yes)] 

, 내가해야

내 기업은이 같은 IndexedEmbedded 특성을 적용은 IList 포함 일괄 처리를 사용하여 12 백만 행의 초기 색인 생성 BookAdditionalInfos라는 IList를 색인하기 시작할 때까지 모든 것이 완벽하게 작동합니다. 이 IndexedEmbedded 속성이 없으면 (또는이 IList를 인덱싱하지 않으면) 모든 것이 정상이며 Field 속성이있는 모든 속성 표시가 인덱싱됩니다.

Fluent NHibernate를 사용하고 있습니다.

무엇이 문제입니까? 또한 내가 http://ayende.com/blog/3992/nhibernate-search 보았다, 그러나 어떤 결과

없이 문제는 다음과 같습니다 :

당신에게

편집 감사 내가 색인 영원히 복용하고 아무것도 색인이되지 않습니다, 색인은 IList하려고 할 때. 이 IList를 인덱싱하지 않고 (또는 IList에 IndexedEmbedded을 지정하지 않고) 인덱싱은 정상적으로 수행되며 인덱싱 된 결과가 표시됩니다.

EDIT (초기 인덱싱 기능) : 당신이 거기에 고전 N + 1 개 선택 문제가 생겼어요처럼

public void BuildInitialBookSearchIndex() 
     { 
      FSDirectory directory = null; 
      IndexWriter writer = null; 

      var type = typeof(Book); 

      var info = new DirectoryInfo(GetIndexDirectory()); 

      //if (info.Exists) 
      //{ 
      // info.Delete(true); 
      //} 

      try 
      { 
       directory = FSDirectory.GetDirectory(Path.Combine(info.FullName, type.Name), true); 
       writer = new IndexWriter(directory, new StandardAnalyzer(), true); 
      } 
      finally 
      { 
       if (directory != null) 
       { 
        directory.Close(); 
       } 

       if (writer != null) 
       { 
        writer.Close(); 
       } 
      } 

      var fullTextSession = Search.CreateFullTextSession(Session); 

      var currentIndex = 0; 
      const int batchSize = 5000; 

      while (true) 
      { 
       var entities = Session 
        .CreateCriteria<Book>() 
        .SetFirstResult(currentIndex) 
        .SetMaxResults(batchSize) 
        .List(); 

       using (var tx = Session.BeginTransaction()) 
       { 
        foreach (var entity in entities) 
        { 
         fullTextSession.Index(entity); 
        } 

        currentIndex += batchSize; 

        Session.Flush(); 
        tx.Commit(); 
        Session.Clear(); 
       } 

       if (entities.Count < batchSize) 
        break; 
      } 
     } 
+0

무엇이 문제입니까? 던져지는 예외가 있습니까? –

+0

은 예외를 throw하지 않습니다. 위의 질문에 12 백만 행을 인덱싱하는 데 사용하는 초기 인덱싱 기능이 제공됩니다. IList가 IndexedEmbedded으로 표시 될 때이 함수에 몇 가지 문제가 있다고 생각합니다. – Koste

+1

문제가 무엇을 의미하는지 혼란 스럽습니다. 아무런 예외도 던지지 않고 있습니다. 영원히 받아 들여지고 있습니까? 필드를 잘못 인덱싱합니까? – Prescott

답변

0

그것은 나에게 보이는 - 당신은 당신의 책을 선택할 때 기본적으로, 당신은있어 또한 BookAdditionalInfos를 선택하지 않기 때문에, NHibernate는 각 책에 대해 새로운 select를 발행하여 인덱싱하는 동안 해당 책의 BookAdditionalInfo를 검색해야합니다. 빠른 수정 변경하는 것입니다 귀하의 선택에 :

var entities = Session 
       .CreateCriteria<Book>() 
       .SetFetchMode("BookAdditionalInfos", FetchMode.Eager) 
       .SetResultTransformer(Transformers.DistinctRootEntity) 
       .SetFirstResult(currentIndex) 
       .SetMaxResults(batchSize) 
       .List(); 

그것은이 같은 엔티티 당신에게 여러 행을주는 BookAdditionalInfo 테이블에 가입 할 것이기 때문에 당신은 아마 지금 그러나 페이징에 추가 문제로 실행하겠습니다 결과 세트에 다음과 같이보고 싶을 수도 있습니다.

var pagedEntities = DetachedCriteria.For<Book>() 
       .SetFirstResult(currentIndex) 
       .SetMaxResults(batchSize) 
       .SetProjection(Projections.Id()); 

    var entities = Session 
       .CreateCriteria<Book>() 
       .Add(Property.ForName("id").In(pagedEntities)) 
       .SetFetchMode("BookAdditionalInfos", FetchMode.Eager) 
       .SetResultTransformer(Transformers.DistinctRootEntity) 
       .List(); 
+0

Martin, 답변 해 주셔서 감사합니다. 나는이 해결책을 시도하지만 결과는 없다. BookAdditionalInfos도 가져 오려고했지만 인덱스하지 않았습니다. 제네릭 목록이 IndexedEmbedded 인 경우 어떤 책도 인덱싱되지 않습니다. 해결 방법을 만들었습니다. BookAdditionalInfo 클래스에 대한 색인을 생성하고 Book에 대한 참조를 유지하고 Book 엔티티를 IndexedEmbedded로 표시하면 모든 것이 정상입니다. 두 번째 제안에 감사드립니다. – Koste

관련 문제