Esempio n. 1
0
        private void btnDBCreateIndex_Click(object sender, EventArgs e)
        {

            StringBuffer sql = "SELECT TOP 1000 Id,FirstName,LastName FROM Person(NOLOCK)";
            try
            {
                IList<Person> listPersons = EntityConvertor.QueryForList<Person>(sql.ToString(), strSqlConn, null);
                SetOutput("======================DB索引创建开始===============================");
                IndexModifier modifier = new IndexModifier(INDEX_STORE_PATH, new StandardAnalyzer(), true);

                #region 同步创建索引

                Stopwatch watch = new Stopwatch();
                watch.Start();
                IndexDB(modifier, listPersons);
                modifier.Optimize();//优化索引
                modifier.Close();//关闭索引读写器
                watch.Stop();
                StringBuffer sb = "索引完成,共用时:" + watch.Elapsed.Hours + "时 " + watch.Elapsed.Minutes + "分 " + watch.Elapsed.Seconds + "秒 " + watch.Elapsed.Milliseconds + "毫秒";
                SetOutput(sb);

                #endregion

                //#region 异步创建索引

                //dtStart = DateTime.Now;
                //AsyncIndexDBCaller caller = new AsyncIndexDBCaller(IndexDB);
                //IAsyncResult ar = caller.BeginInvoke(modifier, listPersons, new AsyncCallback(IndexCallback), modifier);

                //#endregion
            }
            catch (Exception ex)
            {
                SetOutput(ex.Message);
            }
        }