From 53b19dad87c4262ca5c4d0bc1b3a4e20b37f9bdd Mon Sep 17 00:00:00 2001 From: Yeechan Lu Date: Tue, 25 Mar 2014 13:36:33 +0800 Subject: [PATCH] Revert "Revert use FuzzyMatcher on Bookmarks since it's too slow" --- Wox.Plugin.System/BrowserBookmarks.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Wox.Plugin.System/BrowserBookmarks.cs b/Wox.Plugin.System/BrowserBookmarks.cs index 7b72159b2e..94eef2bdc5 100644 --- a/Wox.Plugin.System/BrowserBookmarks.cs +++ b/Wox.Plugin.System/BrowserBookmarks.cs @@ -22,7 +22,8 @@ namespace Wox.Plugin.System if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List(); var fuzzyMather = FuzzyMatcher.Create(query.RawQuery); - List returnList = bookmarks.Where(o => MatchProgram(o, query.RawQuery.ToLower())).ToList(); + List returnList = bookmarks.Where(o => MatchProgram(o, fuzzyMather)).ToList(); + returnList = returnList.OrderByDescending(o => o.Score).ToList(); return returnList.Select(c => new Result() { Title = c.Name, @@ -37,11 +38,12 @@ namespace Wox.Plugin.System } }).ToList(); } - private bool MatchProgram(Bookmark bookmark, String query) + private bool MatchProgram(Bookmark bookmark, FuzzyMatcher matcher) { - if (bookmark.Name.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0) return true; - if (bookmark.Url.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0) return true; - if (bookmark.PinyinName.Contains(query)) return true; + if ((bookmark.Score = matcher.Evaluate(bookmark.Name).Score) > 0) return true; + if ((bookmark.Score = matcher.Evaluate(bookmark.PinyinName).Score) > 0) return true; + if ((bookmark.Score = matcher.Evaluate(bookmark.Url).Score / 10) > 0) return true; + return false; } @@ -137,6 +139,7 @@ namespace Wox.Plugin.System public string PinyinName { get; private set; } public string Url { get; set; } public string Source { get; set; } + public int Score { get; set; } /* TODO: since Source maybe unimportant, we just need to compare Name and Url */ public bool Equals(Bookmark other)