2011-10-11 5 views
0

Lucene.net50K 엔티티에서 검색하려면 사용하고 있습니다. 이러한 엔티티는 데이터베이스에 저장됩니다. 나는 응용 프로그램 마녀를 만들었습니다 때마다 엔티티를 색인하려고합니다. lucene.net 색인 속도 감소

코드

은 매우 간단합니다 :

var entityList = GetEntityList(100); 

foreach (var item in entityList) 
    Indexer.IndexEntity(item); 

을 그리고이 인덱서 클래스입니다 :

public class Indexer { 
    public void IndexEntity(Entity item) 
    { 
     IndexWriter writer; 
     string path = ConfigurationManager.AppSettings["SearchIndexPath"]; 
     FSDirectory directory = FSDirectory.Open(new DirectoryInfo(path)); 
     Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_29); 
     if (Directory.GetFiles(path).Length > 0) 
      writer = new IndexWriter(directory, analyzer, false, IndexWriter.MaxFieldLength.UNLIMITED); 
     else 
      writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED); 
     Document document = new Document(); 
     document.Add(new Field("id", item.Id.ToString(), Field.Store.YES, Field.Index.NO, Field.TermVector.NO)); 
     document.Add(new Field("category", item.Category.Id.ToString(), Field.Store.YES, Field.Index.NO, Field.TermVector.NO)); 
     document.Add(new Field("location", item.Location.Id.ToString(), Field.Store.YES, Field.Index.NO, Field.TermVector.NO)); 
     document.Add(new Field("point", item.Point.ToString(), Field.Store.YES, Field.Index.NO, Field.TermVector.NO)); 
     document.Add(new Field("picture", item.PictureUrl, Field.Store.YES, Field.Index.NO, Field.TermVector.NO)); 
     document.Add(new Field("creationdate", item.CreationDate.ToString(), Field.Store.YES, Field.Index.NO, Field.TermVector.NO)); 
     document.Add(new Field("title", item.Title, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES)); 
     document.Add(new Field("body", item.Body, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES)); 
     string str2 = string.Empty; 
     foreach (Tag tag in item.Tags) 
     { 
      if (!string.IsNullOrEmpty(str2)) 
      { 
       str2 = str2 + "-"; 
      } 
      str2 = str2 + tag.DisplayName; 
     } 
     document.Add(new Field("tags", str2, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES)); 
     writer.AddDocument(document); 
     writer.Optimize(); 
     writer.Close(); 
    } 
} 

모든 것은 괜찮다고 내 검색 속도가 지금 충분히 좋다. 문제는의 색인 속도가 으로 감소한 것입니다. 내 응용 프로그램은 지금까지 약 15K 개체에 대한 색인이 생성되고 색인 파일 크기는 약 600MB입니다. 이제 새로운 엔티티 100 개를 인덱싱하려면 약 약 24 분이 소요됩니다!

무엇이 문제입니까? 미리 감사드립니다.

답변

5

두 가지 코드에서 꽤 명확하게 눈에 띄는 : 모든 문서를 추가 한 후 인덱스를 최적화하고

  1. . 최근 버전의 Lucene에는 인덱스를 최적화하지 않아도 (세그먼트 별 캐싱 당) 인덱스를 최적화하지 않아도되고 모든 문서를 추가 한 후에 인덱스를 최적화하는 것이 매우 적합합니다.
  2. 지속적으로 열고 닫는 중입니다./귀하의 색인 커밋. 루핑 구조를 감안할 때 루프 외부에서 인덱스 작성기를 열고 엔터티를 추가 한 다음 닫기/커밋하십시오. 당신이 빠른 인덱스 가시성을해야하는 경우 계수 연산의 어떤 종류에 따라 루프 (에 주기적 커밋 명령을 추가 할 수 있습니다 것은 나에게 OK 소리가 난다.이 두 가지 변화와

, 나는 당신이 극적인 속도 업을 볼 수있을 거라 생각

+0

색인을 전혀 최적화해서는 안된다는 뜻입니까? –

+0

색인 작성기 병합 인수 (최적화와 비슷한 효과가 있음)를 사용하면 가치가있을 수 있지만, –

+0

덩어리, 45 초에서 50 초로 줄었고 100 개 항목마다 인덱스가 최적화되었습니다. +1 (동의) –