/Samples/Commands/Bingo.BingSearch/BingSearchEngine.cs
C# | 43 lines | 32 code | 3 blank | 8 comment | 0 complexity | f0feef7ee6172bc648537dd1633e9e0f MD5 | raw file
- using System.Collections.Generic;
- using System.Linq;
- using Bingo.BingSearch.Bing;
- using Bingo.Common;
-
- namespace Bingo.BingSearch
- {
- /// <summary>
- /// Implementation of the web search engine using Bing
- /// </summary>
- public class BingSearchEngine : ISearchEngine
- {
- /// <summary>
- /// Searches the web using the query provided.
- /// </summary>
- /// <param name="query">The query.</param>
- /// <returns></returns>
- public IEnumerable<SearchResult> DoSearch(string query)
- {
- using (var service = new LiveSearchPortTypeClient())
- {
- var request = new SearchRequest
- {
- AppId = "F703173CD4C405522296261437A850508F4A6E14",
- Sources = new SourceType[] {SourceType.Web},
- Query = query
- };
-
- var response = service.Search(request);
-
- return
- response.Web.Results.Select(
- result =>
- new SearchResult
- {
- Url = result.Url,
- Title = result.Title,
- Description = result.Description
- });
- }
- }
- }
- }