/// <summary> /// Returns First Complete match from string /// </summary> /// <param name="a_startNode"> Node to Start Lookup From </param> /// <param name="a_string"> The String to Match</param> /// <returns> Valid Node if Match is found </returns> private static Node LookupCompleteMatch(Node a_startNode, string a_string) { Node currentNode = a_startNode; string findString = a_string; while (currentNode != null) { Node.MatchResult matchingResult = currentNode.GetMatchingChild(findString); if (matchingResult.MatchType == Node.MatchType.None || matchingResult.MatchType == Node.MatchType.PartialNode) { return(null); } currentNode = matchingResult.Node; if (matchingResult.MatchType == Node.MatchType.PartialString && currentNode.IsLeaf() == false) { // Partial Match and Children Present - Evaluate them int startIndex = matchingResult.MatchCount; int subStrLen = findString.Length - startIndex; findString = findString.Substring(startIndex, subStrLen); } else if (matchingResult.MatchType == Node.MatchType.Full && currentNode.CompleteID != Node.InvalidCompleteID) // Full Complete Match { return(currentNode); } } return(null); }
private static LookupQuery LookupMatchForInsert(Node a_startNode, string a_string) { Node lastNode = null; Node currentNode = a_startNode; int totalMatchingChars = 0; int lastMatchCount = 0; string findString = a_string; while (currentNode != null) { lastNode = currentNode; Node.MatchResult matchingResult = currentNode.GetMatchingChild(findString); currentNode = matchingResult.Node; totalMatchingChars += matchingResult.MatchCount; if (matchingResult.MatchType == Node.MatchType.Full) { return(LookupQuery.Invalid); } if (matchingResult.MatchType == Node.MatchType.None) { return(new LookupQuery(lastNode, true, totalMatchingChars, lastMatchCount)); } if (matchingResult.MatchType == Node.MatchType.Partial || matchingResult.MatchType == Node.MatchType.PartialNode) { return(new LookupQuery(currentNode, true, totalMatchingChars, matchingResult.MatchCount)); } if (matchingResult.MatchType == Node.MatchType.PartialString) { if (currentNode.IsLeaf() == false) { int startIndex = matchingResult.MatchCount; int subStrLen = findString.Length - startIndex; findString = findString.Substring(startIndex, subStrLen); } else // No Valid Nodes { return(new LookupQuery(currentNode, true, totalMatchingChars, matchingResult.MatchCount)); } } lastMatchCount = matchingResult.MatchCount; } return(LookupQuery.Invalid); }
/// <summary> /// Returns First Complete Match from string including Partial String Matches /// </summary> /// <param name="a_startNode"> Node to Start Lookup From</param> /// <param name="a_string"> The String to Match</param> /// <returns> Lookup Query with Results </returns> private static LookupQuery LookupMatchIncludingPartialString(Node a_startNode, string a_string) { Node currentNode = a_startNode; string findString = a_string; int totalMatchingChars = 0; while (currentNode != null) { Node.MatchResult matchingResult = currentNode.GetMatchingChild(findString); if (matchingResult.MatchType == Node.MatchType.None) { return(LookupQuery.Invalid); } currentNode = matchingResult.Node; totalMatchingChars += matchingResult.MatchCount; if (matchingResult.MatchType == Node.MatchType.Full) // Found Complete Match { return(new LookupQuery(currentNode, false, totalMatchingChars, matchingResult.MatchCount)); } // Allow Complete Partial Node Matches if (matchingResult.MatchType == Node.MatchType.PartialNode) { if (matchingResult.Node.CompleteID != Node.InvalidCompleteID || matchingResult.MatchCount == findString.Length) { return(new LookupQuery(currentNode, true, totalMatchingChars, matchingResult.MatchCount)); } } if (matchingResult.MatchType == Node.MatchType.PartialString && currentNode.IsLeaf() == false) // Partial Match { // Partial Match and Children Present - Evaluate them int startIndex = matchingResult.MatchCount; int subStrLen = findString.Length - startIndex; findString = findString.Substring(startIndex, subStrLen); } } return(LookupQuery.Invalid); }