コード例 #1
0
        private void UpdateListView(UpdateLVMethod method, int currentPage)
        {
            int TotalRecord     = this.topDocs.scoreDocs.Length - ((this.currentPage - 1) * Static.PageItems); //总的数据项数
            int EveryTimeRecord = 40;                                                                          //每次批量增加的数量
            int TotalTimes      = TotalRecord / EveryTimeRecord;                                               //批量添加的执行次数
            int indexStart      = (this.currentPage - 1) * Static.PageItems;                                   //开始的index
            int indexRecord     = indexStart;

            ScoreDoc[] scoreDocs = this.topDocs.scoreDocs;
            for (int i = 0; i <= TotalTimes; i++)
            {
                if (this.isStopSearch == true)
                {
                    return;
                }

                ListViewItem[] items;

                if (i < TotalTimes) //i不是最后一次执行
                {
                    method(out items, ref scoreDocs, ref indexRecord, EveryTimeRecord);
                }
                else
                {
                    int lastQuantity = TotalRecord + indexStart - indexRecord;
                    method(out items, ref scoreDocs, ref indexRecord, lastQuantity);
                }

                CrossThreadOperateControl CrossUpdateListView = delegate()
                {
                    lock (this.form.lvwFiles)
                    {
                        this.form.lvwFiles.BeginUpdate();
                        //利用AddRange批量增加,目的是减少刷屏次数,减轻不断闪烁问题。
                        this.form.lvwFiles.Items.AddRange(items);
                        this.form.lvwFiles.EndUpdate();
                    }
                };
                this.form.lvwFiles.Invoke(CrossUpdateListView);
            }
        }
コード例 #2
0
        /// <summary>
        /// 获取当前页码所在页的数据并更新ListView
        /// </summary>
        public void GetCurrentPage()
        {
            try
            {
                this.topDocs = this.indexSearcher.Search(boolQuery, Static.PageItems * this.currentPage);
            }
            catch (Exception)
            {
                this.NullResult(); //空结果,修改主窗的status状态。
                this.CallBack();   //线程执行完,修改主窗的相关属性。
                return;
            }
            UpdateLVMethod method;

            switch (this.searchMode)
            {
            case SearchMode.File:
                method = new UpdateLVMethod(this.UpdateFileListView);
                break;

            case SearchMode.MP3:
                method = new UpdateLVMethod(this.UpdateMP3ListView);
                break;

            default:
                method = new UpdateLVMethod(this.UpdateMP3ListView);
                break;
            }

            this.UpdateListView(method, this.currentPage);

            CrossThreadOperateControl CrossOperate = delegate()
            {
                this.form.IsSearch = false;
                this.form.索引ToolStripMenuItem.Enabled   = true;
                this.form.保存结果ToolStripMenuItem.Enabled = true;
            };

            this.form.Invoke(CrossOperate);
        }
コード例 #3
0
        /// <summary>
        /// 搜索文件
        /// </summary>
        public void SearchFile()
        {
            this.isStopSearch = false;
            this.dtStart      = DateTime.Now;//开始时间

            if (this.indexSearcher == null)
            {
                this.NullResult(); //空结果,修改主窗的status状态。
                this.CallBack();   //线程执行完,修改主窗的相关属性。
                return;
            }

            Query query;

            if (this.keyword.Name != "")
            {
                try
                {
                    QueryParser parser = new QueryParser("Name", this.analyzer);
                    query = parser.Parse(this.keyword.Name);
                    boolQuery.Add(query, BooleanClause.Occur.MUST);
                }
                catch (Exception)
                { }
            }

            if (this.keyword.Directory != null && this.keyword.Directory != "")
            {
                PrefixQuery pq = new PrefixQuery(new Term("Directory", this.keyword.Directory));
                boolQuery.Add(pq, BooleanClause.Occur.MUST);
            }

            if (this.keyword.Extension != null && this.keyword.Extension != "")
            {
                TermQuery termQuery = new TermQuery(new Term("Extension", this.keyword.Extension));
                boolQuery.Add(termQuery, BooleanClause.Occur.MUST);
            }

            try
            {
                //搜索前Static.PageItems项
                this.topDocs = this.indexSearcher.Search(boolQuery, Static.PageItems);
            }
            catch (Exception)
            {
                this.NullResult(); //空结果,修改主窗的status状态。
                this.CallBack();   //线程执行完,修改主窗的相关属性。
                return;
            }

            this.dtStop = DateTime.Now;//完成时间
            if (this.topDocs.totalHits > 0)
            {
                CrossThreadOperateControl CrossUpdateStatus = delegate()
                {
                    lock (this.form.tsslStatus)
                    {
                        this.form.OrginalStatusText = Deal.ToEnglishNumString(this.topDocs.totalHits)
                                                      + " 个对象     用时:" + (this.dtStop - this.dtStart).TotalSeconds + "秒";
                        this.form.tsslStatus.Text = Deal.LimitStringLength(this.form.OrginalStatusText,
                                                                           this.form.TsslLength);
                    }
                };
                this.form.Invoke(CrossUpdateStatus);
            }
            else
            {
                this.NullResult(); //空结果,修改主窗的status状态。
                this.CallBack();   //线程执行完,修改主窗的相关属性。
                return;
            }

            this.pageNums    = topDocs.totalHits / Static.PageItems + 1; //总的页数
            this.currentPage = 1;                                        //每次搜索时当前页数为1

            UpdateLVMethod method = new UpdateLVMethod(this.UpdateFileListView);

            this.UpdateListView(method, this.currentPage);
            this.CallBack();//线程执行完,修改主窗的相关属性。
        }
