예제 #1
0
        private void BtnFind_Click(object sender, EventArgs e)
        {
            int iMaxResult = 1000;

            if (CheckTextBoxNotNull(TxtMaxResult))
            {
                Int32.TryParse(TxtMaxResult.Text, out iMaxResult);
            }
            if (iMaxResult < 1)
            {
                iMaxResult = 1000;
            }
            TxtMaxResult.Text = iMaxResult.ToString();

            BooleanQuery allQuery = new BooleanQuery();

            TermRangeQuery queryFromTo = null;
            string         sFrom       = DateTools.DateToString(DPickerFrom.Value, DateTools.Resolution.MINUTE);
            string         sTo         = DateTools.DateToString(DPickerTo.Value, DateTools.Resolution.MINUTE);

            if (RdBtnSentOn.Checked) //Sent
            {
                if (DPickerFrom.Checked && DPickerTo.Checked)
                {
                    queryFromTo = new TermRangeQuery("SentOn", sFrom, sTo, true, true);
                }
                else if (DPickerFrom.Checked && !DPickerTo.Checked)
                {
                    queryFromTo = new TermRangeQuery("SentOn", sFrom, null, true, true);
                }
                else if (!DPickerFrom.Checked && DPickerTo.Checked)
                {
                    queryFromTo = new TermRangeQuery("SentOn", null, sTo, true, true);
                }
            }
            else
            {
                if (DPickerFrom.Checked && DPickerTo.Checked)
                {
                    queryFromTo = new TermRangeQuery("ReceivedOn", sFrom, sTo, true, true);
                }
                else if (DPickerFrom.Checked && !DPickerTo.Checked)
                {
                    queryFromTo = new TermRangeQuery("ReceivedOn", sFrom, null, true, true);
                }
                else if (!DPickerFrom.Checked && DPickerTo.Checked)
                {
                    queryFromTo = new TermRangeQuery("ReceivedOn", null, sTo, true, true);
                }
            }

            if (queryFromTo != null)
            {
                allQuery.Add(queryFromTo, Occur.MUST);
            }

            Lucene.Net.Analysis.Standard.StandardAnalyzer analyzer = MyLucene.GetAnalyzer();
            if (CheckTextBoxNotNull(TxtBody))
            {
                Query querySubject = MyLucene.GetTextQuery("Subject", TxtBody.Text, analyzer);
                if (ChkSubject.Checked)
                {
                    allQuery.Add(querySubject, Occur.MUST);
                }
                else
                {
                    BooleanQuery query2    = new BooleanQuery();
                    Query        queryBody = MyLucene.GetTextQuery("Body", TxtBody.Text, analyzer);
                    query2.Add(querySubject, Occur.SHOULD);
                    query2.Add(queryBody, Occur.SHOULD);
                    allQuery.Add(query2, Occur.MUST);
                }
            }

            if (CheckTextBoxNotNull(TxtReceiver))
            {
                BooleanQuery qReceiver = new BooleanQuery();
                Query        qTo       = MyLucene.GetTextQuery("To", TxtReceiver.Text, analyzer);
                Query        qCC       = MyLucene.GetTextQuery("CC", TxtReceiver.Text, analyzer);
                qReceiver.Add(qTo, Occur.SHOULD);
                qReceiver.Add(qCC, Occur.SHOULD);
                allQuery.Add(qReceiver, Occur.MUST);
            }

            if (CheckTextBoxNotNull(TxtSender))
            {
                BooleanQuery query3       = new BooleanQuery();
                Query        qSender      = MyLucene.GetTextQuery("SenderName", TxtSender.Text, analyzer);
                Query        qSenderEmail = MyLucene.GetTextQuery("SenderEmailAddress", TxtSender.Text, analyzer);
                query3.Add(qSender, Occur.SHOULD);
                query3.Add(qSenderEmail, Occur.SHOULD);
                allQuery.Add(query3, Occur.MUST);
            }

            if (string.IsNullOrEmpty(allQuery.ToString()))
            {
                MessageBox.Show("Vui lòng chọn điều kiện", "Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Information); return;
            }

            IndexSearcher searcher = MyLucene.GetSearcher();

            lst = MyLucene.Search(searcher, allQuery, iMaxResult);
            searcher.Dispose();
            analyzer.Dispose();

            dt.Clear();
            for (int i = 0; i < lst.Count; i++)
            {
                MailData mailData = lst[i];
                object[] row      = { i, mailData.DSentOn, mailData.SenderEmailAddress, mailData.Subject, mailData.DReceivedOn };
                dt.Rows.Add(row);
            }
            bindingSource1.DataSource = dt;
        }
예제 #2
0
        public WorkerThreadResult RunMT(bW1Arg arg)
        {
            WorkerThreadResult result = new WorkerThreadResult();

            string indexPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "LuceneData");

            Lucene.Net.Store.Directory directory = Lucene.Net.Store.FSDirectory.Open(indexPath);
            Lucene.Net.Analysis.Standard.StandardAnalyzer analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);

            Worker workerObject = new Worker();

            workerObject.Writer      = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED);
            workerObject.ConStackLog = ErrLog;
            workerObject.SetRAMBufferSizeMB();

            List <FileMeta> LstMsgFile = MyIO.GetFileMsgFromTo(MyConfig.GetMailFolder(), arg.DFrom, arg.DTo);

            if (arg.IsReIndex)
            {
                workerObject.DeleteAllDocuments();
            }
            else
            {
                //Xoa bo nhung item trung lap giua list moi tao va du lieu da index
                using (Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(directory))
                {
                    for (int i = LstMsgFile.Count - 1; i >= 0; i--)
                    {
                        if (MyLucene.CheckDocExist(searcher, LstMsgFile[i]))
                        {
                            LstMsgFile.RemoveAt(i);
                            result.IncreaseNumDupFiles();
                        }
                    }
                }
            }

            //Chay song song
            ParallelLoopResult pResult = Parallel.ForEach(LstMsgFile, (currentFileMeta) => workerObject.DoWork(currentFileMeta));

            StringBuilder sb = new StringBuilder();

            if (pResult.IsCompleted)
            {
                workerObject.DisposeWriter();
                analyzer.Dispose();
                directory.Dispose();

                result.FileDone = LstMsgFile;

                int i = 0;
                foreach (var a in ErrLog)
                {
                    string item;
                    ErrLog.TryPop(out item);
                    i++;
                    sb.Append(i.ToString());
                    sb.Append(". ");
                    sb.Append(item);
                    sb.Append(Environment.NewLine);
                }
                result.ErrLog = sb.ToString();
            }
            return(result);
        }
