diff --git a/README.md b/README.md index 3a0820888f42613307cbbb4cc18677eda7fe045d..e4ecd1beb922e44217d0099169aaa00ba2535257 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ #### 依赖组件 1. [Rubyer](https://gitee.com/wuyanxin1028/rubyer-wpf) 2. [Lucene.Net](http://lucenenet.apache.org) -3. [PanGu.Lucene.Analyzer](https://github.com/NeverCL/PanGu.Lucene.Analyzer) +3. [Jieba.NET](https://github.com/anderscui/jieba.NET) 4. [NPOI](https://github.com/nissl-lab/npoi) 5. [Spire.Office](https://www.e-iceblue.com/Introduce/spire-office-for-net.html) 6. [Microsoft.Office.Interop.Excel](https://www.nuget.org/packages/Microsoft.Office.Interop.Excel/) diff --git a/TextLocator/App.config b/TextLocator/App.config index 9f52dbbeac3f5aa466df0fea5a3386083781c479..b471d023241aac3d47e91e2fdb5d8fcebb2d8048 100644 --- a/TextLocator/App.config +++ b/TextLocator/App.config @@ -18,13 +18,13 @@ - + - + @@ -57,6 +57,14 @@ + + + + + + + + \ No newline at end of file diff --git a/TextLocator/Core/AppConst.cs b/TextLocator/Core/AppConst.cs index 0ac51a0a9f7183634e5d286abfe6f5027a387a76..18a107440fdd325e1c2bc75daa0320f204c56880 100644 --- a/TextLocator/Core/AppConst.cs +++ b/TextLocator/Core/AppConst.cs @@ -15,11 +15,11 @@ namespace TextLocator.Core /// /// 线程池最小数量 /// - public static readonly int THREAD_POOL_MIN_SIZE = int.Parse(AppUtil.ReadValue("ThreadPool", "MinSize", "16")); + public static readonly int THREAD_POOL_MIN_SIZE = int.Parse(AppUtil.ReadValue("ThreadPool", "MinSize", "32")); /// /// 线程池最大数量 /// - public static readonly int THREAD_POOL_MAX_SIZE = int.Parse(AppUtil.ReadValue("ThreadPool", "MaxSize", "32")); + public static readonly int THREAD_POOL_MAX_SIZE = int.Parse(AppUtil.ReadValue("ThreadPool", "MaxSize", "64")); /// /// 应用目录 /// @@ -67,5 +67,18 @@ namespace TextLocator.Core /// 匹配文件后缀 /// public static readonly Regex REGIX_FILE_EXT = new Regex(@"^.+\.(" + FileTypeUtil.GetFileTypeExts("|") + ")$"); + + /// + /// 比例最小值 + /// + public const int MIN_PERCENT = 0; + /// + /// 比例最大值 + /// + public const int MAX_PERCENT = 100; + /// + /// 文件内容缩略信息截取值 + /// + public const int FILE_CONTENT_SUB_LENGTH = 120; } } diff --git a/TextLocator/Core/AppCore.cs b/TextLocator/Core/AppCore.cs index ad88dfbbb19b64c79211e81e321c7c67647b4c89..e8de8fe3914efbd65f3ca5e7f673b6619bc875ba 100644 --- a/TextLocator/Core/AppCore.cs +++ b/TextLocator/Core/AppCore.cs @@ -1,11 +1,7 @@ using log4net; using System; -using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace TextLocator.Core { diff --git a/TextLocator/Index/IndexCore.cs b/TextLocator/Index/IndexCore.cs index d39f7ed169da30058a50be4e969c82a225f044ca..6c4e345e293f6fbdb68ecc2fcd54de71afc9770e 100644 --- a/TextLocator/Index/IndexCore.cs +++ b/TextLocator/Index/IndexCore.cs @@ -4,14 +4,10 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; -using System.Text.RegularExpressions; using System.Threading; using TextLocator.Core; using TextLocator.Enums; using TextLocator.Factory; -using TextLocator.Index; -using TextLocator.Jieba; -using TextLocator.Service; using TextLocator.Util; namespace TextLocator.Index @@ -94,6 +90,7 @@ namespace TextLocator.Index FilePath = filePaths[i], IndexWriter = indexWriter, Callback = callback, + Rebuild = rebuild, ResetEvent = resetEvent }); } @@ -139,7 +136,8 @@ namespace TextLocator.Index { string skipMsg = "跳过文件:" + filePath; - callback(skipMsg, CalcCompletionRatio(finishCount, totalCount)); + // 跳过的文件闪烁 + callback(skipMsg, CalcFinishRatio(finishCount, totalCount)); lock (locker) { @@ -169,7 +167,7 @@ namespace TextLocator.Index TaskInfo taskInfo = obj as TaskInfo; try { - // 开始时间1 + // 解析时间 var taskMark = TaskTime.StartNew(); // 索引写入 @@ -196,7 +194,7 @@ namespace TextLocator.Index string filePathPadding = filePath; try { - filePathPadding = filePath.Substring(0, 35) + "......" + filePath.Substring(filePath.Length - 35); + filePathPadding = filePath.Substring(0, 30) + "......" + filePath.Substring(filePath.Length - 30); } catch { } @@ -209,15 +207,15 @@ namespace TextLocator.Index // 缩略信息 string breviary = AppConst.REGIX_LINE_BREAKS_AND_WHITESPACE.Replace(content, ""); - if (breviary.Length > 120) + if (breviary.Length > AppConst.FILE_CONTENT_SUB_LENGTH) { - breviary = breviary.Substring(0, 120) + "..."; + breviary = breviary.Substring(0, AppConst.FILE_CONTENT_SUB_LENGTH) + "..."; } // 文件标记 string fileMark = MD5Util.GetMD5Hash(filePath); //fileInfo.DirectoryName + fileInfo.CreationTime.ToString(); - // 开始时间2 + // 索引时间 taskMark = TaskTime.StartNew(); lock (locker) @@ -243,7 +241,7 @@ namespace TextLocator.Index msg.Append(",索引:" + taskMark.ConsumeTime + "秒"); // 执行状态回调 - taskInfo.Callback(msg.ToString(), CalcCompletionRatio(finishCount, taskInfo.TotalCount)); ; + taskInfo.Callback(msg.ToString(), CalcFinishRatio(finishCount, taskInfo.TotalCount)); log.Debug(msg); } @@ -272,7 +270,7 @@ namespace TextLocator.Index /// /// /// - private static double CalcCompletionRatio(double finishCount, double totalCount) + private static double CalcFinishRatio(double finishCount, double totalCount) { return finishCount * 1.00F / totalCount * 1.00F * 100.00F; } @@ -299,6 +297,10 @@ namespace TextLocator.Index /// public Callback Callback { get; set; } /// + /// 重建 + /// + public bool Rebuild { get; set; } + /// /// 多线程重置 /// public MutipleThreadResetEvent ResetEvent { get; set; } diff --git a/TextLocator/MainWindow.xaml b/TextLocator/MainWindow.xaml index b97cb3f052884fe0eb5b8a8927ddeb80368f1385..292687d7b1ed3d9ee4bd99607162bf3f9a0cc338 100644 --- a/TextLocator/MainWindow.xaml +++ b/TextLocator/MainWindow.xaml @@ -6,7 +6,11 @@ xmlns:local="clr-namespace:TextLocator" xmlns:rubyer="clr-namespace:Rubyer;assembly=Rubyer" mc:Ignorable="d" - Title="文本搜索定位器" Width="1600" Height="900" WindowStartupLocation="CenterScreen" Icon="Resource/App.ico" Loaded="Window_Loaded"> + Title="文本搜索定位器" Width="1600" Height="900" Icon="Resource/App.ico" + WindowStartupLocation="CenterScreen" Loaded="Window_Loaded"> + + + @@ -776,7 +780,7 @@ - diff --git a/TextLocator/MainWindow.xaml.cs b/TextLocator/MainWindow.xaml.cs index 87bcf245f351b4d73baed7d6b23f544d4a744b8b..24bcada351044abf593e4155b224b370ba8ad610 100644 --- a/TextLocator/MainWindow.xaml.cs +++ b/TextLocator/MainWindow.xaml.cs @@ -62,18 +62,6 @@ namespace TextLocator // 清理事件 CleanSearchResult(); - // 检查索引是否存在 - if (CheckIndexExist()) - { - foreach(FileInfo fi in new DirectoryInfo(AppConst.APP_INDEX_DIR).GetFiles()) - { - using (StreamReader reader = new StreamReader(fi.FullName, Encoding.UTF8)) - { - reader.ReadToEnd(); - } - } - } - // 检查配置参数信息 if (string.IsNullOrEmpty(AppUtil.ReadValue("AppConfig", "MaxCountLimit", ""))) { @@ -90,6 +78,7 @@ namespace TextLocator /// private void InitializeFileTypeFilters() { + TaskTime taskTime = TaskTime.StartNew(); // 文件类型筛选下拉框数据初始化 FileTypeFilter.Children.Clear(); FileTypeNames.Children.Clear(); @@ -106,7 +95,7 @@ namespace TextLocator }; radioButtonAll.Checked += FileType_Checked; FileTypeFilter.Children.Add(radioButtonAll); - + // 获取文件类型枚举,遍历并加入下拉列表 foreach (FileType fileType in Enum.GetValues(typeof(FileType))) @@ -134,6 +123,7 @@ namespace TextLocator Background = Brushes.DarkGray }); } + log.Debug("InitializeFileTypeFilters 耗时:" + taskTime.ConsumeTime + "秒"); } /// @@ -141,6 +131,7 @@ namespace TextLocator /// private void InitializeAppConfig() { + TaskTime taskTime = TaskTime.StartNew(); // 初始化显示被索引的文件夹列表 _IndexFolders.Clear(); // 读取被索引文件夹配置信息,如果配置信息为空:默认为我的文档和我的桌面 @@ -161,6 +152,7 @@ namespace TextLocator } FolderPaths.Text = foldersText.Substring(0, foldersText.Length - 2); FolderPaths.ToolTip = FolderPaths.Text; + log.Debug("InitializeAppConfig 耗时:" + taskTime.ConsumeTime + "秒"); } #endregion @@ -203,7 +195,7 @@ namespace TextLocator } // 排序 - filePaths.Sort(); + //filePaths.Sort(); // 创建索引方法 IndexCore.CreateIndex(filePaths, rebuild, ShowStatus); @@ -232,16 +224,20 @@ namespace TextLocator /// /// 显示状态 /// - /// - /// - private void ShowStatus(string text, double percent = 100) + /// 消息 + /// 进度 + private void ShowStatus(string text, double percent = AppConst.MAX_PERCENT) { Dispatcher.BeginInvoke(new Action(() => { + WorkStatus.Text = text; - if (percent > 0) + if (percent > AppConst.MIN_PERCENT) { WorkProgress.Value = percent; - } + + TaskbarItemInfo.ProgressState = percent < AppConst.MAX_PERCENT ? System.Windows.Shell.TaskbarItemProgressState.Normal : System.Windows.Shell.TaskbarItemProgressState.None; + TaskbarItemInfo.ProgressValue = WorkProgress.Value / WorkProgress.Maximum; + } })); } diff --git a/TextLocator/Properties/AssemblyInfo.cs b/TextLocator/Properties/AssemblyInfo.cs index 8369d75cce9bb694f3af6d393ad2468ca0902d01..3866ac7456e69a42b519c8256832045bce80bfde 100644 --- a/TextLocator/Properties/AssemblyInfo.cs +++ b/TextLocator/Properties/AssemblyInfo.cs @@ -49,8 +49,8 @@ using System.Windows; //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //通过使用 "*",如下所示: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.1")] -[assembly: AssemblyFileVersion("1.1.1.1")] +[assembly: AssemblyVersion("1.2.0")] +[assembly: AssemblyFileVersion("1.2.0.0")] // log4net [assembly: log4net.Config.XmlConfigurator(Watch = true)] \ No newline at end of file diff --git a/TextLocator/Service/NoTextFileService.cs b/TextLocator/Service/NoTextFileService.cs index 0d3212eaf9747acf20a1a5df7f067bd4cb275b04..fc9ac84fd583f1adf76858fb73ae2a78d00efef2 100644 --- a/TextLocator/Service/NoTextFileService.cs +++ b/TextLocator/Service/NoTextFileService.cs @@ -22,8 +22,8 @@ namespace TextLocator.Service System.Diagnostics.FileVersionInfo info = System.Diagnostics.FileVersionInfo.GetVersionInfo(filePath); StringBuilder builder = new StringBuilder(); builder.Append("文件名称:" + info.FileName.Substring(info.FileName.LastIndexOf("\\") + 1)); - builder.Append("\r\n更新时间:" + fileInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")); - builder.Append("\r\n文件大小:" + Math.Ceiling(fileInfo.Length / 1024.0) + " KB"); + builder.Append(";更新时间:" + fileInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss")); + builder.Append(";文件大小:" + Math.Ceiling(fileInfo.Length / 1024.0) + " KB"); return builder.ToString(); } diff --git a/TextLocator/Service/PowerPointFileService.cs b/TextLocator/Service/PowerPointFileService.cs index cf772fe8c2af83eadbd5049fd7ea054dfda9eb9d..c158b12b28509ee771c01cfdd8b8fb883bad065c 100644 --- a/TextLocator/Service/PowerPointFileService.cs +++ b/TextLocator/Service/PowerPointFileService.cs @@ -50,7 +50,7 @@ namespace TextLocator.Service } catch (Exception ex) { - log.Error(ex.Message, ex); + log.Error(filePath + " -> " + ex.Message, ex); } } return content; diff --git a/TextLocator/TextLocator.csproj b/TextLocator/TextLocator.csproj index 7bb5f83e5fa3cf93d27c312b494ff0d9ad249af4..7daa739d828daba07e36bc13ca6e181881208c7e 100644 --- a/TextLocator/TextLocator.csproj +++ b/TextLocator/TextLocator.csproj @@ -39,11 +39,11 @@ Resource\App.ico - - ..\packages\Portable.BouncyCastle.1.8.6\lib\net40\BouncyCastle.Crypto.dll + + ..\packages\Portable.BouncyCastle.1.9.0\lib\net40\BouncyCastle.Crypto.dll - - ..\packages\SharpZipLib.1.3.1\lib\net45\ICSharpCode.SharpZipLib.dll + + ..\packages\SharpZipLib.1.3.3\lib\net45\ICSharpCode.SharpZipLib.dll ..\packages\jieba.NET.0.42.2\lib\net45\JiebaNet.Analyser.dll @@ -51,8 +51,8 @@ ..\packages\jieba.NET.0.42.2\lib\net45\JiebaNet.Segmenter.dll - - ..\packages\log4net.2.0.12\lib\net45\log4net.dll + + ..\packages\log4net.2.0.14\lib\net45\log4net.dll ..\packages\Lucene.Net.3.0.3\lib\NET40\Lucene.Net.dll @@ -72,62 +72,62 @@ ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll - - ..\packages\NPOI.2.5.4\lib\net45\NPOI.dll + + ..\packages\NPOI.2.5.5\lib\net45\NPOI.dll - - ..\packages\NPOI.2.5.4\lib\net45\NPOI.OOXML.dll + + ..\packages\NPOI.2.5.5\lib\net45\NPOI.OOXML.dll - - ..\packages\NPOI.2.5.4\lib\net45\NPOI.OpenXml4Net.dll + + ..\packages\NPOI.2.5.5\lib\net45\NPOI.OpenXml4Net.dll - - ..\packages\NPOI.2.5.4\lib\net45\NPOI.OpenXmlFormats.dll + + ..\packages\NPOI.2.5.5\lib\net45\NPOI.OpenXmlFormats.dll ..\packages\Rubyer.1.0.16\lib\net46\Rubyer.dll - - ..\packages\Spire.Office.6.8.2\lib\net40\Spire.Barcode.dll + + ..\packages\Spire.Office.7.2.0\lib\net40\Spire.Barcode.dll - - ..\packages\Spire.Office.6.8.2\lib\net40\Spire.DataExport.dll + + ..\packages\Spire.Office.7.2.0\lib\net40\Spire.DataExport.dll - ..\packages\Spire.Office.6.8.2\lib\net40\Spire.DataExport.ResourceMgr.dll + ..\packages\Spire.Office.7.2.0\lib\net40\Spire.DataExport.ResourceMgr.dll - - ..\packages\Spire.Office.6.8.2\lib\net40\Spire.Doc.dll + + ..\packages\Spire.Office.7.2.0\lib\net40\Spire.Doc.dll - - ..\packages\Spire.Office.6.8.2\lib\net40\Spire.DocViewer.Forms.dll + + ..\packages\Spire.Office.7.2.0\lib\net40\Spire.DocViewer.Forms.dll - - ..\packages\Spire.Office.6.8.2\lib\net40\Spire.Email.dll + + ..\packages\Spire.Office.7.2.0\lib\net40\Spire.Email.dll - ..\packages\Spire.Office.6.8.2\lib\net40\Spire.License.dll + ..\packages\Spire.Office.7.2.0\lib\net40\Spire.License.dll - - ..\packages\Spire.Office.6.8.2\lib\net40\Spire.OfficeViewer.Forms.dll + + ..\packages\Spire.Office.7.2.0\lib\net40\Spire.OfficeViewer.Forms.dll - - ..\packages\Spire.Office.6.8.2\lib\net40\Spire.Pdf.dll + + ..\packages\Spire.Office.7.2.0\lib\net40\Spire.Pdf.dll - - ..\packages\Spire.Office.6.8.2\lib\net40\Spire.PdfViewer.Asp.dll + + ..\packages\Spire.Office.7.2.0\lib\net40\Spire.PdfViewer.Asp.dll - - ..\packages\Spire.Office.6.8.2\lib\net40\Spire.PdfViewer.Forms.dll + + ..\packages\Spire.Office.7.2.0\lib\net40\Spire.PdfViewer.Forms.dll - - ..\packages\Spire.Office.6.8.2\lib\net40\Spire.Presentation.dll + + ..\packages\Spire.Office.7.2.0\lib\net40\Spire.Presentation.dll - - ..\packages\Spire.Office.6.8.2\lib\net40\Spire.Spreadsheet.dll + + ..\packages\Spire.Office.7.2.0\lib\net40\Spire.Spreadsheet.dll - - ..\packages\Spire.Office.6.8.2\lib\net40\Spire.XLS.dll + + ..\packages\Spire.Office.7.2.0\lib\net40\Spire.XLS.dll diff --git a/TextLocator/Util/CacheUtil.cs b/TextLocator/Util/CacheUtil.cs index 46bdfb09549cb26c6ee5a17acfb08234c32321f1..82b2c6d2165835deece2deb3585d351ad760b39b 100644 --- a/TextLocator/Util/CacheUtil.cs +++ b/TextLocator/Util/CacheUtil.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; namespace TextLocator.Util { diff --git a/TextLocator/Util/FileUtil.cs b/TextLocator/Util/FileUtil.cs index 0f3885f42d1772c87d07235bcbf4b7efdeef136c..24cd8679867aed2097e4cecbaaa9e027a9cd7482 100644 --- a/TextLocator/Util/FileUtil.cs +++ b/TextLocator/Util/FileUtil.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; +using System.Threading.Tasks; using System.Windows.Media.Imaging; using TextLocator.Core; using TextLocator.Enums; @@ -155,7 +156,7 @@ namespace TextLocator.Util foreach (string path in paths) { string fileName = path.Substring(path.LastIndexOf("\\") + 1); - if (fileName.StartsWith("`") || fileName.StartsWith("$")) + if (fileName.StartsWith("`") || fileName.StartsWith("$") || fileName.StartsWith("~") || fileName.StartsWith(".")) { continue; } diff --git a/TextLocator/packages.config b/TextLocator/packages.config index 101547c1fdabae0111364f540250729c37bffa2e..872d517eaac20d4eb4d5414c8cf6894d5a85375e 100644 --- a/TextLocator/packages.config +++ b/TextLocator/packages.config @@ -1,15 +1,15 @@  - + - - + + - - + + \ No newline at end of file