protected override void LoadData()
 {
     Trace.Write("SuggestionsControl LoadData() - Start Calling Suggestions Command");
     ISuggestionsCommand suggestionsCommand = new SuggestionsCommand(Query);
     SuggestionsList = suggestionsCommand.Suggest();
     Trace.Write("SuggestionsControl LoadData() - End Calling Suggestions Command");
 }
Exemplo n.º 2
0
 public void AddSuggestions(SuggestionsList suggestionsList)
 {
     foreach (SuggestionItem newSuggestion in suggestionsList)
     {
         SuggestionItem suggestion = GetSuggestion(newSuggestion.Name);
         if (suggestion == null)
         {
             Add(newSuggestion);
         }
         else
         {
             if (newSuggestion.Weight > suggestion.Weight)
             {
                 suggestion.Weight = newSuggestion.Weight;
             }
         }
     }
 }
        public SuggestionsList GetSuggestions(SuggestionsContext suggestionsContext)
        {
            SuggestionsList suggestionsList = new SuggestionsList();
            try
            {
                string query = suggestionsContext.Query;

                string urlTemplate = "http://google.com/complete/search?output=toolbar&q={0}";
                string url = string.Format(urlTemplate, query);

                XmlDocument xmlDocument = new XMLConnector().GetXMLDocument(url); ;

                XmlNodeList resultNodes = xmlDocument.SelectNodes("toplevel/CompleteSuggestion");
                if (resultNodes != null)
                {
                    foreach (XmlNode resultNode in resultNodes)
                    {
                        string name = null;
                        double numberQueries = 0;

                        XmlNode suggestionNode = resultNode.SelectSingleNode("suggestion");
                        if (suggestionNode != null)
                        {
                            XmlAttribute dataAttribute = suggestionNode.Attributes["data"];
                            if (dataAttribute != null)
                            {
                                name = dataAttribute.Value;
                            }
                        }

                        XmlNode numQueriesNode = resultNode.SelectSingleNode("num_queries");
                        if (numQueriesNode != null)
                        {
                            XmlAttribute intAttribute = numQueriesNode.Attributes["int"];
                            if (intAttribute != null)
                            {
                                string numQuery = intAttribute.Value;
                                try {
                                    numberQueries = double.Parse(numQuery);
                                } catch (Exception) {}
                            }
                        }

                        if (name != null && numberQueries > 0)
                        {
                            SuggestionItem suggestionItem = new SuggestionItem(name);
                            suggestionItem.Provider = ProviderEnum.Google;
                            suggestionItem.NumberQueries = numberQueries;
                            suggestionItem.Weight = CalculateWeight(numberQueries);
                            suggestionsList.Add(suggestionItem);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                ErrorService.Log("GoogleSuggestionsService", "GetSuggestions", suggestionsContext.ToString(), exception);
            }

            return suggestionsList;
        }
 public static void CacheSuggestionList(string query, SuggestionsList suggestionsList)
 {
     string cacheName = "suggestion-" + query;
     int cacheExpiration = ConfigService.GetConfig(ConfigKeys.THEINTERNETBUZZ_SUGGESTIONS_EXPIRATION, 60);
     CacheService.Put(cacheName, cacheExpiration, suggestionsList);
 }