This package has been deprecated

Author message:

This package has been deprecated. See https://learn.microsoft.com/bing/search-apis for details on how to use Bing Search Services.

@azure/cognitiveservices-customsearch
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

An isomorphic javascript sdk for - CustomSearchClient

This package contains an isomorphic SDK for CustomSearchClient.

Currently supported environments

  • Node.js version 6.x.x or higher
  • Browser JavaScript

How to Install

npm install @azure/cognitiveservices-customsearch

How to use

nodejs - Authentication, client creation and search customInstance as an example written in TypeScript.

Install @azure/ms-rest-azure-js
npm install @azure/ms-rest-azure-js
Sample code

The following sample performs a search for given query on a custom configuration. The custom configuration can be setup using the Custom search portal. To know more, refer to the Azure Documentation Bing Custom Search

const { CustomSearchClient } = require("@azure/cognitiveservices-customsearch");
const { CognitiveServicesCredentials } = require("@azure/ms-rest-azure-js");

async function main() {
  const customSearchKey = process.env["customSearchKey"] || "<customSearchKey>";
  const customSearchEndPoint =
    process.env["customSearchEndPoint"] || "<customSearchEndPoint>";
  const customConfig = process.env["customConfig"] || "<customConfig>";
  const cognitiveServiceCredentials = new CognitiveServicesCredentials(
    customSearchKey
  );
  const client = new CustomSearchClient(cognitiveServiceCredentials, {
    endpoint: customSearchEndPoint
  });
  const query = "World Peace";
  const options = {
    count: 10,
    safeSearch: "Moderate"
  };
  client.customInstance
    .search(customConfig, query, options)
    .then(result => {
      console.log("The result is: ");
      console.log(result);
    })
    .catch(err => {
      console.log("An error occurred:");
      console.error(err);
    });
}

main();

browser - Authentication, client creation and search customInstance as an example written in JavaScript.

Sample code
  • index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>@azure/cognitiveservices-customsearch sample</title>
    <script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
    <script src="node_modules/@azure/cognitiveservices-customsearch/dist/cognitiveservices-customsearch.js"></script>
    <script type="text/javascript">
      const customSearchKey = "<YOUR_CUSTOM_SEARCH_KEY>";
      const customSearchEndPoint = "<YOUR_CUSTOM_SEARCH_ENDPOINT>";
      const customConfig = "<YOUR_CUSTOM_CONFIG>";

      const cognitiveServiceCredentials = new msRest.ApiKeyCredentials({
        inHeader: {
          "Ocp-Apim-Subscription-Key": customSearchKey
        }
      });

      const client = new Azure.CognitiveservicesCustomsearch.CustomSearchClient(
        cognitiveServiceCredentials,
        {
          endpoint: customSearchEndPoint
        }
      );

      const query = "World Peace";
      const options = {
        count: 10,
        safeSearch: "Moderate"
      };
      client.customInstance
        .search(customConfig, query, options)
        .then(result => {
          console.log("The result is: ");
          console.log(result);
        })
        .catch(err => {
          console.log("An error occurred:");
          console.error(err);
        });
    </script>
  </head>
  <body></body>
</html>

Related projects

Impressions

Dependencies (2)

Dev Dependencies (5)

Package Sidebar

Install

npm i @azure/cognitiveservices-customsearch

Weekly Downloads

38

Version

3.0.1

License

MIT

Unpacked Size

294 kB

Total Files

49

Last publish

Collaborators

  • microsoft1es
  • amarzavery
  • vladbarosan
  • veronicagg
  • azure-sdk