예제 #3
0
        public WorkerThreadResult RunMT(List <FileMeta> LstMsgFile, bool IsReIndex)
        {
            WorkerThreadResult result = new WorkerThreadResult();

            string indexPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "LuceneData");

            Lucene.Net.Store.Directory directory = Lucene.Net.Store.FSDirectory.Open(indexPath);
            Lucene.Net.Analysis.Standard.StandardAnalyzer analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);

            Worker2 workerObject = new Worker2();

            workerObject.Writer      = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED);
            workerObject.ConStackLog = ErrLog;
            workerObject.SetRAMBufferSizeMB();

            if (IsReIndex)
            {
                workerObject.DeleteAllDocuments();
            }
            else
            {
                //Xoa bo nhung item trung lap giua list moi tao va du lieu da index
                using (Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(directory))
                {
                    for (int idx2 = LstMsgFile.Count - 1; idx2 >= 0; idx2--)
                    {
                        if (MyLucene.CheckDocExist(searcher, LstMsgFile[idx2]))
                        {
                            LstMsgFile.RemoveAt(idx2);
                            result.IncreaseNumDupFiles();
                        }
                    }
                }
            }
            //Chia list thanh cac list con
            int chunkSize = 200;
            int maxThread = 25;

            int totalItem = LstMsgFile.Count;
            int numThread = totalItem / chunkSize;

            if (numThread > maxThread)
            {
                numThread = maxThread;
                chunkSize = totalItem / maxThread;
            }
            if (totalItem % chunkSize != 0)
            {
                numThread++;
            }

            List <List <FileMeta> > lst1 = new List <List <FileMeta> >();

            for (int idx = 0; idx < totalItem; idx++)
            {
                int iMin = idx * chunkSize;
                int iMax = iMin + chunkSize;
                if (iMax > totalItem)
                {
                    iMax = totalItem;
                }
                List <FileMeta> lst2 = new List <FileMeta>();
                for (int j = iMin; j < iMax; j++)
                {
                    lst2.Add(LstMsgFile[j]);
                }
                if (lst2.Count != 0)
                {
                    lst1.Add(lst2);
                }
            }

            //Chay song song
            List <Thread> lstTask = new List <Thread>();

            foreach (var item in lst1)
            {
                Thread thread = new Thread(workerObject.DoWork);
                thread.Start(item);
                lstTask.Add(thread);
            }

            //Cho cho den khi cac thread chay xong moi chay tiep
            foreach (var th in lstTask)
            {
                th.Join();
            }

            //Luu du lieu
            workerObject.DisposeWriter();
            analyzer.Dispose();
            directory.Dispose();

            result.FileDone = LstMsgFile;

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < ErrLog.Count; i++)
            {
                string item = ErrLog.Pop();
                sb.Append((i + 1).ToString());
                sb.Append(". ");
                sb.Append(item);
                sb.Append(Environment.NewLine);
            }
            result.ErrLog = sb.ToString();
            return(result);
        }