public IEnumerator <BestBetsMatch> GetEnumerator() { // Create a list for the main category. var mainList = from item in new Array[1] select new { Synonym = _bestBet.Name, IsExact = _bestBet.IsExactMatch, IsNegated = false }; // Create a list for each of the Include synonyms var includeList = from item in _bestBet.IncludeSynonyms select new { Synonym = item.Text, IsExact = item.IsExactMatch, IsNegated = false }; // Create a list for each of the Exclude synonyms var excludeList = from item in _bestBet.ExcludeSynonyms select new { Synonym = item.Text, IsExact = item.IsExactMatch, IsNegated = true }; // Combine the lists and return the actual BestBetMatch objects. // NOTE: The assumption is that there are no duplicates. Union would // remove duplicates, but at the cost of additional processing. foreach (var item in mainList.Concat(includeList).Concat(excludeList)) { int tokenCount = -1; try { //TODO: Uh, do we need to clean the synonym????????? tokenCount = _tokenAnalyzer.GetTokenCount(item.Synonym); } catch (Exception ex) { throw new Exception( "Error in getting token count for: " + _bestBet.Name + ", Synonym: ," + item.Synonym, ex); } // Return a new object each time rather than update an existing object // that might be referenced/used somewhere else. yield return(new BestBetsMatch() { Category = _bestBet.Name, ContentID = _bestBet.ID, Synonym = item.Synonym, Language = _bestBet.Language, IsNegated = item.IsNegated, IsExact = item.IsExact, TokenCount = tokenCount }); } }
/// <summary> /// Gets a list of the BestBet Category IDs that matched our term /// </summary> /// <param name="language">The two-character language code to constrain the matches to</param> /// <param name="cleanedTerm">A term that have been cleaned of punctuation and special characters</param> /// <returns>An array of category ids</returns> public string[] GetMatches(string language, string cleanedTerm) { // Step 2. Get Number of Tokens in the term int numTokens = _tokenAnalyzer.GetTokenCount(cleanedTerm); // Step 4. Iterate over the matches IEnumerable <BestBetsMatch> matches = GetBestBetMatches( cleanedTerm, language, numTokens ); // Step 5. Process the matches and extract only the category IDs we will // be returning to the client string[] validCategories = FilterValidCategories(matches, numTokens); return(validCategories); }