protected void resultListView_OnItemDataBound(object sender, ListViewItemEventArgs e) { ListViewDataItem dataItem = (ListViewDataItem)e.Item; if (e.Item.ItemType == ListViewItemType.DataItem) { DictionarySearchResult dictionaryResult = (DictionarySearchResult)dataItem.DataItem; if (dictionaryResult != null) { PlaceHolder phPronunciation = (PlaceHolder)dataItem.FindControl("phPronunciation"); if (dictionaryResult.Term.HasPronunciation && phPronunciation != null) { phPronunciation.Visible = true; HtmlAnchor pronunciationLink = (HtmlAnchor)dataItem.FindControl("pronunciationLink"); if (pronunciationLink != null && dictionaryResult.Term.Pronunciation.HasAudio) { pronunciationLink.Visible = true; pronunciationLink.HRef = dictionaryResult.Term.Pronunciation.Audio; } else pronunciationLink.Visible = false; Literal pronunciationKey = (Literal)dataItem.FindControl("pronunciationKey"); if (pronunciationKey != null && dictionaryResult.Term.Pronunciation.HasKey) pronunciationKey.Text = " " + dictionaryResult.Term.Pronunciation.Key; } else phPronunciation.Visible = false; } } }
public string GetTermDefinition(object termSearchResult) { string definition = String.Empty; DictionarySearchResult termInfo = termSearchResult as DictionarySearchResult; if (termInfo != null) { // Special handling for Expand. Otherwise, just send back the definition. if (!string.IsNullOrEmpty(Expand)) { // Is the matched name identical to the term name (preferred name)? // If so, return the actual definition if (termInfo.MatchedTerm.CompareTo(termInfo.Term.Term) == 0) { definition = termInfo.Term.Definition.Html; } // Otherwise, report that this name is an alias. else { definition = String.Format("(Other name for: {0})", termInfo.Term.Term); } } else { definition = termInfo.Term.Definition.Html; } } return(definition); }
public DictionarySearchResult SearchDictionaryItems(string searchTerm, int languageId) { var allDictionaryItems = this.GetAllDictionaryItems(); var matchingItems = new List <Dictionary.DictionaryItem>(); var containingItems = new List <Dictionary.DictionaryItem>(); var searchResult = new DictionarySearchResult() { SearchResults = new List <DictionarySearchItem>(), HasExactMatch = false }; if (!String.IsNullOrWhiteSpace(searchTerm)) { // need to loop through all dictionary items and find any matching the search text foreach (var item in allDictionaryItems) { string dicValue = item.Value(languageId); if (dicValue.ToLower() == searchTerm.Trim().ToLower()) { // exact match searchResult.HasExactMatch = true; matchingItems.Add(item); } else // only search for near matches if there are no exact matches is that the right logic ? { if (dicValue.ToLower().Contains(searchTerm.Trim().ToLower()) || item.key.ToLower() == searchTerm.Trim().ToLower()) { // contains containingItems.Add(item); } } } if (matchingItems.Any()) //bind any matches { searchResult.SearchResults = matchingItems.Select(f => new DictionarySearchItem() { Key = f.key, Id = f.id.ToString(), Value = f.Value(languageId) }).ToList(); } else { if (containingItems.Any()) //bind any near matches { searchResult.SearchResults = containingItems.Select(f => new DictionarySearchItem() { Key = f.key, Id = f.id.ToString(), Value = f.Value(languageId) }).ToList(); } else { searchResult.StatusMessage = "No Matching Search Results"; } } } return(searchResult); }
public string GetTermDefinition(object termSearchResult) { string definition = String.Empty; DictionarySearchResult termInfo = termSearchResult as DictionarySearchResult; if (termInfo != null) { definition = termInfo.Term.Definition.Html; } return definition; }
/// <summary> /// Turn a term's list of aliases into a semi-colon separated list. /// </summary> /// <param name="word">A DictionarySearchResult object containing a Term data structure.</param> /// <returns> A semi-colon separated list of term aliases, enclosed in square brackets. /// <remarks> /// Only returns those aliases which met the search criteria. /// Returns an empty string if an Expand search was performed.</remarks> /// </returns> public string GetTermAliasList(object termSearchResult) { string aliases = String.Empty; DictionarySearchResult termInfo = termSearchResult as DictionarySearchResult; if (termInfo != null // Don't do this unless there are aliases to list. && termInfo.Term.Aliases.Length > 0 ) { StringBuilder sb = new StringBuilder(); // Get the original search string, forcing it to be non-null and removing any // leading/trailing spaces. string searchstr = Strings.Clean(Request.Params["q"]) ?? String.Empty; searchstr = SearchStr.Trim().ToLower(); // Handle the possibility that two alias types might have the same value // (e.g. US Brand Name and Foreign Brand Name) IEnumerable<Alias> uniqueAliases = termInfo.Term.Aliases.Distinct(); // Roll up the list of terms. foreach (Alias alias in uniqueAliases) { if (alias.Name != null) { // Mimic legacy logic for choosing which aliases to display. string name = HiLite(alias.Name.Trim()); string compareName = alias.Name.Trim().ToLower(); // name contains the search string if (BContains && compareName.Contains(searchstr)) sb.AppendFormat("{0}; ", name); // name starts with the search string else if (!BContains && compareName.StartsWith(searchstr)) sb.AppendFormat("{0}; ", name); // else -- not a match. } } // If terms were found, trim off the final semicolon and space before // wrapping the whole thing in square brackets. aliases = sb.ToString(); if (!String.IsNullOrEmpty(aliases)) aliases = String.Format("[ {0} ]", aliases.TrimEnd(' ', ';')); } return aliases; }
/// <summary> /// this is to utilize shared code between search and expand as they return the same objects and do the same action /// </summary> /// <param name="list">the string list that the dictionary service would return</param> /// <returns>deserialized list of DictionarySearchResults</returns> private List <DictionarySearchResult> DeserializeList(NCI.Services.Dictionary.BusinessObjects.DictionarySearchResultEntry[] list, svcDictionaryType dictionaryType) { List <DictionarySearchResult> returnList = new List <DictionarySearchResult>();; foreach (NCI.Services.Dictionary.BusinessObjects.DictionarySearchResultEntry m in list) { try { int id = m.ID; string termName = m.MatchedTerm; DictionaryTerm term = JsonConvert.DeserializeObject <DictionaryTerm>(m.TermDetail); DictionarySearchResult expansion = new DictionarySearchResult(id, termName, term); returnList.Add(expansion); } catch (JsonReaderException ex) { log.ErrorFormat("Error in Json string from service.\nDictionary: {0}\nTerm ID: {1}\nTerm Name: {2}", ex, dictionaryType, m.ID, m.MatchedTerm); } } return(returnList); }
public DictionarySearchResult SearchDictionaryItems(string searchTerm, int languageId) { var allDictionaryItems = this.GetAllDictionaryItems(); var matchingItems = new List<Dictionary.DictionaryItem>(); var containingItems = new List<Dictionary.DictionaryItem>(); var searchResult = new DictionarySearchResult() { SearchResults = new List<DictionarySearchItem>(), HasExactMatch = false }; if (!String.IsNullOrWhiteSpace(searchTerm)) { // need to loop through all dictionary items and find any matching the search text foreach (var item in allDictionaryItems) { string dicValue = item.Value(languageId); if (dicValue.ToLower() == searchTerm.Trim().ToLower()) { // exact match searchResult.HasExactMatch = true; matchingItems.Add(item); } else // only search for near matches if there are no exact matches is that the right logic ? { if (dicValue.ToLower().Contains(searchTerm.Trim().ToLower()) ||item.key.ToLower() == searchTerm.Trim().ToLower()) { // contains containingItems.Add(item); } } } if (matchingItems.Any()) //bind any matches { searchResult.SearchResults = matchingItems.Select(f => new DictionarySearchItem() { Key = f.key, Id = f.id.ToString(), Value = f.Value(languageId) }).ToList(); } else { if (containingItems.Any()) //bind any near matches { searchResult.SearchResults = containingItems.Select(f => new DictionarySearchItem() { Key = f.key, Id = f.id.ToString(), Value = f.Value(languageId) }).ToList(); } else { searchResult.StatusMessage = "No Matching Search Results"; } } } return searchResult; }