/Samples/Commands/Bingo.BingSearch/BingSearchEngine.cs

https://bitbucket.org/bu5hm4nn/sharpfellows.toolkit · C# · 43 lines · 32 code · 3 blank · 8 comment · 0 complexity · f0feef7ee6172bc648537dd1633e9e0f MD5 · raw file

  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Bingo.BingSearch.Bing;
  4. using Bingo.Common;
  5. namespace Bingo.BingSearch
  6. {
  7. /// <summary>
  8. /// Implementation of the web search engine using Bing
  9. /// </summary>
  10. public class BingSearchEngine : ISearchEngine
  11. {
  12. /// <summary>
  13. /// Searches the web using the query provided.
  14. /// </summary>
  15. /// <param name="query">The query.</param>
  16. /// <returns></returns>
  17. public IEnumerable<SearchResult> DoSearch(string query)
  18. {
  19. using (var service = new LiveSearchPortTypeClient())
  20. {
  21. var request = new SearchRequest
  22. {
  23. AppId = "F703173CD4C405522296261437A850508F4A6E14",
  24. Sources = new SourceType[] {SourceType.Web},
  25. Query = query
  26. };
  27. var response = service.Search(request);
  28. return
  29. response.Web.Results.Select(
  30. result =>
  31. new SearchResult
  32. {
  33. Url = result.Url,
  34. Title = result.Title,
  35. Description = result.Description
  36. });
  37. }
  38. }
  39. }
  40. }