Utbildning
Certifiering
Utforma och implementera en Azure AI-lösning med hjälp av Azure AI-tjänster, Azure AI Search och Azure Open AI.
Den här webbläsaren stöds inte längre.
Uppgradera till Microsoft Edge och dra nytta av de senaste funktionerna och säkerhetsuppdateringarna, samt teknisk support.
Get started with the Bing Custom Search client library for C#. Follow these steps to install the package and try out the example code for basic tasks. The Bing Custom Search API enables you to create tailored, ad-free search experiences for topics that you care about. The source code for this sample can be found on GitHub.
Use the Bing Custom Search client library for C# to:
Reference documentation | Library source code | Package (NuGet) | Samples
Microsoft.Azure.CognitiveServices.Search.CustomSearch
package. Installing the NuGet Custom Search package also installs the following assemblies:
Create a new C# console application in Visual Studio. Then add the following packages to your project:
using System;
using System.Linq;
using Microsoft.Azure.CognitiveServices.Search.CustomSearch;
In the main method of your application, instantiate the search client with your API key.
var client = new CustomSearchAPI(new ApiKeyServiceClientCredentials("YOUR-SUBSCRIPTION-KEY"));
Send a search query using your client's SearchAsync()
method, and then save the response. Be sure to replace your YOUR-CUSTOM-CONFIG-ID
with your instance's configuration ID (you can find the ID in the Bing Custom Search portal). This example searches for "Xbox":
// This will look up a single query (Xbox).
var webData = client.CustomInstance.SearchAsync(query: "Xbox", customConfig: Int32.Parse("YOUR-CUSTOM-CONFIG-ID")).Result;
The SearchAsync()
method returns a WebData
object. Use the object to iterate through any WebPages
that were found. This code finds the first webpage result and prints the webpage's Name
and URL
.
if (webData?.WebPages?.Value?.Count > 0)
{
// find the first web page
var firstWebPagesResult = webData.WebPages.Value.FirstOrDefault();
if (firstWebPagesResult != null)
{
Console.WriteLine("Number of webpage results {0}", webData.WebPages.Value.Count);
Console.WriteLine("First web page name: {0} ", firstWebPagesResult.Name);
Console.WriteLine("First web page URL: {0} ", firstWebPagesResult.Url);
}
else
{
Console.WriteLine("Couldn't find web results!");
}
}
else
{
Console.WriteLine("Didn't see any Web data..");
}
Utbildning
Certifiering
Utforma och implementera en Azure AI-lösning med hjälp av Azure AI-tjänster, Azure AI Search och Azure Open AI.
Dokumentation
Quickstart: Call your Bing Custom Search endpoint using Java - Bing Search Services
Use this quickstart to begin requesting search results from your Bing Custom Search instance in Java.
Quickstart: Call your Bing Custom Search endpoint using Node.js - Bing Search Services
Use this quickstart to begin requesting search results from your Bing Custom Search instance using Node.js.
Quickstart: Call your Bing Custom Search endpoint using C# - Bing Search Services
Use this quickstart to begin requesting search results from your Bing Custom Search instance in C#.