Esempio n. 1
0
        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");
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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...
        }
Esempio n. 4
0
        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;
                });
            }
        }