public static IEnumerable <Win32> SearchPrograms(Query search, Settings settings, Dictionary <string, int> historyHistorySources) { //搜索自定义目录菜单 List <string> searchPathPrograms = SearchCustomPathPrograms(settings.ProgramSources, true); //搜索开始菜单 IEnumerable <string> systemPathPrograms = SearchCustomPathPrograms(ProgramPaths(), false); searchPathPrograms.AddRange(systemPathPrograms); List <FilterScoreItem> programs = searchPathPrograms.AsParallel().Distinct() .Select(p => { XinFuzzyMatcher xinFuzzyMatcher = new XinFuzzyMatcher(Path.GetFileNameWithoutExtension(p)); xinFuzzyMatcher.init(); try { bool isMatch = XinFuzzyMatcher.isMatch(xinFuzzyMatcher, search.Search, 0, 0); if (!isMatch) { return(new FilterScoreItem(p, 0)); } if (historyHistorySources != null && historyHistorySources.TryGetValue(p, out int score)) { return(new FilterScoreItem(p, score)); } return(new FilterScoreItem(p, 1000 - xinFuzzyMatcher.pinYinName.Length)); } catch (Exception e) { Log.Error("" + e); } return(new FilterScoreItem(p, 0)); }) .Where(p => p.Score > 0) .OrderByDescending(p => p.Score) .ToList(); if (programs.Count > 20) { programs = programs.GetRange(0, 20); } List <Win32> searchStartMenuPrograms = programs.Select(PathToWin32).ToList(); return(searchStartMenuPrograms); }
public void searchBookmark(List <Bookmark.Mark> searchMarks, Bookmark.Mark mark, string queryString, string foldPath) { if (mark.type.Equals("folder")) { foreach (Bookmark.Mark markChild in mark.children) { searchBookmark(searchMarks, markChild, queryString, foldPath + "/" + mark.name); } } else if (mark.type.Equals("url")) { if (XinFuzzyMatcher.isMatch(mark.name, queryString)) { mark.folderPath = foldPath; searchMarks.Add(mark); } } }
public List <Result> Query(Query query, Dictionary <string, int> historyHistorySources) { string queryString = query.Search; WindowFilterContext <AppWindowViewModel> windowContext = new WindowFilterContext <AppWindowViewModel> { Windows = new WindowFinder().GetWindows().Select(w => new AppWindowViewModel(w)), ForegroundWindowProcessTitle = new AppWindow(SystemWindow.ForegroundWindow.HWnd).ProcessTitle }; List <AppWindowViewModel> filterResults = windowContext.Windows .Where(r => { return(XinFuzzyMatcher.isMatch(r.ProcessTitle + " " + r.WindowTitle, queryString)); }) .OrderByDescending(r => - r.ProcessTitle.Length) .ToList(); // var filterResults = // new WindowFilterer().Filter(windowContext, queryString).Select(o => o.AppWindow.AppWindow) // .Where(window => window.ProcessTitle != "Wox") // .ToList(); List <Result> results = filterResults.Select(o => { Result result = new Result { Title = o.ProcessTitle, SubTitle = o.WindowTitle, IcoPath = o.AppWindow.ExecutablePath, ContextData = o, Action = con => { o.AppWindow.SwitchTo(); Context.API.HideApp(); return(true); } }; return(result); }).ToList(); return(results); }