【发布时间】:2011-01-31 09:43:20
【问题描述】:
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){}
}
【问题讨论】:
-
您在应用程序启动时到底在做什么?那里真的有必要吗?您是否尝试过使用秒表查看您的任务需要多长时间? msdn.microsoft.com/en-us/library/…
-
你说的慢是什么意思..程序甚至没有响应或者需要很多时间..
-
好的,请问你建议我把这段代码也移到哪里????我正在尝试从 ms word docs 创建一个 lucene 索引...