Exemple #1
0
        private void PerformSearch(string ns, string from, string message)
        {
            if (string.IsNullOrEmpty(message))
            {
                Respond(ns, from, "You must provide text to search on.");
                return;
            }

            SearchRequest request = new SearchRequest();
            request.AppId = "1673C17DF0ADCEA175BF492E9689AB886B2A8747";
            request.Sources = new SourceType[] { SourceType.Web };
            request.Query = message;
            SearchResponse response = SearchClient.Search(request);
            if (response.Web != null && response.Web.Results.Count() > 0)
            {
                StringBuilder output = new StringBuilder(string.Format(":magnify: Results <b>{0} &#8211; {1}</b> of {2}<ol>",
                    response.Web.Offset,
                    response.Web.Results.Count(),
                    response.Web.Total));
                foreach (WebResult result in response.Web.Results)
                {
                    output.AppendFormat("<li><strong><u><a href=\"{0}\">{1}</a></u></strong><br />{2}<br /><sup><em>{3}</em></sup></li>",
                        result.Url.Replace("https://", "http://"),   // chat won't allow secure links
                        result.Title,
                        result.Description,
                        result.DisplayUrl);
                }
                output.Append("</ol>");
                Say(ns, output.ToString());
            }
            else
            {
                Respond(ns, from, string.Format("No results found for query '{0}'.", message));
            }
        }
Exemple #2
0
 /// <remarks/>
 public void SearchAsync(SearchRequest parameters) {
     this.SearchAsync(parameters, null);
 }
Exemple #3
0
 /// <remarks/>
 public void SearchAsync(SearchRequest parameters, object userState) {
     if ((this.SearchOperationCompleted == null)) {
         this.SearchOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSearchOperationCompleted);
     }
     this.InvokeAsync("Search", new object[] {
                 parameters}, this.SearchOperationCompleted, userState);
 }
Exemple #4
0
 public SearchResponse Search(SearchRequest parameters) {
     object[] results = this.Invoke("Search", new object[] {
                 parameters});
     return ((SearchResponse)(results[0]));
 }