diff --git a/sdk/search/search-documents/README.md b/sdk/search/search-documents/README.md index c6f3c151e590..488a9c72bff2 100644 --- a/sdk/search/search-documents/README.md +++ b/sdk/search/search-documents/README.md @@ -85,37 +85,6 @@ const indexClient = new SearchIndexClient("", new AzureKeyCredential(" const indexerClient = new SearchIndexerClient("", new AzureKeyCredential("")); ``` -### Send your first search query - -To get running immediately, we're going to connect to a well known sandbox Search service provided by Microsoft. This means you do not need an Azure subscription or Azure Cognitive Search service to try out this query. - -```js -const { SearchClient, AzureKeyCredential } = require("@azure/search-documents"); - -// We'll connect to the Azure Cognitive Search public sandbox and send a -// query to its "nycjobs" index built from a public dataset of available jobs -// in New York. -const indexName = "nycjobs"; -const apiKey = "252044BE3886FE4A8E3BAA4F595114BB"; - -// Create a SearchClient to send queries -const client = new SearchClient( - `https://azs-playground.search.windows.net/`, - indexName, - new AzureKeyCredential(apiKey) -); - -async function main() { - // Let's get the top 5 jobs related to Microsoft - const searchResults = await client.search("Microsoft", { top: 5 }); - for await (const result of searchResults.results) { - console.log(`${result.document.business_title}\n${result.document.job_description}\n`); - } -} - -main(); -``` - ## Key concepts An Azure Cognitive Search service contains one or more indexes that provide persistent storage of searchable data in the form of JSON documents. _(If you're brand new to search, you can make a very rough analogy between indexes and database tables.)_ The @azure/search-documents client library exposes operations on these resources through three main client types. diff --git a/sdk/search/search-documents/samples/javascript/README.md b/sdk/search/search-documents/samples/javascript/README.md index 43fa346ba75d..3744a0d50015 100644 --- a/sdk/search/search-documents/samples/javascript/README.md +++ b/sdk/search/search-documents/samples/javascript/README.md @@ -4,7 +4,6 @@ These sample programs show how to use the JavaScript client libraries for Azure | **File Name** | **Description** | | ---------------------------- | ------------------------ | -| [readonlyQuery.js][readonly] | queries a public dataset | | **Data Source Connections** | | [createDataSourceConnection.js][createDataSourceConnection] | Creates a Datasource Connection | | [createOrUpdateDataSourceConnection.js][createOrUpdateDataSourceConnection] | Updates a Datasource Connection | diff --git a/sdk/search/search-documents/samples/javascript/src/readonlyQuery.js b/sdk/search/search-documents/samples/javascript/src/readonlyQuery.js deleted file mode 100644 index e940c043105b..000000000000 --- a/sdk/search/search-documents/samples/javascript/src/readonlyQuery.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -/** - * Performs a query over a public dataset - */ - -const { SearchClient, AzureKeyCredential, odata } = require("@azure/search-documents"); - -// Load the .env file if it exists -require("dotenv").config(); - -async function main() { - console.log(`Running readonly query sample`); - - // Variables provided by https://docs.microsoft.com/en-us/samples/azure-samples/azure-search-sample-data/azure-search-sample-data/ - const endpoint = "https://azs-playground.search.windows.net"; - const apiKey = "EA4510A6219E14888741FCFC19BFBB82"; - const indexName = "hotels"; - - const credential = new AzureKeyCredential(apiKey); - const client = new SearchClient(endpoint, indexName, credential); - - const count = await client.getDocumentsCount(); - console.log(`${count} documents in index ${client.indexName}`); - - const state = "FL"; - const country = "USA"; - const searchResults = await client.search( - "WiFi", - { - filter: odata`Address/StateProvince eq ${state} and Address/Country eq ${country}`, - orderBy: ["Rating desc"], - select: ["HotelId", "HotelName", "Rating"] - }); - for await (const result of searchResults.results) { - console.log(`${result.document.HotelName}: ${result.document.Rating} stars`); - } -} - -main().catch((err) => { - console.error("The sample encountered an error:", err); -}); diff --git a/sdk/search/search-documents/samples/typescript/README.md b/sdk/search/search-documents/samples/typescript/README.md index 7964503663ad..e95214384b46 100644 --- a/sdk/search/search-documents/samples/typescript/README.md +++ b/sdk/search/search-documents/samples/typescript/README.md @@ -4,7 +4,6 @@ These sample programs show how to use the TypeScript client libraries for Azure | **File Name** | **Description** | | ---------------------------- | ------------------------ | -| [readonlyQuery.ts][readonly] | queries a public dataset | | **Data Source Connections** | | [createDataSourceConnection.ts][createDataSourceConnection] | Creates a Datasource Connection | | [createOrUpdateDataSourceConnection.ts][createOrUpdateDataSourceConnection] | Updates a Datasource Connection | diff --git a/sdk/search/search-documents/samples/typescript/src/readonlyQuery.ts b/sdk/search/search-documents/samples/typescript/src/readonlyQuery.ts deleted file mode 100644 index 4dfc63fc0f94..000000000000 --- a/sdk/search/search-documents/samples/typescript/src/readonlyQuery.ts +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -/** - * Performs a query over a public dataset - */ -import { SearchClient, AzureKeyCredential, odata, GeographyPoint } from "@azure/search-documents"; - -// Load the .env file if it exists -import * as dotenv from "dotenv"; -dotenv.config(); - -interface Hotel { - HotelId: string; - HotelName: string; - Description: string; - Description_fr: string; - Category: string; - Tags: string[]; - ParkingIncluded: boolean; - LastRenovationDate: Date; - Rating: number; - Address: { - StreetAddress: string; - City: string; - StateProvince: string; - PostalCode: string; - Country: string; - }; - Location: GeographyPoint; - Rooms: Array<{ - Description: string; - Description_fr: string; - Type: string; - BaseRate: number; - BedOptions: string; - SleepsCount: number; - SmokingAllowed: boolean; - Tags: string[]; - }>; -} - -export async function main() { - console.log(`Running readonly query sample`); - - // Variables provided by https://docs.microsoft.com/en-us/samples/azure-samples/azure-search-sample-data/azure-search-sample-data/ - const endpoint = "https://azs-playground.search.windows.net"; - const apiKey = "EA4510A6219E14888741FCFC19BFBB82"; - const indexName = "hotels"; - - const credential = new AzureKeyCredential(apiKey); - const client = new SearchClient(endpoint, indexName, credential); - - const count = await client.getDocumentsCount(); - console.log(`${count} documents in index ${client.indexName}`); - - const state = "FL"; - const country = "USA"; - const searchResults = await client.search("WiFi", { - filter: odata`Address/StateProvince eq ${state} and Address/Country eq ${country}`, - orderBy: ["Rating desc"], - select: ["HotelId", "HotelName", "Rating"] - }); - for await (const result of searchResults.results) { - console.log(`${result.document.HotelName}: ${result.document.Rating} stars`); - } -} - -main().catch((err) => { - console.error("The sample encountered an error:", err); -});