public BestMatchSelector(string searchText) { this.searchText = searchText ?? throw new ArgumentNullException(nameof(searchText)); matchPriority = MatchPriority.Nothing; bestCompletion = null; acronymMatchIndexes = AcronymSearchHelpers.TryCreateMatchIndexes(searchText); }
public void Select(Completion completion) { var newMatchPriority = GetMatchPriority(completion); if (newMatchPriority < matchPriority) { bestCompletion = completion; matchPriority = newMatchPriority; } }
public MatchPriority MatchOrder(DataRow trailRecord, DataTable targetTable) { MatchPriority highestMatch = MatchPriority.NONE; MatchPriority matchLevel = highestMatch; foreach (DataRow targetRecord in targetTable.Rows) { string sourceValue = trailRecord["ORDERID"].ToString().Trim(); string targetValue = targetRecord["ORDERID"].ToString().Trim(); if (sourceValue.Equals(targetValue)) { matchLevel = MatchPriority.LEVEL3; } int matchCount = 0; foreach (string column in columnsToMatch) { sourceValue = trailRecord[column].ToString().Trim(); targetValue = targetRecord[column].ToString().Trim(); if (sourceValue.Equals(targetValue)) { matchCount++; } } if (matchCount == columnsToMatch.Count) { matchLevel = (matchLevel == MatchPriority.LEVEL3 ? MatchPriority.LEVEL5 : MatchPriority.LEVEL2); } else if (matchCount == 1) { matchLevel = (matchLevel == MatchPriority.LEVEL3 ? MatchPriority.LEVEL4 : MatchPriority.LEVEL1); } else if (matchCount > 1) { matchLevel = (matchLevel == MatchPriority.LEVEL3 ? MatchPriority.LEVEL4 : MatchPriority.LEVEL2); } if ((int)matchLevel > (int)highestMatch) { highestMatch = matchLevel; } if (highestMatch == MatchPriority.LEVEL5) { break; } } return(highestMatch); }
public BestMatchSelector(string searchText) { if (searchText == null) throw new ArgumentNullException(nameof(searchText)); this.searchText = searchText; matchPriority = MatchPriority.Nothing; bestCompletion = null; acronymMatchIndexes = AcronymSearchHelpers.TryCreateMatchIndexes(searchText); }