private void stringmatch_0() { Assert.Equal(null, FuzzyMatch.StringMatch("foo/bar/baz.js", "bingo")); var res = FuzzyMatch.StringMatch("foo/bar/baz.js", "fbb.js"); res = FuzzyMatch.StringMatch("src/search/QuickOpen.js", "qo"); }
protected override List <object> _Filter(List <object> _unfilteredData, string _displayMember, string userInput) { int count = userInput.Length - 1; string userLetters = userInput.ToLower(); List <object> results = new List <object>(); //List<string> names = new List<string>(); //foreach (var obj in _unfilteredData) //{ // var itemLetters = GetFilterString(obj, _displayMember).ToLower(); // names.Add(itemLetters); //} //// 超过 % 不匹配,就过滤掉 //var ordered = _unfilteredData.OrderBy(x => //( (double)FuzzyMatch.FindMatch(GetFilterString(x, _displayMember).ToLower(), userInput) ) / //( Math.Max(GetFilterString(x, _displayMember).ToLower().Length, userInput.Length)) > RejectionPercent); var ordered = _unfilteredData.OrderBy(x => FuzzyMatch.FindMatch(GetFilterString(x, _displayMember).ToLower(), userInput)); // 取最接近的几条 results.AddRange(ordered); return(results); }
private void generateMatchList_0() { string path = "src/document/DocumentCommandHandler.js"; var specials = FuzzyMatch.FindSpecialCharacters(path); var result = FuzzyMatch.GenerateMatchList("foo", path, specials.specials, specials.lastSegmentSpecialsIndex); Assert.Equal(null, result); }
private void generateMatchList_1() { string path = "src/document/DocumentCommandHandler.js"; var specials = FuzzyMatch.FindSpecialCharacters(path); path = path.ToLower(); var result = FuzzyMatch.GenerateMatchList("d", path, specials.specials, specials.lastSegmentSpecialsIndex); Assert.Equal(13, result[0].index); }
public void Matching_text_with_minimum_distance_of_zero_excludes_other_results() { var results = ResultInfoBuilder.GenerateUnique("tests", 10); var expected = results.Choice(); var sut = new FuzzyMatch(new FuzzyMatchSettings { Text = expected.Description }); var processed = sut.Process(results); processed.Should().NotBeEmpty() .And.ContainSingle() .And.ContainEquivalentOf(expected); }
void CheckFSC(string test, List <int> specials, int lastSegmentSpecialIndex) { var res = FuzzyMatch.FindSpecialCharacters(test); Assert.Equal(specials.Count, res.specials.Count); int i; for (i = 0; i < specials.Count; i++) { Assert.Equal(specials[i], res.specials[i]); } Assert.Equal(lastSegmentSpecialIndex, res.lastSegmentSpecialsIndex); }
public ActionResult FuzzyMatches(long id) { var tweet = Tweet.GetTweet(id); var text = tweet.Text; using (var db = new CommentContext()) { var bestMatches = db.CommentReplies.OrderByDescending(x => Fuzzy.PartialRatio(x.CommentText, text)).Take(3).ToList(); var model = new FuzzyMatch { Tweet = tweet, CommentReplies = bestMatches }; return(View(model)); } }
static bool goodRelativeOrdering(string query, List <string> testStrings) { var lastScore = int.MinValue; var goodOrdering = true; foreach (var str in testStrings) { var result = FuzzyMatch.StringMatch(str, query); if (result.matchQuality < lastScore) { goodOrdering = false; } lastScore = result.matchQuality; } return(goodOrdering); }
void runtest(string query, string str, bool match, int expected_score, string expected_matches) { int score = 0; string format; /*bool retmatch = FuzzyMatch.fuzzy_match(pattern, str, out score, out format); * * Assert.Equal(match, retmatch); * if (retmatch) * { * Assert.Equal(expected_score, score); * } * Assert.Equal(expected_matches, format);*/ var res = FuzzyMatch.StringMatch(str, query, null); // order of what? matchQuality // 2 things ... i need to reverse the order of results, the lower the number the better. // Also the range of chars matched is now a list of indexes into the string... }
//https://gist.github.com/bartlomiejwolk/6cb07b52fbb020cebfbb781a775e64a1 public static List <FuzzyMatch> FuzzySearch(this CommandService self, string query) { if (query == string.Empty) { return(null); } char[] tokens = query.ToCharArray(); List <FuzzyMatch> matches = new List <FuzzyMatch>(); foreach (CommandInfo cmdInfo in self.Commands.DistinctBy(x => x.Name)) { int tokenIndex = 0; int resultCharIndex = 0; List <int> matchedPositions = new List <int>(); while (resultCharIndex < cmdInfo.Name.Length) { if (cmdInfo.Name[resultCharIndex] == tokens[tokenIndex]) { matchedPositions.Add(resultCharIndex); tokenIndex++; if (tokenIndex >= tokens.Length) { var match = new FuzzyMatch() { TextValue = cmdInfo.Name, Positions = matchedPositions }; matches.Add(match); break; } } resultCharIndex++; } } return(matches); }
private async Task ProcessQuery(string query) { if (IoC.Get <IStudio>().CurrentSolution == null) { return; } if (string.IsNullOrEmpty(query)) { Dispatcher.UIThread.Post(() => { ResultsVisible = false; _results.Clear(); }); } else { query = query.ToLower(); var list = new List <SearchResultViewModel>(); await Task.Run(() => { foreach (var project in IoC.Get <IStudio>().CurrentSolution.Projects.ToList()) { project.SourceFiles?.Select(sf => { var match = FuzzyMatch.StringMatch(sf.Project.Location.MakeRelativePath(sf.Location), query, null); if (match != null) { return(new Tuple <bool, int, string, ISourceFile, List <FuzzyMatch.Range> >(true, match.matchQuality, match.label, sf, match.stringRanges)); } return(new Tuple <bool, int, string, ISourceFile, List <FuzzyMatch.Range> >(false, 0, "", sf, null)); }).Where(tp => tp.Item1).Select(tp => { var spans = new List <FormattedTextStyleSpan>(); int index = 0; foreach (var range in tp.Item5) { if (range.matched) { var span = new FormattedTextStyleSpan(index + tp.Item4.Project.Name.Length + 1, range.text.Length, ColorTheme.CurrentTheme.AccentLow); spans.Add(span); } index += range.text.Length; } list.InsertSorted(new SearchResultViewModel(tp.Item4) { Priority = tp.Item2, Spans = spans }); return(tp); }).ToList(); } }); Dispatcher.UIThread.Post(() => { _results.Clear(); foreach (var result in list) { _results.Add(result); } ResultsVisible = _results.Count > 0; SelectedIndex = -1; }); } }