예제 #1
0
        public void Search_FromCandidates_ShouldAsExpected()
        {
            var ss     = new FuzzyMatcher(_candidates);
            var result = ss.Match("40' High Cube Dry");

            Assert.AreEqual(("_40 HC 40' HIGH CUBE CONTAINER", 3), result);
        }
예제 #2
0
        void Calculate()
        {
            selectedItemIndex = -1 + (SelectFirstMatch ? 1 : 0);

            foreach (var item in SearchItems)
            {
                ClearItem(item);

                var match = _fuzzyMatcher.Match(InputValue ?? "", item.Text);
                item.Matches = match.Matches;
                item.Score   = match.Score;

                if (OtherMatchFields != null && OtherMatchFields.Count() > 0)
                {
                    var itemType = item?.DataObject?.GetType();

                    if (itemType == null)
                    {
                        break;
                    }

                    foreach (var otherField in OtherMatchFields)
                    {
                        Debug.WriteLine($"Searching OtherMatchFields field {otherField}");

                        var otherFieldValue = itemType.GetProperty(otherField)?.GetValue(item !.DataObject)?.ToString();

                        if (string.IsNullOrWhiteSpace(otherFieldValue))
                        {
                            continue;
                        }

                        var otherMatch = _fuzzyMatcher.Match(InputValue ?? "", otherFieldValue);

                        if (otherMatch != null && otherMatch.Score > item !.Score)
                        {
                            item.Score                = otherMatch.Score;
                            item.Matches              = otherMatch.Matches;
                            item.OtherMatchFieldName  = otherField;
                            item.OtherMatchFieldValue = otherFieldValue;
                        }
                    }
                }
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            var availableCommands = new [] { "stash", "diff", "commit" };

            Console.WriteLine("\nAvailable commands: {0}\n", string.Join(", ", availableCommands));

            var input = Console.ReadLine();
            var match = FuzzyMatcher.Match(availableCommands, input);

            Console.WriteLine($"Did you mean '{match}'?\n");
        }
예제 #4
0
        public void Search_WithWeights_ShouldAsExpected()
        {
            var weights = new ScoreWeights();

            weights.Add(
                ("container", 0.1m),
                ("STANDARD", 0.3m)
                );
            var ss     = new FuzzyMatcher(_candidates, weights);
            var result = ss.Match("25' STANDARD CONTAINER");

            Assert.AreEqual((null, 0.4m), result);
        }