public void FillTopic(TopicItem topicItem) { String query = topicItem.Query.Replace(" ", "_"); try { XMLConnector XMLConnector = new XMLConnector(); bool isRedirect = true; while (isRedirect) { isRedirect = false; string url = "http://en.wikipedia.org/wiki/Special:Export/" + query; XmlDocument xmlDocument = XMLConnector.GetXMLDocument(url); XmlNodeList nodeList = xmlDocument.GetElementsByTagName("text"); string content = nodeList[0].InnerText; if (content != null && content.Length > 0) { // "#REDIRECT [[Dan Quayle]] {{R from other capitalisation}}" if (content.IndexOf("#REDIRECT") >= 0) { string newQuery = ParseRedirect(content); if (newQuery != null && newQuery.Length > 0) { if (!newQuery.Equals(query)) { query = newQuery; isRedirect = true; } } } else { topicItem.WikipediaSummary = BuildSummary(content); } } } } catch (Exception exception) { ErrorService.Log("WikipediaTopicService", "FillTopic", topicItem.ToString(), exception); } }
public SearchResultList Search(SearchContext searchContext) { SearchResultList resultList = new SearchResultList(); try { string urlTemplate; switch (searchContext.SearchType) { case SearchTypeEnum.Image: urlTemplate = "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key={0}&safe_search=1&per_page={1}&page={2}&format=rest&nojsoncallback=1&privacy_filter=1&content_type=1&sort=relevance&text={3}"; break; default: return resultList; } string query = searchContext.Query; int countPerPage = searchContext.Count; int page = searchContext.Page; string key = ConfigService.GetConfig(ConfigKeys.FLICKR_API_KEY, ""); string url = string.Format(urlTemplate, key, countPerPage, page, HttpUtility.UrlEncode(query)); Console.WriteLine(url); XMLConnector XMLConnector = new XMLConnector(); XmlDocument xmlDocument = XMLConnector.GetXMLDocument(url); new FlickrSearchParser().Parse(xmlDocument, resultList); } catch (Exception exception) { ErrorService.Log("FlickrSearchService", "Search", searchContext.ToString(), exception); } return resultList; }