Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

BingSearchService.cs 1.3 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  1. using System.Collections.Generic;
  2. using System.Configuration;
  3. using System.Threading.Tasks;
  4. using Microsoft.Bot.Builder.Internals.Fibers;
  5. using Zummer.Models.Search;
  6. namespace Zummer.Services
  7. {
  8. /// <summary>
  9. /// Responsible for calling Bing Web Search API
  10. /// </summary>
  11. internal sealed class BingSearchService : ISearchService
  12. {
  13. private const string BingSearchEndpoint = "https://api.cognitive.microsoft.com/bing/v5.0/search/";
  14. private static readonly Dictionary<string, string> Headers = new Dictionary<string, string>
  15. {
  16. { "Ocp-Apim-Subscription-Key", ConfigurationManager.AppSettings["BingSearchServiceKey"] }
  17. };
  18. private readonly IApiHandler apiHandler;
  19. public BingSearchService(IApiHandler apiHandler)
  20. {
  21. SetField.NotNull(out this.apiHandler, nameof(apiHandler), apiHandler);
  22. }
  23. public async Task<BingSearch> FindArticles(string query)
  24. {
  25. var requestParameters = new Dictionary<string, string>
  26. {
  27. { "q", $"{query} site:wikipedia.org" },
  28. { "form", "BTCSWR" }
  29. };
  30. return await this.apiHandler.GetJsonAsync<BingSearch>(BingSearchEndpoint, requestParameters, Headers);
  31. }
  32. }
  33. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...