2011-01-31 3 views
0
void Application_Start(object sender, EventArgs e) 
{ 
    Thread thread = new Thread(new ThreadStart(createIndex)); 
    thread.Start(); 
} 
void createIndex() 
{ 
    string constring = "server=localhost;port=3306;database=hr;uid=root;password=root" ; 
    String luceneIndexDirectory = @"C:\Index"; 

    try 
    { 
     SimpleAnalyzer analyzer = new SimpleAnalyzer(); 
     Directory directory = new SimpleFSDirectory(new File(luceneIndexDirectory)); 
     IndexWriter iwriter = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED); 

     MySqlConnection con = new MySqlConnection(constring); 
     MySqlCommand com = new MySqlCommand("select emp_id , emp_resume from emp;", con); 
     con.Open(); 
     MySqlDataReader dr = com.ExecuteReader(); 
     object objPath = null; 
     object missing = System.Reflection.Missing.Value; 
     object objTrue = true; 
     object objFalse = false; 
     Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); 
     while (dr.Read()) 
     { 
      objPath = Server.MapPath("~") + @"\Cnd_Resume\" + dr.GetString(1); 
      if(System.IO.File.Exists(Convert.ToString(objPath))) 
      { 
       Microsoft.Office.Interop.Word.Document d = wordApp.Documents.Open(ref objPath, ref objFalse, ref objTrue, 
        ref objFalse, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, 
        ref objFalse, ref missing, ref missing, ref missing, ref missing); 

       Document doc = new Document(); 

       doc.add(new Field("id", dr.GetString(0) , Field.Store.YES , Field.Index.NOT_ANALYZED)); 

       doc.add(new Field("name", dr.GetString(1), Field.Store.YES, Field.Index.NOT_ANALYZED)); 

       doc.add(new Field("contents", d.Content.Text, Field.Store.NO, Field.Index.ANALYZED)); 

       d.Close(ref missing, ref missing, ref missing); 

       iwriter.addDocument(doc); 
      } 
     } 

     iwriter.optimize(); 
     iwriter.close(); 
    } 
    catch (Exception ex){} 

} 
+1

어플에서 시작한 것은 무엇입니까? 거기 정말 필요한가요? 스톱워치를 사용하여 작업 시간을 확인해 보았습니까? http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx – Hawxby

+1

느린 말은 .. 프로그램이 응답하지 않거나 시간이 많이 걸리는 것입니다 .. –

+0

ok please 당신도이 코드를 옮길 것을 제안합니까? 나는 ms 워드 문서에서 lucene 색인을 만들려고 노력 중입니다 ... – richards

답변

0

나는 당신이 두 가지 문제가있을 수 있습니다 생각 :

  1. 말씀이 알고 스레드되지 않습니다. 간단히 말해, 여러 스레드를 생성하더라도 단어 자체는 한 번에 하나의 문서 만 처리합니다. 마치 싱글 톤과 같은 것입니다. 적절한 싱글 톤 구현은 멀티 스레드 환경에서이를 달성합니다. 또한, 생각할 때 - 한 번에 하나의 문서 만 편집 할 수 있습니다. 물론 여러 개의 Word UI 창을 가질 수 있지만 엔진 자체는 사용자별로 한 번에 하나의 문서 만 편집 할 수 있습니다.

  2. MySQL 쿼리가 실행되는 데 너무 오래 걸립니다.