Quickstart: Call your Bing Custom Search endpoint using Java
Artikel
Use this quickstart to learn how to request search results from your Bing Custom Search instance. Although this application is written in Java, the Bing Custom Search API is a RESTful web service compatible with most programming languages. The source code for this sample is available on GitHub.
Create a class named CustomSrchJava, and then create variables for your subscription key, custom search endpoint, and search instance's custom configuration ID.
Create a function named prettify() to format the JSON response from the Bing Custom Search API.
Java
// pretty-printer for JSON; uses GSON parser to parse and re-serializepublicstatic String prettify(String json_text){
JsonParser parser = new JsonParser();
JsonObject json = parser.parse(json_text).getAsJsonObject();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
return gson.toJson(json);
}
Send and receive a search request
Create a function named SearchWeb() that sends a request and returns a SearchResults object. Create the request url by combining your custom configuration ID, query, and endpoint information. Add your subscription key to the Ocp-Apim-Subscription-Key header.
Börja här och lär dig att skapa, migrera och skala Java-program i Azure med hjälp av Azure-tjänsterna. Använd de verktyg och ramverk som du känner till och gillar – Spring, Tomcat, WildFly, JBoss, WebLogic, WebSphere, Maven, Gradle, IntelliJ, Eclipse, Jenkins, Terraform med flera.