Exemplo n.º 1
0
        public YSearchResultCollection SearchWeb(String query, int offset, int limit, ref OmukSemantics semantics)
        {
            //semantics = new OmukSemantics();
            YSearchResultCollection resultCollection = new YSearchResultCollection();

            ysearchresponse ysearchResponse= this.ProcessRequest(query, offset, limit);
            resultCollection.NextPageUrl = ysearchResponse.nextpage;
            foreach (ysearchresponseResultset_webResult webResult in ysearchResponse.resultset_web.result)
            {
                resultCollection.SearchResult.Add(new YSearchItem()
                                                    {
                                                        AbstractText = webResult.@abstract,
                                                        Title = webResult.title,
                                                        UrlField = webResult.url
                                                    });
                semantics.ProcessContext(webResult.title, webResult.url, webResult.@abstract);
            }

            if (offset == 0)
            {
                if (semantics.Category.Equals("movie"))
                {
                    ysearchResponse = this.ProcessRequest(query + " rottentomatoes", 0, 4);
                    foreach (ysearchresponseResultset_webResult webResult in ysearchResponse.resultset_web.result)
                    {
                        if (webResult.url.StartsWith("http://www.rottentomatoes.com/m") || webResult.url.StartsWith("http://rottentomatoes.com/m"))
                        {
                            resultCollection.SearchResult.Insert(1, (new YSearchItem()
                            {
                                AbstractText = webResult.@abstract,
                                Title = webResult.title,
                                UrlField = webResult.url
                            }));
                        }
                    }
                }

            }

            return resultCollection;
        }
Exemplo n.º 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;
        }