Example #1
0
        private String AppID = "52447E790CBE691A81FDFF596A4A976B85715ED4";//"52447E790CBE691A81FDFF596A4A976BB4FD39CD";
        public BingSearchItemCollection SearchWeb(String query, int offset, int limit, ref OmukSemantics semantics)
        {
            xsd.SearchResponse       searchResponse = this.ProcessRequest(query, offset, limit);
            BingSearchItemCollection itemCollection = new BingSearchItemCollection();

            if (searchResponse.Errors != null && searchResponse.Errors.Length > 0)
            {
                foreach (xsd.SearchResponseErrors errors in searchResponse.Errors)
                {
                    itemCollection.Errors.Add(new BingSearchError()
                    {
                        Code      = errors.Error.Code,
                        HelpUrl   = errors.Error.HelpUrl,
                        Message   = errors.Error.Message,
                        Parameter = errors.Error.Parameter,
                        Value     = errors.Error.Value
                    });
                }
            }

            if (searchResponse.Web != null && searchResponse.Web.Results != null)
            {
                itemCollection.Offset = searchResponse.Web.Offset;
                itemCollection.Total  = searchResponse.Web.Total;
                if (searchResponse.Web.Results.Length > 0)
                {
                    foreach (xsd.WebWebResult result in searchResponse.Web.Results)
                    {
                        String desc = String.IsNullOrEmpty(result.Description) ? String.Empty :
                                      result.Description.Replace("", "<b>").Replace("", "</b>");
                        String title = result.Title.Replace("", "<b>").Replace("", "</b>");
                        itemCollection.Results.Add(new BingSearchItem()
                        {
                            Description = desc,
                            DisplayUrl  = result.DisplayUrl,
                            TimeField   = result.DateTime,
                            Title       = title,
                            UrlField    = result.Url
                        });
                        semantics.ProcessContext(title, result.Url, desc);
                    }
                }
            }

            if (offset == 0)
            {
                if (semantics.Category.Equals("movie"))
                {
                    searchResponse = this.ProcessRequest(query + " rottentomatoes", 0, 4);
                    if (searchResponse.Web.Results.Length > 0)
                    {
                        foreach (xsd.WebWebResult result in searchResponse.Web.Results)
                        {
                            String desc = String.IsNullOrEmpty(result.Description) ? String.Empty :
                                          result.Description.Replace("", "<b>").Replace("", "</b>");
                            String title = result.Title.Replace("", "<b>").Replace("", "</b>");

                            if (result.Url.StartsWith("http://www.rottentomatoes.com/m") || result.Url.StartsWith("http://rottentomatoes.com/m"))
                            {
                                itemCollection.Results.Add(new BingSearchItem()
                                {
                                    Description = desc,
                                    DisplayUrl  = result.DisplayUrl,
                                    TimeField   = result.DateTime,
                                    Title       = title,
                                    UrlField    = result.Url
                                });
                            }
                        }
                    }
                }
            }

            return(itemCollection);
        }
Example #2
0
        private String AppID = "52447E790CBE691A81FDFF596A4A976B85715ED4"; //"52447E790CBE691A81FDFF596A4A976BB4FD39CD";

        #endregion Fields

        #region Methods

        public BingSearchItemCollection SearchWeb(String query, int offset, int limit, ref OmukSemantics semantics)
        {
            xsd.SearchResponse searchResponse = this.ProcessRequest(query, offset, limit);
            BingSearchItemCollection itemCollection = new BingSearchItemCollection();

            if (searchResponse.Errors != null && searchResponse.Errors.Length > 0)
            {
                foreach (xsd.SearchResponseErrors errors in searchResponse.Errors)
                {
                    itemCollection.Errors.Add(new BingSearchError()
                                                {
                                                    Code = errors.Error.Code,
                                                    HelpUrl = errors.Error.HelpUrl,
                                                    Message = errors.Error.Message,
                                                    Parameter = errors.Error.Parameter,
                                                    Value = errors.Error.Value
                                                });
                }
            }

            if (searchResponse.Web != null && searchResponse.Web.Results != null)
            {
                itemCollection.Offset = searchResponse.Web.Offset;
                itemCollection.Total = searchResponse.Web.Total;
                if (searchResponse.Web.Results.Length > 0)
                {
                    foreach (xsd.WebWebResult result in searchResponse.Web.Results)
                    {
                        String desc = String.IsNullOrEmpty(result.Description) ? String.Empty :
                                                                    result.Description.Replace("", "<b>").Replace("", "</b>");
                        String title = result.Title.Replace("", "<b>").Replace("", "</b>");
                        itemCollection.Results.Add(new BingSearchItem()
                                                    {
                                                        Description = desc,
                                                        DisplayUrl = result.DisplayUrl,
                                                        TimeField = result.DateTime,
                                                        Title = title,
                                                        UrlField = result.Url
                                                    });
                        semantics.ProcessContext(title, result.Url, desc);
                    }
                }
            }

            if (offset == 0)
            {
                if (semantics.Category.Equals("movie"))
                {
                    searchResponse = this.ProcessRequest(query + " rottentomatoes", 0, 4);
                    if (searchResponse.Web.Results.Length > 0)
                    {
                        foreach (xsd.WebWebResult result in searchResponse.Web.Results)
                        {
                            String desc = String.IsNullOrEmpty(result.Description) ? String.Empty :
                                                                        result.Description.Replace("", "<b>").Replace("", "</b>");
                            String title = result.Title.Replace("", "<b>").Replace("", "</b>");

                            if (result.Url.StartsWith("http://www.rottentomatoes.com/m") || result.Url.StartsWith("http://rottentomatoes.com/m"))
                            {
                                itemCollection.Results.Add(new BingSearchItem()
                                                            {
                                                                Description = desc,
                                                                DisplayUrl = result.DisplayUrl,
                                                                TimeField = result.DateTime,
                                                                Title = title,
                                                                UrlField = result.Url
                                                            });
                            }
                        }
                    }
                }
            }

            return itemCollection;
        }