コード例 #4
0
ファイル: Search.cs プロジェクト: cqm0609/lucene-file-finder
        private void UpdateListView(UpdateLVMethod method, int currentPage)
        {
            int TotalRecord = this.topDocs.scoreDocs.Length - ((this.currentPage - 1) * Static.PageItems);//总的数据项数
            int EveryTimeRecord = 40; //每次批量增加的数量
            int TotalTimes = TotalRecord / EveryTimeRecord;//批量添加的执行次数
            int indexStart = (this.currentPage - 1) * Static.PageItems;//开始的index
            int indexRecord = indexStart;
            ScoreDoc[] scoreDocs = this.topDocs.scoreDocs;
            for (int i = 0; i <= TotalTimes; i++)
            {
                if (this.isStopSearch == true)
                    return;

                ListViewItem[] items;

                if (i < TotalTimes) //i不是最后一次执行
                {
                    method(out items, ref scoreDocs, ref indexRecord, EveryTimeRecord);
                }
                else
                {
                    int lastQuantity = TotalRecord + indexStart - indexRecord;
                    method(out items, ref scoreDocs, ref indexRecord, lastQuantity);
                }

                CrossThreadOperateControl CrossUpdateListView = delegate()
                {
                    lock (this.form.lvwFiles)
                    {
                        this.form.lvwFiles.BeginUpdate();
                        //利用AddRange批量增加,目的是减少刷屏次数,减轻不断闪烁问题。
                        this.form.lvwFiles.Items.AddRange(items);
                        this.form.lvwFiles.EndUpdate();
                    }
                };
                this.form.lvwFiles.Invoke(CrossUpdateListView);
            }
        }
コード例 #5
0
ファイル: Search.cs プロジェクト: cqm0609/lucene-file-finder
        /// <summary>
        /// 搜索MP3
        /// </summary>
        public void SearchMP3()
        {
            this.isStopSearch = false;
            this.dtStart = DateTime.Now;//搜索开始

            if (this.indexSearcher == null)
            {
                this.NullResult();//空结果,修改主窗的status状态。
                this.CallBack();//线程执行完,修改主窗的相关属性。
                return;
            }

            Query query;

            if (this.keyword.Name != "")
            {
                try
                {
                    MultiFieldQueryParser parser = new MultiFieldQueryParser(this.mp3Fields, this.analyzer);
                    query = parser.Parse(this.keyword.Name);
                    boolQuery.Add(query, BooleanClause.Occur.MUST);
                }
                catch (Exception)
                { }
            }

            if (this.keyword.Directory != null && this.keyword.Directory != "")
            {
                PrefixQuery pq = new PrefixQuery(new Term("Directory", this.keyword.Directory));
                boolQuery.Add(pq, BooleanClause.Occur.MUST);
            }

            if (this.keyword.Artist != null)
            {
                TermQuery term = new TermQuery(new Term("ArtistStore", this.keyword.Artist));
                boolQuery.Add(term, BooleanClause.Occur.MUST);
            }

            try
            {
                //搜索前Static.PageItems项
                this.topDocs = this.indexSearcher.Search(boolQuery, Static.PageItems);
            }
            catch (Exception)
            {
                this.NullResult();//空结果,修改主窗的status状态。
                this.CallBack();//线程执行完,修改主窗的相关属性。
                return;
            }

            this.dtStop = DateTime.Now;//完成时间
            if (this.topDocs.totalHits > 0)
            {
                CrossThreadOperateControl CrossUpdateStatus = delegate()
                {
                    this.form.OrginalStatusText = Deal.ToEnglishNumString(this.topDocs.totalHits)
                        + " 个对象     用时:" + (this.dtStop - this.dtStart).TotalSeconds + "秒";
                    this.form.tsslStatus.Text = Deal.LimitStringLength(this.form.OrginalStatusText,
                        this.form.TsslLength);
                };
                this.form.Invoke(CrossUpdateStatus);
            }
            else
            {
                this.NullResult();//空结果,修改主窗的status状态。
                this.CallBack();//线程执行完,修改主窗的相关属性。
                return;
            }

            this.pageNums = topDocs.totalHits / Static.PageItems + 1;//总的页数
            this.currentPage = 1;//每次搜索时当前页数为1

            UpdateLVMethod method = new UpdateLVMethod(this.UpdateMP3ListView);
            this.UpdateListView(method, this.currentPage);
            this.CallBack();//线程执行完,修改主窗的相关属性。
        }
コード例 #6
0
ファイル: Search.cs プロジェクト: cqm0609/lucene-file-finder
        /// <summary>
        /// 获取当前页码所在页的数据并更新ListView
        /// </summary>
        public void GetCurrentPage()
        {
            try
            {
                this.topDocs = this.indexSearcher.Search(boolQuery, Static.PageItems * this.currentPage);
            }
            catch (Exception)
            {
                this.NullResult();//空结果,修改主窗的status状态。
                this.CallBack();//线程执行完,修改主窗的相关属性。
                return;
            }
            UpdateLVMethod method;
            switch (this.searchMode)
            {
                case SearchMode.File:
                    method = new UpdateLVMethod(this.UpdateFileListView);
                    break;
                case SearchMode.MP3:
                    method = new UpdateLVMethod(this.UpdateMP3ListView);
                    break;
                default:
                    method = new UpdateLVMethod(this.UpdateMP3ListView);
                    break;
            }

            this.UpdateListView(method, this.currentPage);

            CrossThreadOperateControl CrossOperate = delegate()
            {
                this.form.IsSearch = false;
                this.form.索引ToolStripMenuItem.Enabled = true;
                this.form.保存结果ToolStripMenuItem.Enabled = true;
            };
            this.form.Invoke(CrossOperate);
        }