[search-documents] Migrated Samples to the new pipeline (#16804)

* Migrated Samples to the new pipeline

* Formatted the file
This commit is contained in:
Sarangan Rajamanickam 2021-08-10 14:04:08 -07:00 коммит произвёл GitHub
Родитель 00b8d1ac7d
Коммит 098bf2e9f9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
126 изменённых файлов: 3157 добавлений и 3111 удалений

Просмотреть файл

@ -10,14 +10,14 @@
"audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit",
"build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1",
"build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1",
"build:samples": "dev-tool samples prep && cd dist-samples && tsc -p .",
"build:samples": "echo Obsolete.",
"execute:samples": "dev-tool samples run samples-dev",
"build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1",
"build": "tsc -p . && rollup -c 2>&1 && api-extractor run --local",
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
"clean": "rimraf dist dist-* temp types *.tgz *.log",
"execute:samples": "npm run build:samples && dev-tool samples run dist-samples/javascript dist-samples/typescript/dist/dist-samples/typescript/src/",
"extract-api": "tsc -p . && api-extractor run --local",
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"",
"integration-test:browser": "karma start --single-run",
"integration-test:node": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 5000000 --full-trace dist-esm/**/*.spec.js --harmony",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
@ -131,5 +131,16 @@
"typescript": "~4.2.0",
"util": "^0.12.1",
"typedoc": "0.15.2"
},
"//sampleConfiguration": {
"productName": "Azure Search Documents",
"productSlugs": [
"azure",
"azure-cognitive-search",
"azure-search"
],
"requiredResources": {
"Azure Search Documents instance": "https://docs.microsoft.com/azure/search/search-create-service-portal"
}
}
}

Просмотреть файл

@ -1,3 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @summary Demonstrates the SearchIndexingBufferedSender with Autoflush based on size.
*/
import {
SearchIndexingBufferedSender,
AzureKeyCredential,
@ -5,8 +12,8 @@ import {
GeographyPoint,
SearchIndexClient
} from "@azure/search-documents";
import { createIndex, documentKeyRetriever, WAIT_TIME } from "../../utils/setup";
import { Hotel } from "../../utils/interfaces";
import { createIndex, documentKeyRetriever, WAIT_TIME } from "./setup";
import { Hotel } from "./interfaces";
import { delay } from "@azure/core-http";
import * as dotenv from "dotenv";
dotenv.config();
@ -18,9 +25,9 @@ dotenv.config();
* when the size of the batch is greater than threshold (which is set to 1000)
* by default.
*/
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
const TEST_INDEX_NAME = "hotel-live-sample-test3";
const endpoint = process.env.ENDPOINT || "";
const apiKey = process.env.SEARCH_API_ADMIN_KEY || "";
const TEST_INDEX_NAME = "example-index-sample-4";
function getDocumentsArray(size: number): Hotel[] {
const array: Hotel[] = [];
@ -51,7 +58,12 @@ function getDocumentsArray(size: number): Hotel[] {
return array;
}
export async function main() {
async function main() {
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
console.log(`Running SearchIndexingBufferedSender-uploadDocuments-With Auto Flush Sizes Sample`);
const credential = new AzureKeyCredential(apiKey);

Просмотреть файл

@ -1,3 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @summary Demonstrates the SearchIndexingBufferedSender with Autoflush based on timer.
*/
import {
SearchIndexingBufferedSender,
AzureKeyCredential,
@ -6,8 +13,8 @@ import {
SearchIndexClient,
DEFAULT_FLUSH_WINDOW
} from "@azure/search-documents";
import { createIndex, documentKeyRetriever, WAIT_TIME } from "../../utils/setup";
import { Hotel } from "../../utils/interfaces";
import { createIndex, documentKeyRetriever, WAIT_TIME } from "./setup";
import { Hotel } from "./interfaces";
import { delay } from "@azure/core-http";
import * as dotenv from "dotenv";
dotenv.config();
@ -19,11 +26,16 @@ dotenv.config();
* when the time interval is met. The time interval is set to 60000ms
* by default.
*/
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
const TEST_INDEX_NAME = "hotel-live-sample-test2";
const endpoint = process.env.ENDPOINT || "";
const apiKey = process.env.SEARCH_API_ADMIN_KEY || "";
const TEST_INDEX_NAME = "example-index-sample-5";
export async function main() {
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
console.log(`Running SearchIndexingBufferedSender-uploadDocuments-With Auto Flush Timer Sample`);
const credential = new AzureKeyCredential(apiKey);

Просмотреть файл

@ -1,3 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @summary Demonstrates the SearchIndexingBufferedSender with Manual Flush.
*/
import {
SearchIndexingBufferedSender,
AzureKeyCredential,
@ -5,8 +12,8 @@ import {
GeographyPoint,
SearchIndexClient
} from "@azure/search-documents";
import { createIndex, documentKeyRetriever, WAIT_TIME } from "../../utils/setup";
import { Hotel } from "../../utils/interfaces";
import { createIndex, documentKeyRetriever, WAIT_TIME } from "./setup";
import { Hotel } from "./interfaces";
import { delay } from "@azure/core-http";
import * as dotenv from "dotenv";
dotenv.config();
@ -16,11 +23,16 @@ dotenv.config();
* In this sample, the autoFlush is set to false. i.e. the user
* wants to call the flush manually.
*/
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
const TEST_INDEX_NAME = "hotel-live-sample-test1";
const endpoint = process.env.ENDPOINT || "";
const apiKey = process.env.SEARCH_API_ADMIN_KEY || "";
const TEST_INDEX_NAME = "example-index-sample-6";
export async function main() {
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
console.log(`Running SearchIndexingBufferedSender-uploadDocuments-Without AutoFlush Sample`);
const credential = new AzureKeyCredential(apiKey);

Просмотреть файл

@ -0,0 +1,97 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @summary Demonstrates the DataSource Connection Operations.
*/
import {
SearchIndexerClient,
AzureKeyCredential,
SearchIndexerDataSourceConnection
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.ENDPOINT || "";
const apiKey = process.env.SEARCH_API_ADMIN_KEY || "";
const connectionString = process.env.CONNECTION_STRING || "";
const dataSourceConnectionName = "example-ds-connection-sample-1";
async function createDataSourceConnection(
dataSourceConnectionName: string,
client: SearchIndexerClient
) {
console.log(`Creating DS Connection Operation`);
const dataSourceConnection: SearchIndexerDataSourceConnection = {
name: dataSourceConnectionName,
description: "My Data Source 1",
type: "cosmosdb",
container: {
name: "my-container-1"
},
connectionString
};
await client.createDataSourceConnection(dataSourceConnection);
}
async function getAndUpdateDataSourceConnection(
dataSourceConnectionName: string,
client: SearchIndexerClient
) {
console.log(`Get And Update DS Connection Operation`);
const ds: SearchIndexerDataSourceConnection = await client.getDataSourceConnection(
dataSourceConnectionName
);
ds.container.name = "Listings_5K_KingCounty_WA";
console.log(`Updating Container Name of Datasource Connection ${dataSourceConnectionName}`);
await client.createOrUpdateDataSourceConnection(ds);
}
async function listDataSourceConnections(client: SearchIndexerClient) {
console.log(`List DS Connection Operation`);
const listOfDataSourceConnections: Array<SearchIndexerDataSourceConnection> = await client.listDataSourceConnections();
console.log(`List of Data Source Connections`);
console.log(`*******************************`);
for (let ds of listOfDataSourceConnections) {
console.log(`Name: ${ds.name}`);
console.log(`Description: ${ds.description}`);
console.log(`Connection String: ${ds.connectionString}`);
console.log(`Data Change Detection Policy: ${ds.dataChangeDetectionPolicy}`);
console.log(`Data Deletion Detection Policy: ${ds.dataDeletionDetectionPolicy}`);
console.log(`Etag: ${ds.etag}`);
console.log(`DataContainer`);
console.log(`\tName: ${ds.container.name}`);
console.log(`\tQuery: ${ds.container.query}`);
console.log();
}
}
async function deleteDataSourceConnection(
dataSourceConnectionName: string,
client: SearchIndexerClient
) {
console.log(`Deleting DS Connection Operation`);
await client.deleteDataSourceConnection(dataSourceConnectionName);
}
async function main() {
console.log(`Running DS Connection Operations Sample....`);
if (!endpoint || !apiKey || !connectionString) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
try {
await createDataSourceConnection(dataSourceConnectionName, client);
await getAndUpdateDataSourceConnection(dataSourceConnectionName, client);
await listDataSourceConnections(client);
} finally {
await deleteDataSourceConnection(dataSourceConnectionName, client);
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -0,0 +1,158 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @summary Demonstrates the Index Operations.
*/
import {
SearchIndexClient,
AzureKeyCredential,
SearchIndex,
SearchIndexStatistics
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.ENDPOINT || "";
const apiKey = process.env.SEARCH_API_ADMIN_KEY || "";
const indexName = "example-index-sample-1";
async function createIndex(indexName: string, client: SearchIndexClient) {
console.log(`Creating Index Operation`);
const index: SearchIndex = {
name: indexName,
fields: [
{
type: "Edm.String",
name: "id",
key: true
},
{
type: "Edm.Double",
name: "awesomenessLevel",
sortable: true,
filterable: true,
facetable: true
},
{
type: "Edm.String",
name: "description",
searchable: true
},
{
type: "Edm.ComplexType",
name: "details",
fields: [
{
type: "Collection(Edm.String)",
name: "tags",
searchable: true
}
]
},
{
type: "Edm.Int32",
name: "hiddenWeight",
hidden: true
}
]
};
await client.createIndex(index);
}
async function getAndUpdateIndex(indexName: string, client: SearchIndexClient) {
console.log(`Get And Update Index Operation`);
const index: SearchIndex = await client.getIndex(indexName);
index.fields.push({
type: "Edm.DateTimeOffset",
name: "lastUpdatedOn",
filterable: true
});
await client.createOrUpdateIndex(index);
}
async function getIndexStatistics(indexName: string, client: SearchIndexClient) {
console.log(`Get Index Statistics Operation`);
const statistics: SearchIndexStatistics = await client.getIndexStatistics(indexName);
console.log(`Document Count: ${statistics.documentCount}`);
console.log(`Storage Size: ${statistics.storageSize}`);
}
async function getServiceStatistics(client: SearchIndexClient) {
console.log(`Get Service Statistics Operation`);
const { counters, limits } = await client.getServiceStatistics();
console.log(`Counters`);
console.log(`========`);
console.log(`\tDocument Counter`);
console.log(`\t\tUsage: ${counters.documentCounter.usage}`);
console.log(`\t\tQuota: ${counters.documentCounter.quota}`);
console.log(`\tIndex Counter`);
console.log(`\t\tUsage: ${counters.indexCounter.usage}`);
console.log(`\t\tQuota: ${counters.indexCounter.quota}`);
console.log(`\tIndexer Counter`);
console.log(`\t\tUsage: ${counters.indexerCounter.usage}`);
console.log(`\t\tQuota: ${counters.indexerCounter.quota}`);
console.log(`\tData Source Counter`);
console.log(`\t\tUsage: ${counters.dataSourceCounter.usage}`);
console.log(`\t\tQuota: ${counters.dataSourceCounter.quota}`);
console.log(`\tStorage Size Counter`);
console.log(`\t\tUsage: ${counters.storageSizeCounter.usage}`);
console.log(`\t\tQuota: ${counters.storageSizeCounter.quota}`);
console.log(`\tSynonym Map Counter`);
console.log(`\t\tUsage: ${counters.synonymMapCounter.usage}`);
console.log(`\t\tQuota: ${counters.synonymMapCounter.quota}`);
console.log();
console.log(`Limits`);
console.log(`======`);
console.log(`\tMax Fields Per Index: ${limits.maxFieldsPerIndex}`);
console.log(`\tMax Field Nesting Depth Per Index: ${limits.maxFieldNestingDepthPerIndex}`);
console.log(
`\tMax Complex Collection Fields Per Index: ${limits.maxComplexCollectionFieldsPerIndex}`
);
console.log(
`\tMax Complex Objects In Collections Per Document: ${limits.maxComplexObjectsInCollectionsPerDocument}`
);
}
async function listIndexes(client: SearchIndexClient) {
console.log(`List Indexes Operation`);
const result = await client.listIndexes();
let listOfIndexes = await result.next();
console.log(`List of Indexes`);
console.log(`***************`);
while (!listOfIndexes.done) {
console.log(`Name: ${listOfIndexes.value.name}`);
console.log(`Similarity Algorithm: ${listOfIndexes.value.similarity?.odatatype}`);
console.log();
listOfIndexes = await result.next();
}
}
async function deleteIndex(indexName: string, client: SearchIndexClient) {
console.log(`Deleting Index Operation`);
await client.deleteIndex(indexName);
}
async function main() {
console.log(`Running Index Operations Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
try {
await createIndex(indexName, client);
await getAndUpdateIndex(indexName, client);
await getIndexStatistics(indexName, client);
await getServiceStatistics(client);
await listIndexes(client);
} finally {
await deleteIndex(indexName, client);
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -0,0 +1,119 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @summary Demonstrates the Indexer Operations.
*/
import {
SearchIndexerClient,
AzureKeyCredential,
SearchIndexer,
SearchIndexerStatus
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.ENDPOINT || "";
const apiKey = process.env.SEARCH_API_ADMIN_KEY || "";
const dataSourceName = process.env.DATA_SOURCE_NAME || "";
const targetIndexName = process.env.TARGET_INDEX_NAME || "";
const indexerName = "example-indexer-sample-1";
async function createIndexer(indexerName: string, client: SearchIndexerClient) {
console.log(`Creating Indexer Operation`);
const indexer: SearchIndexer = {
name: indexerName,
description: "Description for Sample Indexer",
dataSourceName,
targetIndexName,
isDisabled: false
};
await client.createIndexer(indexer);
}
async function getAndUpdateIndexer(indexerName: string, client: SearchIndexerClient) {
console.log(`Get And Update Indexer Operation`);
const indexer: SearchIndexer = await client.getIndexer(indexerName);
indexer.isDisabled = true;
await client.createOrUpdateIndexer(indexer);
indexer.isDisabled = false;
await client.createOrUpdateIndexer(indexer);
}
async function getIndexerStatus(indexerName: string, client: SearchIndexerClient) {
console.log(`Get Indexer Status Operation`);
const indexerStatus: SearchIndexerStatus = await client.getIndexerStatus(indexerName);
console.log(`Status: ${indexerStatus.status}`);
console.log(`Limits`);
console.log(`******`);
console.log(
`MaxDocumentContentCharactersToExtract: ${indexerStatus.limits.maxDocumentContentCharactersToExtract}`
);
console.log(`MaxDocumentExtractionSize: ${indexerStatus.limits.maxDocumentExtractionSize}`);
console.log(`MaxRunTime: ${indexerStatus.limits.maxRunTime}`);
}
async function listIndexers(client: SearchIndexerClient) {
console.log(`List Indexers Operation`);
const listOfIndexers: Array<SearchIndexer> = await client.listIndexers();
console.log(`\tList of Indexers`);
console.log(`\t****************`);
for (let indexer of listOfIndexers) {
console.log(`Name: ${indexer.name}`);
console.log(`Description: ${indexer.description}`);
console.log(`Data Source Name: ${indexer.dataSourceName}`);
console.log(`Skillset Name: ${indexer.skillsetName}`);
console.log(`Target Index Name: ${indexer.targetIndexName}`);
console.log(`Indexing Schedule`);
console.log(`\tInterval: ${indexer.schedule?.interval}`);
console.log(`\tStart Time: ${indexer.schedule?.startTime}`);
console.log(`Is Disabled: ${indexer.isDisabled}`);
console.log(`ETag: ${indexer.etag}`);
console.log(`Parameters`);
console.log(`\tBatch Size: ${indexer.parameters?.batchSize}`);
console.log(`\tMax Failed Items: ${indexer.parameters?.maxFailedItems}`);
console.log(`\tMax Failed Items Per Batch: ${indexer.parameters?.maxFailedItemsPerBatch}`);
console.log();
}
}
async function resetIndexer(indexerName: string, client: SearchIndexerClient) {
console.log(`Reset Indexer Operation`);
await client.resetIndexer(indexerName);
}
async function deleteIndexer(indexerName: string, client: SearchIndexerClient) {
console.log(`Deleting Indexer Operation`);
await client.deleteIndexer(indexerName);
}
async function runIndexer(indexerName: string, client: SearchIndexerClient) {
console.log(`Run Indexer Operation`);
await client.runIndexer(indexerName);
}
async function main() {
console.log(`Running Indexer Operations Sample....`);
if (!endpoint || !apiKey || !dataSourceName || !targetIndexName) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
try {
await createIndexer(indexerName, client);
await getAndUpdateIndexer(indexerName, client);
await getIndexerStatus(indexerName, client);
await listIndexers(client);
await resetIndexer(indexerName, client);
await runIndexer(indexerName, client);
} finally {
await deleteIndexer(indexerName, client);
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,6 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @summary Defines the Hotel Interface.
*/
import { GeographyPoint } from "@azure/search-documents";
export interface Hotel {

Просмотреть файл

@ -1,6 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @summary Defines the utility methods.
*/
import { SearchIndexClient, SearchIndex, KnownAnalyzerNames } from "@azure/search-documents";
import { Hotel } from "./interfaces";

Просмотреть файл

@ -0,0 +1,127 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @summary Demonstrates the Skillset Operations.
*/
import {
SearchIndexerClient,
AzureKeyCredential,
SearchIndexerSkillset
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.ENDPOINT || "";
const apiKey = process.env.SEARCH_API_ADMIN_KEY || "";
const skillsetName = "example-skillset-sample-1";
async function createSkillset(skillsetName: string, client: SearchIndexerClient) {
console.log(`Creating Skillset Operation`);
const skillset: SearchIndexerSkillset = {
name: skillsetName,
description: `Skillset description`,
skills: [
{
odatatype: "#Microsoft.Skills.Text.EntityRecognitionSkill",
inputs: [
{
name: "text",
source: "/document/merged_content"
},
{
name: "languageCode",
source: "/document/language"
}
],
outputs: [
{
name: "persons",
targetName: "people"
},
{
name: "organizations",
targetName: "organizations"
},
{
name: "locations",
targetName: "locations"
}
]
}
]
};
await client.createSkillset(skillset);
}
async function getAndUpdateSkillset(skillsetName: string, client: SearchIndexerClient) {
console.log(`Get And Update Skillset Operation`);
const skillset: SearchIndexerSkillset = await client.getSkillset(skillsetName);
skillset.skills[0].outputs = [
{
name: "persons",
targetName: "people"
},
{
name: "organizations",
targetName: "organizations"
}
];
await client.createOrUpdateSkillset(skillset);
}
async function listSkillsets(client: SearchIndexerClient) {
console.log(`List Skillset Operation`);
const listOfSkillsets: Array<SearchIndexerSkillset> = await client.listSkillsets();
console.log(`\tList of Skillsets`);
console.log(`\t******************`);
for (let skillset of listOfSkillsets) {
console.log(`Name: ${skillset.name}`);
console.log(`Description: ${skillset.description}`);
console.log(`Skills`);
console.log(`******`);
for (let skill of skillset.skills) {
console.log(`ODataType: ${skill.odatatype}`);
console.log(`Inputs`);
for (let input of skill.inputs) {
console.log(`\tName: ${input.name}`);
console.log(`\tSource: ${input.source}`);
}
console.log(`Outputs`);
for (let output of skill.outputs) {
console.log(`\tName: ${output.name}`);
console.log(`\tTarget Name: ${output.targetName}`);
}
}
}
}
async function deleteSkillset(skillsetName: string, client: SearchIndexerClient) {
console.log(`Deleting Skillset Operation`);
await client.deleteSkillset(skillsetName);
}
async function main() {
console.log(`Running Skillset Operations Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
try {
await createSkillset(skillsetName, client);
await getAndUpdateSkillset(skillsetName, client);
await listSkillsets(client);
} finally {
await deleteSkillset(skillsetName, client);
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -0,0 +1,71 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @summary Demonstrates the SynonymMap Operations.
*/
import { SearchIndexClient, AzureKeyCredential, SynonymMap } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.ENDPOINT || "";
const apiKey = process.env.SEARCH_API_ADMIN_KEY || "";
const synonymMapName = "example-synonymmap-sample-1";
async function createSynonymMap(synonymMapName: string, client: SearchIndexClient) {
console.log(`Creating SynonymMap Operation`);
const sm: SynonymMap = {
name: synonymMapName,
synonyms: ["United States, United States of America => USA", "Washington, Wash. => WA"]
};
await client.createSynonymMap(sm);
}
async function getAndUpdateSynonymMap(synonymMapName: string, client: SearchIndexClient) {
console.log(`Get And Update SynonymMap Operation`);
const sm: SynonymMap = await client.getSynonymMap(synonymMapName);
console.log(`Update synonyms Synonym Map my-synonymmap`);
sm.synonyms.push("Florida, Fld. => FL");
await client.createOrUpdateSynonymMap(sm);
}
async function listSynonymMaps(client: SearchIndexClient) {
console.log(`List SynonymMaps Operation`);
const listOfSynonymMaps: Array<SynonymMap> = await client.listSynonymMaps();
console.log(`List of SynonymMaps`);
console.log(`*******************`);
for (let sm of listOfSynonymMaps) {
console.log(`Name: ${sm.name}`);
console.log(`Synonyms`);
for (let synonym of sm.synonyms) {
console.log(synonym);
}
}
}
async function deleteSynonymMap(synonymMapName: string, client: SearchIndexClient) {
console.log(`Deleting SynonymMap Operation`);
await client.deleteSynonymMap(synonymMapName);
}
async function main() {
console.log(`Running Index Operations Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
try {
await createSynonymMap(synonymMapName, client);
await getAndUpdateSynonymMap(synonymMapName, client);
await listSynonymMaps(client);
} finally {
await deleteSynonymMap(synonymMapName, client);
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,133 +0,0 @@
# Azure Cognitive Search client library samples for JavaScript
These sample programs show how to use the JavaScript client libraries for Azure Cognitive Search in some common scenarios.
| **File Name** | **Description** |
| ---------------------------- | ------------------------ |
| **Data Source Connections** |
| [createDataSourceConnection.js][createDataSourceConnection] | Creates a Datasource Connection |
| [createOrUpdateDataSourceConnection.js][createOrUpdateDataSourceConnection] | Updates a Datasource Connection |
| [deleteDataSourceConnectionByName.js][deleteDataSourceConnectionByName] | Deletes Datasource Connection by Name |
| [deleteDataSourceConnectionByObject.js][deleteDataSourceConnectionByObject] | Deletes Datasource Connection by Object |
| [getDataSourceConnection.js][getDataSourceConnection] | Gets a Datasource Connection |
| [listDataSourceConnectionNames.js][listDataSourceConnectionNames] | List names of Datasource Connections |
| [listDataSourceConnections.js][listDataSourceConnections] | List Datasource Connections |
| **Indexers** |
| [createIndexer.js][createIndexer] | Creates an Indexer |
| [createOrUpdateIndexer.js][createOrUpdateIndexer] | Updates an Indexer |
| [deleteIndexerByName.js][deleteIndexerByName] | Deletes Indexer by Name |
| [deleteIndexerByObject.js][deleteIndexerByObject] | Deletes Indexer by Object |
| [getIndexer.js][getIndexer] | Gets an Indexer |
| [getIndexerStatus.js][getIndexerStatus] | Gets the status of an Indexer |
| [listIndexerNames.js][listIndexerNames] | List names of Indexers |
| [listIndexers.js][listIndexers] | List Indexers |
| [resetIndexer.js][resetIndexer] | Resets an Indexer |
| [runIndexer.js][runIndexer] | Runs an Indexer |
| **Indexes** |
| [analyzeText.js][analyzeText] | Analyzes a given text |
| [createIndex.js][createIndex] | Creates an Index |
| [createOrUpdateIndex.js][createOrUpdateIndex] | Updates an Index |
| [deleteIndexByName.js][deleteIndexByName] | Deletes Index by Name |
| [deleteIndexByObject.js][deleteIndexByObject] | Deletes Index by Object |
| [getIndex.js][getIndex] | Gets an Index |
| [getIndexStatistics.js][getIndexStatistics] | Gets the Statistics of an Index |
| [listIndexes.js][listIndexes] | List Indexes |
| [listIndexNames.js][listIndexNames] | List Names of Indexes |
| **Skillsets** |
| [createOrUpdateSkillset.js][createOrUpdateSkillset] | Updates a skillset |
| [createSkillset.js][createSkillset] | Creates a skillset |
| [deleteSkillsetByName.js][deleteSkillsetByName] | Deletes a Skillset by Name |
| [deleteSkillsetByObject.js][deleteSkillsetByObject] | Deletes a Skillset by Object |
| [getSkillset.js][getSkillset] | Gets a skillset |
| [listSkillsets.js][listSkillsets] | List all skillsets |
| [listSkillsetsNames.js][listSkillsetsNames] | List names of skillsets |
| **SynonymMaps** |
| [createOrUpdateSynonymMap.js][createOrUpdateSynonymMap] | Updates a synonym map |
| [createSynonymMap.js][createSynonymMap] | Creates a synonym map |
| [deleteSynonymMapByName.js][deleteSynonymMapByName] | Deletes a synonym map by Name |
| [deleteSynonymMapByObject.js][deleteSynonymMapByObject] | Deletes a synonym map by object |
| [getSynonymMap.js][getSynonymMap] | Gets a synonym map |
| [listSynonymMapNames.js][listSynonymMapNames] | List names of synonym maps |
| [listSynonymMaps.js][listSynonymMaps] | List all synonym maps |
## Prerequisites
The samples are compatible with [LTS versions of Node.js](https://nodejs.org/about/releases/).
You need [an Azure subscription][freesub] and [an Azure Cognitive Search service][search_resource] to run these sample programs. Samples retrieve credentials to access the Azure Cognitive Search endpoint from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function.
Adapting the samples to run in the browser may require some additional consideration. For details, please see the [package README][package].
## Setup
To run the samples using the published version of the package:
1. Install the dependencies using `npm`:
```bash
npm install
```
2. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically.
3. Run whichever samples you like (note that some samples may require additional setup, see the table above):
```bash
node readonlyQuery.js
```
Alternatively, run a single sample with the correct environment variables set (step 3 is not required if you do this), for example (cross-platform):
```bash
npx cross-env SEARCH_API_ENDPOINT="<endpoint>" SEARCH_API_KEY="<api key>" node readonlyQuery.js
```
## Next Steps
Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients.
[readonly]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/readonlyQuery.js
[apiref]: https://aka.ms/azsdk/js/search/docs
[search_resource]: https://docs.microsoft.com/azure/search/search-create-service-portal
[freesub]: https://azure.microsoft.com/free/
[package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/README.md
[createDataSourceConnection]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/dataSourceConnections/createDataSourceConnection.js
[createOrUpdateDataSourceConnection]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/dataSourceConnections/createOrUpdateDataSourceConnection.js
[deleteDataSourceConnectionByName]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/dataSourceConnections/deleteDataSourceConnectionByName.js
[deleteDataSourceConnectionByObject]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/dataSourceConnections/deleteDataSourceConnectionByObject.js
[getDataSourceConnection]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/dataSourceConnections/getDataSourceConnection.js
[listDataSourceConnectionNames]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/dataSourceConnections/listDataSourceConnectionNames.js
[listDataSourceConnections]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/dataSourceConnections/listDataSourceConnections.js
[createIndexer]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexers/createIndexer.js
[createOrUpdateIndexer]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexers/createOrUpdateIndexer.js
[deleteIndexerByName]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexers/deleteIndexerByName.js
[deleteIndexerByObject]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexers/deleteIndexerByObject.js
[getIndexer]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexers/getIndexer.js
[getIndexerStatus]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexers/getIndexerStatus.js
[listIndexerNames]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexers/listIndexerNames.js
[listIndexers]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexers/listIndexers.js
[resetIndexer]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexers/resetIndexer.js
[runIndexer]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexers/runIndexer.js
[analyzeText]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexes/analyzeText.js
[createIndex]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexes/createIndex.js
[createOrUpdateIndex]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexes/createOrUpdateIndex.js
[deleteIndexByName]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexes/deleteIndexByName.js
[deleteIndexByObject]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexes/deleteIndexByObject.js
[getIndex]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexes/getIndex.js
[getIndexStatistics]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexes/getIndexStatistics.js
[listIndexes]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexes/listIndexes.js
[listIndexNames]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/indexes/listIndexNames.js
[createOrUpdateSkillset]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/skillSets/createOrUpdateSkillset.js
[createSkillset]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/skillSets/createSkillset.js
[deleteSkillsetByName]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/skillSets/deleteSkillsetByName.js
[deleteSkillsetByObject]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/skillSets/deleteSkillsetByObject.js
[getSkillset]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/skillSets/getSkillset.js
[listSkillsets]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/skillSets/listSkillsets.js
[listSkillsetsNames]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/skillSets/listSkillsetsNames.js
[createOrUpdateSynonymMap]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/synonymMaps/createOrUpdateSynonymMap.js
[createSynonymMap]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/synonymMaps/createSynonymMap.js
[deleteSynonymMapByName]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/synonymMaps/deleteSynonymMapByName.js
[deleteSynonymMapByObject]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/synonymMaps/deleteSynonymMapByObject.js
[getSynonymMap]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/synonymMaps/getSynonymMap.js
[listSynonymMapNames]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/synonymMaps/listSynonymMapNames.js
[listSynonymMaps]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/javascript/src/synonymMaps/listSynonymMaps.js

Просмотреть файл

@ -1,6 +0,0 @@
# Used in most samples. Retrieve these values from a Cognitive Search instance
# in the Azure Portal.
SEARCH_API_KEY=<search api key>
SEARCH_API_ENDPOINT=https://<resource name>.search.windows.net
INDEX_NAME=hotels-sample-index

Просмотреть файл

@ -1,37 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexerClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Create Datasource Connection Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const dataSourceConnection = {
name: "my-data-source-2",
description: "My Data Source 1",
type: "cosmosdb",
container: {
name: "my-container-1"
},
connectionString:
"AccountEndpoint=https://hotels-docbb.documents.azure.com:443/;AccountKey=4UPsNZyFAjgZ1tzHPGZaxS09XcwLrIawbXBWk6IixcxJoSePTcjBn0mi53XiKWu8MaUgowUhIovOv7kjksqAug==;Database=SampleData"
};
await client.createDataSourceConnection(dataSourceConnection);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,29 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexerClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running CreateOrUpdate Datasource Connection Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Datasource Connection my-data-source-2`);
const ds = await client.getDataSourceConnection("my-data-source-2")
ds.container.name = "Listings_5K_KingCounty_WA";
console.log(`Updating Container Name of Datasource Connection my-data-source-2`);
await client.createOrUpdateDataSourceConnection(ds);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,26 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexerClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Delete Datasource Connection Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Deleting Datasource Connection my-data-source-2`);
await client.deleteDataSourceConnection("my-data-source-2")
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,28 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexerClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Delete Datasource Connection Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Datasource Connection my-data-source-2`);
const ds = await client.getDataSourceConnection("my-data-source-2");
console.log(`Deleting Datasource Connection my-data-source-2`);
await client.deleteDataSourceConnection(ds);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,36 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexerClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Get Datasource Connection Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Datasource Connection my-data-source-2`);
const ds = await client.getDataSourceConnection("my-data-source-2")
console.log(`Name: ${ds.name}`);
console.log(`Description: ${ds.description}`);
console.log(`Connection String: ${ds.connectionString}`);
console.log(`Data Change Detection Policy: ${ds.dataChangeDetectionPolicy}`);
console.log(`Data Deletion Detection Policy: ${ds.dataDeletionDetectionPolicy}`);
console.log(`Etag: ${ds.etag}`);
console.log(`DataContainer`);
console.log(`\tName: ${ds.container.name}`);
console.log(`\tQuery: ${ds.container.query}`);
console.log();
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,32 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexerClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running List Datasource Connection Names Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const listOfDataSourceConnectionNames = await client.listDataSourceConnectionsNames();
console.log(`Names of Data Source Connections`);
console.log(`*******************************`);
for(const ds of listOfDataSourceConnectionNames) {
console.log(ds);
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,40 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexerClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running List Datasource Connections Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const listOfDataSourceConnections = await client.listDataSourceConnections();
console.log(`List of Data Source Connections`);
console.log(`*******************************`)
for(const ds of listOfDataSourceConnections) {
console.log(`Name: ${ds.name}`);
console.log(`Description: ${ds.description}`);
console.log(`Connection String: ${ds.connectionString}`);
console.log(`Data Change Detection Policy: ${ds.dataChangeDetectionPolicy}`);
console.log(`Data Deletion Detection Policy: ${ds.dataDeletionDetectionPolicy}`);
console.log(`Etag: ${ds.etag}`);
console.log(`DataContainer`);
console.log(`\tName: ${ds.container.name}`);
console.log(`\tQuery: ${ds.container.query}`);
console.log();
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,30 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const { SearchIndexerClient, AzureKeyCredential } = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Create Indexer Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const indexer = {
name: "my-azure-indexer-1",
description: "Description for Sample Indexer",
dataSourceName: "realestate-us-sample",
targetIndexName: "realestate-us-sample-index",
isDisabled: false
};
await client.createIndexer(indexer);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,26 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const { SearchIndexerClient, AzureKeyCredential } = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Create Or Update Indexer Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Getting Indexer my-azure-indexer-1`);
const indexer = await client.getIndexer("my-azure-indexer-1");
console.log(`Updating isDisabled status of Indexer my-azure-indexer-1`);
indexer.isDisabled = true;
await client.createOrUpdateIndexer(indexer);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,26 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexerClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Delete Indexer Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Deleting Indexer my-azure-indexer-1`);
await client.deleteIndexer("my-azure-indexer-1")
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,29 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexerClient,
AzureKeyCredential,
SearchIndexer
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Delete Indexer Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Getting Indexer my-azure-indexer-1`);
const indexer = await client.getIndexer("my-azure-indexer-1");
console.log(`Deleting Indexer my-azure-indexer-1`);
await client.deleteIndexer(indexer);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,30 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const { SearchIndexerClient, AzureKeyCredential, SearchIndexer } = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Get Indexer Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Getting Indexer my-azure-indexer-1`);
const indexer = await client.getIndexer("my-azure-indexer-1");
console.log(`Name: ${indexer.name}`);
console.log(`Description: ${indexer.description}`);
console.log(`Data Source Name: ${indexer.dataSourceName}`);
console.log(`Skillset Name: ${indexer.skillsetName}`);
console.log(`Target Index Name: ${indexer.targetIndexName}`);
console.log(`Is Disabled: ${indexer.isDisabled}`);
console.log(`ETag: ${indexer.etag}`);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,29 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const { SearchIndexerClient, AzureKeyCredential } = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Get Indexer Status Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Getting Indexer Status of my-azure-indexer-1`);
const indexerStatus = await client.getIndexerStatus("my-azure-indexer-1");
console.log(`Status: ${indexerStatus.status}`);
console.log(`Limits`);
console.log(`******`);
console.log(`MaxDocumentContentCharactersToExtract: ${indexerStatus.limits.maxDocumentContentCharactersToExtract}`)
console.log(`MaxDocumentExtractionSize: ${indexerStatus.limits.maxDocumentExtractionSize}`)
console.log(`MaxRunTime: ${indexerStatus.limits.maxRunTime}`);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,28 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const { SearchIndexerClient, AzureKeyCredential } = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running List Indexer Names Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const listOfIndexerNames = await client.listIndexersNames();
console.log(`\tNames of Indexers`);
console.log(`\t*****************`);
for(const indexerName of listOfIndexerNames) {
console.log(`${indexerName}`);
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,35 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const { SearchIndexerClient, AzureKeyCredential } = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running List Indexers Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const listOfIndexers = await client.listIndexers();
console.log(`\tList of Indexers`);
console.log(`\t****************`);
for(const indexer of listOfIndexers) {
console.log(`Name: ${indexer.name}`);
console.log(`Description: ${indexer.description}`);
console.log(`Data Source Name: ${indexer.dataSourceName}`);
console.log(`Skillset Name: ${indexer.skillsetName}`);
console.log(`Target Index Name: ${indexer.targetIndexName}`);
console.log(`Is Disabled: ${indexer.isDisabled}`);
console.log(`ETag: ${indexer.etag}`);
console.log();
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,23 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const { SearchIndexerClient, AzureKeyCredential } = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Reset Indexer Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Reset Indexer my-azure-indexer-1`);
await client.resetIndexer("my-azure-indexer-1");
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,23 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const { SearchIndexerClient, AzureKeyCredential } = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Run Indexer Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Run Indexer my-azure-indexer-1`);
await client.runIndexer("my-azure-indexer-1");
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,40 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/* eslint-disable no-unused-expressions */
const {
SearchIndexClient,
AzureKeyCredential,
KnownTokenFilterNames
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Analyze Text Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
const index = await client.getIndex("example-index");
// Note adding this analyzer to an existing index will cause it to be unresponsive
// for a short period, hence the need to pass `allowIndexDowntime: true`.
await client.createOrUpdateIndex(index, { allowIndexDowntime: true });
const result = await client.analyzeText("example-index", {
text: "MSFT is xyzzy Great!",
analyzerName: "example-analyzer"
});
console.log(result.tokens);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,63 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Create Index Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
const index = {
name: "example-index-2",
fields: [
{
type: "Edm.String",
name: "id",
key: true
},
{
type: "Edm.Double",
name: "awesomenessLevel",
sortable: true,
filterable: true,
facetable: true
},
{
type: "Edm.String",
name: "description",
searchable: true
},
{
type: "Edm.ComplexType",
name: "details",
fields: [
{
type: "Collection(Edm.String)",
name: "tags",
searchable: true
}
]
},
{
type: "Edm.Int32",
name: "hiddenWeight",
hidden: true
}
]
};
await client.createIndex(index);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,35 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Create Or Update Index Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Index example-index-2`);
const index = await client.getIndex("example-index-2");
console.log(`Adding fields to Index example-index-2`);
index.fields.push({
type: "Edm.DateTimeOffset",
name: "lastUpdatedOn",
filterable: true
});
await client.createOrUpdateIndex(index);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,26 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Delete Index Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Deleting Index example-index-2`);
await client.deleteIndex("example-index-2")
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,28 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Delete Index Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Index example-index-2`);
const index = await client.getIndex("example-index-2");
console.log(`Deleting Index example-index-2`);
await client.deleteIndex(index);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,28 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Get Index Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Index example-index`);
const index = await client.getIndex("example-index");
console.log(`Name: ${index.name}`);
console.log(`Similarity Algorithm: ${index.similarity.odatatype}`);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,28 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Get Index Statistics Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Index Statistics of example-index`);
const statistics = await client.getIndexStatistics("example-index");
console.log(`Document Count: ${statistics.documentCount}`);
console.log(`Storage Size: ${statistics.storageSize}`);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,52 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Get Service Statistics Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
const {counters, limits} = await client.getServiceStatistics();
console.log(`Counters`);
console.log(`========`);
console.log(`\tDocument Counter`);
console.log(`\t\tUsage: ${counters.documentCounter.usage}`);
console.log(`\t\tQuota: ${counters.documentCounter.quota}`);
console.log(`\tIndex Counter`);
console.log(`\t\tUsage: ${counters.indexCounter.usage}`);
console.log(`\t\tQuota: ${counters.indexCounter.quota}`);
console.log(`\tIndexer Counter`);
console.log(`\t\tUsage: ${counters.indexerCounter.usage}`);
console.log(`\t\tQuota: ${counters.indexerCounter.quota}`);
console.log(`\tData Source Counter`);
console.log(`\t\tUsage: ${counters.dataSourceCounter.usage}`);
console.log(`\t\tQuota: ${counters.dataSourceCounter.quota}`);
console.log(`\tStorage Size Counter`);
console.log(`\t\tUsage: ${counters.storageSizeCounter.usage}`);
console.log(`\t\tQuota: ${counters.storageSizeCounter.quota}`);
console.log(`\tSynonym Map Counter`);
console.log(`\t\tUsage: ${counters.synonymMapCounter.usage}`);
console.log(`\t\tQuota: ${counters.synonymMapCounter.quota}`);
console.log();
console.log(`Limits`);
console.log(`======`);
console.log(`\tMax Fields Per Index: ${limits.maxFieldsPerIndex}`);
console.log(`\tMax Field Nesting Depth Per Index: ${limits.maxFieldNestingDepthPerIndex}`);
console.log(`\tMax Complex Collection Fields Per Index: ${limits.maxComplexCollectionFieldsPerIndex}`);
console.log(`\tMax Complex Objects In Collections Per Document: ${limits.maxComplexObjectsInCollectionsPerDocument}`);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,30 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const { SearchIndexClient, AzureKeyCredential } = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running List Indexes Names Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
const result = await client.listIndexesNames();
let listOfIndexNames = await result.next();
console.log(`List of Index Names`);
console.log(`*******************`);
while (!listOfIndexNames.done) {
console.log(listOfIndexNames.value);
listOfIndexNames = await result.next();
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,32 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const { SearchIndexClient, AzureKeyCredential } = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running List Indexes Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
const result = await client.listIndexes();
let listOfIndexes = await result.next();
console.log(`List of Indexes`);
console.log(`***************`);
while (!listOfIndexes.done) {
console.log(`Name: ${listOfIndexes.value.name}`);
console.log(`Similarity Algorithm: ${listOfIndexes.value.similarity.odatatype}`);
console.log();
listOfIndexes = await result.next();
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,36 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const { SearchIndexerClient, AzureKeyCredential } = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Create Or Update Skillset Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Getting Skillset my-azureblob-skillset`);
const skillset = await client.getSkillset("my-azureblob-skillset");
skillset.skills[0].outputs = [
{
name: "persons",
targetName: "people"
},
{
name: "organizations",
targetName: "organizations"
}
]
await client.createOrUpdateSkillset(skillset);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,55 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const { SearchIndexerClient, AzureKeyCredential } = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Create Skillset Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const skillset = {
name: `my-azureblob-skillset`,
description: `Skillset description`,
skills: [
{
odatatype: "#Microsoft.Skills.Text.EntityRecognitionSkill",
inputs: [
{
name: "text",
source: "/document/merged_content"
},
{
name: "languageCode",
source: "/document/language"
}
],
outputs: [
{
name: "persons",
targetName: "people"
},
{
name: "organizations",
targetName: "organizations"
},
{
name: "locations",
targetName: "locations"
}
]
}
]
};
await client.createSkillset(skillset);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,26 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexerClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Delete Skillset Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Deleting Indexer my-azureblob-skillset`);
await client.deleteSkillset("my-azureblob-skillset")
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,28 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexerClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Delete Skillset Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Getting Skillset my-azureblob-skillset`);
const skillset = await client.getSkillset("my-azureblob-skillset");
console.log(`Deleting Indexer my-azureblob-skillset`);
await client.deleteSkillset(skillset)
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,40 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const { SearchIndexerClient, AzureKeyCredential } = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Get Skillset Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Getting Skillset my-azureblob-skillset`);
const skillset = await client.getSkillset("my-azureblob-skillset");
console.log(`Name: ${skillset.name}`);
console.log(`Description: ${skillset.description}`);
console.log(`Skills`);
console.log(`******`);
for(const skill of skillset.skills) {
console.log(`ODataType: ${skill.odatatype}`);
console.log(`Inputs`);
for(const input of skill.inputs) {
console.log(`\tName: ${input.name}`);
console.log(`\tSource: ${input.source}`);
}
console.log(`Outputs`);
for(const output of skill.outputs) {
console.log(`\tName: ${output.name}`);
console.log(`\tTarget Name: ${output.targetName}`);
}
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,47 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexerClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running List Skillsets Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const listOfSkillsets = await client.listSkillsets();
console.log(`\tList of Skillsets`);
console.log(`\t******************`);
for(const skillset of listOfSkillsets) {
console.log(`Name: ${skillset.name}`);
console.log(`Description: ${skillset.description}`);
console.log(`Skills`);
console.log(`******`);
for(const skill of skillset.skills) {
console.log(`ODataType: ${skill.odatatype}`);
console.log(`Inputs`);
for(const input of skill.inputs) {
console.log(`\tName: ${input.name}`);
console.log(`\tSource: ${input.source}`);
}
console.log(`Outputs`);
for(const output of skill.outputs) {
console.log(`\tName: ${output.name}`);
console.log(`\tTarget Name: ${output.targetName}`);
}
}
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,28 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const { SearchIndexerClient, AzureKeyCredential } = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running List Skillsets Names Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const listOfSkillsetNames = await client.listSkillsetsNames();
console.log(`\tNames of Skillsets`);
console.log(`\t******************`);
for(const skName of listOfSkillsetNames) {
console.log(`${skName}`);
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,29 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Create Or Update SynonymMap Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Synonym Map my-synonymmap`);
const sm = await client.getSynonymMap("my-synonymmap");
console.log(`Update synonyms Synonym Map my-synonymmap`);
sm.synonyms.push("Florida, Fld. => FL");
await client.createOrUpdateSynonymMap(sm);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,29 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Create SynonymMap Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
const sm = {
name: `my-synonymmap`,
synonyms: ["United States, United States of America => USA", "Washington, Wash. => WA"]
};
await client.createSynonymMap(sm);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,26 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Delete SynonymMap Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Deleting SynonymMap my-synonymmap`);
await client.deleteSynonymMap("my-synonymmap")
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,28 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Delete SynonymMap Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Synonym Map my-synonymmap`);
const sm = await client.getSynonymMap("my-synonymmap");
console.log(`Deleting SynonymMap my-synonymmap`);
await client.deleteSynonymMap(sm);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,31 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const {
SearchIndexClient,
AzureKeyCredential
} = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running Get SynonymMap Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Synonym Map my-synonymmap`);
const sm = await client.getSynonymMap("my-synonymmap");
console.log(`Name: ${sm.name}`);
console.log(`Synonyms`);
for(const synonym of sm.synonyms) {
console.log(synonym);
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,28 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const { SearchIndexClient, AzureKeyCredential } = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running List SynonymMap Names Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
const listOfSynonymMapsNames = await client.listSynonymMapsNames();
console.log(`List of SynonymMap Names`);
console.log(`************************`);
for(const smName of listOfSynonymMapsNames) {
console.log(`${smName}`);
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,32 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
const { SearchIndexClient, AzureKeyCredential } = require("@azure/search-documents");
require("dotenv").config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
async function main() {
console.log(`Running List SynonymMaps Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
const listOfSynonymMaps = await client.listSynonymMaps();
console.log(`List of SynonymMaps`);
console.log(`*******************`);
for(const sm of listOfSynonymMaps) {
console.log(`Name: ${sm.name}`);
console.log(`Synonyms`);
for(const synonym of sm.synonyms) {
console.log(synonym);
}
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,10 +0,0 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "typescript/dist",
"lib": ["DOM", "ES6"]
},
"include": ["typescript/src/**.ts", "typescript/src/**/**.ts"],
"exclude": ["typescript/*.json", "**/node_modules/", "../node_modules", "../typings"]
}

Просмотреть файл

@ -1,146 +0,0 @@
# Azure Cognitive Search client library samples for TypeScript
These sample programs show how to use the TypeScript client libraries for Azure Cognitive Search in some common scenarios.
| **File Name** | **Description** |
| ---------------------------- | ------------------------ |
| **Data Source Connections** |
| [createDataSourceConnection.ts][createDataSourceConnection] | Creates a Datasource Connection |
| [createOrUpdateDataSourceConnection.ts][createOrUpdateDataSourceConnection] | Updates a Datasource Connection |
| [deleteDataSourceConnectionByName.ts][deleteDataSourceConnectionByName] | Deletes Datasource Connection by Name |
| [deleteDataSourceConnectionByObject.ts][deleteDataSourceConnectionByObject] | Deletes Datasource Connection by Object |
| [getDataSourceConnection.ts][getDataSourceConnection] | Gets a Datasource Connection |
| [listDataSourceConnectionNames.ts][listDataSourceConnectionNames] | List names of Datasource Connections |
| [listDataSourceConnections.ts][listDataSourceConnections] | List Datasource Connections |
| **Indexers** |
| [createIndexer.ts][createIndexer] | Creates an Indexer |
| [createOrUpdateIndexer.ts][createOrUpdateIndexer] | Updates an Indexer |
| [deleteIndexerByName.ts][deleteIndexerByName] | Deletes Indexer by Name |
| [deleteIndexerByObject.ts][deleteIndexerByObject] | Deletes Indexer by Object |
| [getIndexer.ts][getIndexer] | Gets an Indexer |
| [getIndexerStatus.ts][getIndexerStatus] | Gets the status of an Indexer |
| [listIndexerNames.ts][listIndexerNames] | List names of Indexers |
| [listIndexers.ts][listIndexers] | List Indexers |
| [resetIndexer.ts][resetIndexer] | Resets an Indexer |
| [runIndexer.ts][runIndexer] | Runs an Indexer |
| **Indexes** |
| [analyzeText.ts][analyzeText] | Analyzes a given text |
| [createIndex.ts][createIndex] | Creates an Index |
| [createOrUpdateIndex.ts][createOrUpdateIndex] | Updates an Index |
| [deleteIndexByName.ts][deleteIndexByName] | Deletes Index by Name |
| [deleteIndexByObject.ts][deleteIndexByObject] | Deletes Index by Object |
| [getIndex.ts][getIndex] | Gets an Index |
| [getIndexStatistics.ts][getIndexStatistics] | Gets the Statistics of an Index |
| [listIndexes.ts][listIndexes] | List Indexes |
| [listIndexNames.ts][listIndexNames] | List Names of Indexes |
| **Skillsets** |
| [createOrUpdateSkillset.ts][createOrUpdateSkillset] | Updates a skillset |
| [createSkillset.ts][createSkillset] | Creates a skillset |
| [deleteSkillsetByName.ts][deleteSkillsetByName] | Deletes a Skillset by Name |
| [deleteSkillsetByObject.ts][deleteSkillsetByObject] | Deletes a Skillset by Object |
| [getSkillset.ts][getSkillset] | Gets a skillset |
| [listSkillsets.ts][listSkillsets] | List all skillsets |
| [listSkillsetsNames.ts][listSkillsetsNames] | List names of skillsets |
| **SynonymMaps** |
| [createOrUpdateSynonymMap.ts][createOrUpdateSynonymMap] | Updates a synonym map |
| [createSynonymMap.ts][createSynonymMap] | Creates a synonym map |
| [deleteSynonymMapByName.ts][deleteSynonymMapByName] | Deletes a synonym map by Name |
| [deleteSynonymMapByObject.ts][deleteSynonymMapByObject] | Deletes a synonym map by object |
| [getSynonymMap.ts][getSynonymMap] | Gets a synonym map |
| [listSynonymMapNames.ts][listSynonymMapNames] | List names of synonym maps |
| [listSynonymMaps.ts][listSynonymMaps] | List all synonym maps |
## Prerequisites
The samples are compatible with [LTS versions of Node.js](https://nodejs.org/about/releases/).
Before running the samples in Node, they must be compiled to JavaScript using the TypeScript compiler. For more information on TypeScript, see the [TypeScript documentation][typescript]. Install the TypeScript compiler using
```bash
npm install -g typescript
```
You need [an Azure subscription][freesub] and [an Azure Cognitive Search service][search_resource] to run these sample programs. Samples retrieve credentials to access the Azure Cognitive Search endpoint from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function.
Adapting the samples to run in the browser may require some additional consideration. For details, please see the [package README][package].
## Setup
To run the samples using the published version of the package:
1. Install the dependencies using `npm`:
```bash
npm install
```
2. Compile the samples
```bash
npm run build
```
3. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically.
4. Run whichever samples you like (note that some samples may require additional setup, see the table above):
```bash
node dist/readonlyQuery.js
```
Alternatively, run a single sample with the correct environment variables set (step 3 is not required if you do this), for example (cross-platform):
```bash
npx cross-env SEARCH_API_ENDPOINT="<endpoint>" SEARCH_API_KEY="<api key>" node dist/readonlyQuery.js
```
## Next Steps
Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients.
[readonly]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/readonlyQuery.ts
[apiref]: https://aka.ms/azsdk/js/search/docs
[search_resource]: https://docs.microsoft.com/azure/search/search-create-service-portal
[freesub]: https://azure.microsoft.com/free/
[package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/README.md
[typescript]: https://www.typescriptlang.org/docs/home.html
[createDataSourceConnection]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/dataSourceConnections/createDataSourceConnection.ts
[createOrUpdateDataSourceConnection]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/dataSourceConnections/createOrUpdateDataSourceConnection.ts
[deleteDataSourceConnectionByName]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/dataSourceConnections/deleteDataSourceConnectionByName.ts
[deleteDataSourceConnectionByObject]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/dataSourceConnections/deleteDataSourceConnectionByObject.ts
[getDataSourceConnection]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/dataSourceConnections/getDataSourceConnection.ts
[listDataSourceConnectionNames]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/dataSourceConnections/listDataSourceConnectionNames.ts
[listDataSourceConnections]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/dataSourceConnections/listDataSourceConnections.ts
[createIndexer]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexers/createIndexer.ts
[createOrUpdateIndexer]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexers/createOrUpdateIndexer.ts
[deleteIndexerByName]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexers/deleteIndexerByName.ts
[deleteIndexerByObject]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexers/deleteIndexerByObject.ts
[getIndexer]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexers/getIndexer.ts
[getIndexerStatus]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexers/getIndexerStatus.ts
[listIndexerNames]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexers/listIndexerNames.ts
[listIndexers]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexers/listIndexers.ts
[resetIndexer]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexers/resetIndexer.ts
[runIndexer]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexers/runIndexer.ts
[analyzeText]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexes/analyzeText.ts
[createIndex]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexes/createIndex.ts
[createOrUpdateIndex]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexes/createOrUpdateIndex.ts
[deleteIndexByName]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexes/deleteIndexByName.ts
[deleteIndexByObject]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexes/deleteIndexByObject.ts
[getIndex]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexes/getIndex.ts
[getIndexStatistics]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexes/getIndexStatistics.ts
[listIndexes]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexes/listIndexes.ts
[listIndexNames]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/indexes/listIndexNames.ts
[createOrUpdateSkillset]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/skillSets/createOrUpdateSkillset.ts
[createSkillset]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/skillSets/createSkillset.ts
[deleteSkillsetByName]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/skillSets/deleteSkillsetByName.ts
[deleteSkillsetByObject]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/skillSets/deleteSkillsetByObject.ts
[getSkillset]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/skillSets/getSkillset.ts
[listSkillsets]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/skillSets/listSkillsets.ts
[listSkillsetsNames]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/skillSets/listSkillsetsNames.ts
[createOrUpdateSynonymMap]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/synonymMaps/createOrUpdateSynonymMap.ts
[createSynonymMap]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/synonymMaps/createSynonymMap.ts
[deleteSynonymMapByName]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/synonymMaps/deleteSynonymMapByName.ts
[deleteSynonymMapByObject]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/synonymMaps/deleteSynonymMapByObject.ts
[getSynonymMap]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/synonymMaps/getSynonymMap.ts
[listSynonymMapNames]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/synonymMaps/listSynonymMapNames.ts
[listSynonymMaps]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/samples/typescript/src/synonymMaps/listSynonymMaps.ts

Просмотреть файл

@ -1,6 +0,0 @@
# Used in most samples. Retrieve these values from a Cognitive Services instance
# in the Azure Portal.
SEARCH_API_KEY=<search api key>
SEARCH_API_ENDPOINT=https://<resource name>.search.windows.net
INDEX_NAME=hotels-sample-index

Просмотреть файл

@ -1,37 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexerClient,
AzureKeyCredential,
SearchIndexerDataSourceConnection
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Create Datasource Connection Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const dataSourceConnection: SearchIndexerDataSourceConnection = {
name: "my-data-source-2",
description: "My Data Source 1",
type: "cosmosdb",
container: {
name: "my-container-1"
},
connectionString:
"AccountEndpoint=https://hotels-docbb.documents.azure.com:443/;AccountKey=4UPsNZyFAjgZ1tzHPGZaxS09XcwLrIawbXBWk6IixcxJoSePTcjBn0mi53XiKWu8MaUgowUhIovOv7kjksqAug==;Database=SampleData"
};
await client.createDataSourceConnection(dataSourceConnection);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,31 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexerClient,
AzureKeyCredential,
SearchIndexerDataSourceConnection
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running CreateOrUpdate Datasource Connection Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Datasource Connection my-data-source-2`);
const ds:SearchIndexerDataSourceConnection = await client.getDataSourceConnection("my-data-source-2")
ds.container.name = "Listings_5K_KingCounty_WA";
console.log(`Updating Container Name of Datasource Connection my-data-source-2`);
await client.createOrUpdateDataSourceConnection(ds);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,27 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexerClient,
AzureKeyCredential
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Delete Datasource Connection Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Deleting Datasource Connection my-data-source-2`);
await client.deleteDataSourceConnection("my-data-source-2")
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,30 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexerClient,
AzureKeyCredential,
SearchIndexerDataSourceConnection
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Delete Datasource Connection Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Datasource Connection my-data-source-2`);
const ds:SearchIndexerDataSourceConnection = await client.getDataSourceConnection("my-data-source-2");
console.log(`Deleting Datasource Connection my-data-source-2`);
await client.deleteDataSourceConnection(ds);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,38 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexerClient,
AzureKeyCredential,
SearchIndexerDataSourceConnection
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Get Datasource Connection Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Datasource Connection my-data-source-2`);
const ds:SearchIndexerDataSourceConnection = await client.getDataSourceConnection("my-data-source-2")
console.log(`Name: ${ds.name}`);
console.log(`Description: ${ds.description}`);
console.log(`Connection String: ${ds.connectionString}`);
console.log(`Data Change Detection Policy: ${ds.dataChangeDetectionPolicy}`);
console.log(`Data Deletion Detection Policy: ${ds.dataDeletionDetectionPolicy}`);
console.log(`Etag: ${ds.etag}`);
console.log(`DataContainer`);
console.log(`\tName: ${ds.container.name}`);
console.log(`\tQuery: ${ds.container.query}`);
console.log();
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,29 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SearchIndexerClient, AzureKeyCredential } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running List Datasource Connection Names Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const listOfDataSourceConnectionNames: string[] = await client.listDataSourceConnectionsNames();
console.log(`Names of Data Source Connections`);
console.log(`*******************************`);
for (let ds of listOfDataSourceConnectionNames) {
console.log(ds);
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,42 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexerClient,
AzureKeyCredential,
SearchIndexerDataSourceConnection
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running List Datasource Connections Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const listOfDataSourceConnections: Array<SearchIndexerDataSourceConnection> = await client.listDataSourceConnections();
console.log(`List of Data Source Connections`);
console.log(`*******************************`);
for (let ds of listOfDataSourceConnections) {
console.log(`Name: ${ds.name}`);
console.log(`Description: ${ds.description}`);
console.log(`Connection String: ${ds.connectionString}`);
console.log(`Data Change Detection Policy: ${ds.dataChangeDetectionPolicy}`);
console.log(`Data Deletion Detection Policy: ${ds.dataDeletionDetectionPolicy}`);
console.log(`Etag: ${ds.etag}`);
console.log(`DataContainer`);
console.log(`\tName: ${ds.container.name}`);
console.log(`\tQuery: ${ds.container.query}`);
console.log();
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,31 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SearchIndexerClient, AzureKeyCredential, SearchIndexer } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Create Indexer Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const indexer: SearchIndexer = {
name: "my-azure-indexer-1",
description: "Description for Sample Indexer",
dataSourceName: "realestate-us-sample",
targetIndexName: "realestate-us-sample-index",
isDisabled: false
};
await client.createIndexer(indexer);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,27 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SearchIndexerClient, AzureKeyCredential, SearchIndexer } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Create Or Update Indexer Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Getting Indexer my-azure-indexer-1`);
const indexer: SearchIndexer = await client.getIndexer("my-azure-indexer-1");
console.log(`Updating isDisabled status of Indexer my-azure-indexer-1`);
indexer.isDisabled = true;
await client.createOrUpdateIndexer(indexer);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,27 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexerClient,
AzureKeyCredential
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Delete Indexer Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Deleting Indexer my-azure-indexer-1`);
await client.deleteIndexer("my-azure-indexer-1")
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,30 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexerClient,
AzureKeyCredential,
SearchIndexer
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Delete Indexer Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Getting Indexer my-azure-indexer-1`);
const indexer: SearchIndexer = await client.getIndexer("my-azure-indexer-1");
console.log(`Deleting Indexer my-azure-indexer-1`);
await client.deleteIndexer(indexer);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,38 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SearchIndexerClient, AzureKeyCredential, SearchIndexer } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Get Indexer Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Getting Indexer my-azure-indexer-1`);
const indexer: SearchIndexer = await client.getIndexer("my-azure-indexer-1");
console.log(`Name: ${indexer.name}`);
console.log(`Description: ${indexer.description}`);
console.log(`Data Source Name: ${indexer.dataSourceName}`);
console.log(`Skillset Name: ${indexer.skillsetName}`);
console.log(`Target Index Name: ${indexer.targetIndexName}`);
console.log(`Indexing Schedule`);
console.log(`\tInterval: ${indexer.schedule?.interval}`);
console.log(`\tStart Time: ${indexer.schedule?.startTime}`);
console.log(`Is Disabled: ${indexer.isDisabled}`);
console.log(`ETag: ${indexer.etag}`);
console.log(`Parameters`);
console.log(`\tBatch Size: ${indexer.parameters?.batchSize}`);
console.log(`\tMax Failed Items: ${indexer.parameters?.maxFailedItems}`);
console.log(`\tMax Failed Items Per Batch: ${indexer.parameters?.maxFailedItemsPerBatch}`);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,30 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SearchIndexerClient, AzureKeyCredential, SearchIndexerStatus } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Get Indexer Status Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Getting Indexer Status of my-azure-indexer-1`);
const indexerStatus: SearchIndexerStatus = await client.getIndexerStatus("my-azure-indexer-1");
console.log(`Status: ${indexerStatus.status}`);
console.log(`Limits`);
console.log(`******`);
console.log(`MaxDocumentContentCharactersToExtract: ${indexerStatus.limits.maxDocumentContentCharactersToExtract}`)
console.log(`MaxDocumentExtractionSize: ${indexerStatus.limits.maxDocumentExtractionSize}`)
console.log(`MaxRunTime: ${indexerStatus.limits.maxRunTime}`);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,29 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SearchIndexerClient, AzureKeyCredential } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running List Indexer Names Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const listOfIndexerNames: string[] = await client.listIndexersNames();
console.log(`\tNames of Indexers`);
console.log(`\t*****************`);
for (let indexerName of listOfIndexerNames) {
console.log(`${indexerName}`);
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,43 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SearchIndexerClient, AzureKeyCredential, SearchIndexer } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running List Indexers Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const listOfIndexers: Array<SearchIndexer> = await client.listIndexers();
console.log(`\tList of Indexers`);
console.log(`\t****************`);
for (let indexer of listOfIndexers) {
console.log(`Name: ${indexer.name}`);
console.log(`Description: ${indexer.description}`);
console.log(`Data Source Name: ${indexer.dataSourceName}`);
console.log(`Skillset Name: ${indexer.skillsetName}`);
console.log(`Target Index Name: ${indexer.targetIndexName}`);
console.log(`Indexing Schedule`);
console.log(`\tInterval: ${indexer.schedule?.interval}`);
console.log(`\tStart Time: ${indexer.schedule?.startTime}`);
console.log(`Is Disabled: ${indexer.isDisabled}`);
console.log(`ETag: ${indexer.etag}`);
console.log(`Parameters`);
console.log(`\tBatch Size: ${indexer.parameters?.batchSize}`);
console.log(`\tMax Failed Items: ${indexer.parameters?.maxFailedItems}`);
console.log(`\tMax Failed Items Per Batch: ${indexer.parameters?.maxFailedItemsPerBatch}`);
console.log();
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,24 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SearchIndexerClient, AzureKeyCredential } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Reset Indexer Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Reset Indexer my-azure-indexer-1`);
await client.resetIndexer("my-azure-indexer-1");
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,24 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SearchIndexerClient, AzureKeyCredential } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Run Indexer Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Run Indexer my-azure-indexer-1`);
await client.runIndexer("my-azure-indexer-1");
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,67 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/* eslint-disable no-unused-expressions */
import {
SearchIndexClient,
AzureKeyCredential,
SearchIndex,
KnownTokenFilterNames
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Analyze Text Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
const index: SearchIndex = await client.getIndex("example-index");
index.tokenizers?.push({
name: "example-tokenizer",
odatatype: "#Microsoft.Azure.Search.StandardTokenizerV2",
maxTokenLength: 125
});
index.charFilters?.push({
name: "example-char-filter",
odatatype: "#Microsoft.Azure.Search.MappingCharFilter",
mappings: ["MSFT=>Microsoft"]
});
index.tokenFilters?.push({
name: "example-token-filter",
odatatype: "#Microsoft.Azure.Search.StopwordsTokenFilter",
stopwords: ["xyzzy"]
});
index.analyzers?.push({
name: "example-analyzer",
odatatype: "#Microsoft.Azure.Search.CustomAnalyzer",
tokenizerName: "example-tokenizer",
charFilters: ["example-char-filter"],
tokenFilters: [KnownTokenFilterNames.Lowercase, "example-token-filter"]
});
// Note adding this analyzer to an existing index will cause it to be unresponsive
// for a short period, hence the need to pass `allowIndexDowntime: true`.
await client.createOrUpdateIndex(index, { allowIndexDowntime: true });
const result = await client.analyzeText("example-index", {
text: "MSFT is xyzzy Great!",
analyzerName: "example-analyzer"
});
console.log(result.tokens);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,65 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexClient,
AzureKeyCredential,
SearchIndex
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Create Index Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
const index: SearchIndex = {
name: "example-index-2",
fields: [
{
type: "Edm.String",
name: "id",
key: true
},
{
type: "Edm.Double",
name: "awesomenessLevel",
sortable: true,
filterable: true,
facetable: true
},
{
type: "Edm.String",
name: "description",
searchable: true
},
{
type: "Edm.ComplexType",
name: "details",
fields: [
{
type: "Collection(Edm.String)",
name: "tags",
searchable: true
}
]
},
{
type: "Edm.Int32",
name: "hiddenWeight",
hidden: true
}
]
};
await client.createIndex(index);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,37 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexClient,
AzureKeyCredential,
SearchIndex
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Create Or Update Index Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Index example-index-2`);
const index:SearchIndex = await client.getIndex("example-index-2");
console.log(`Adding fields to Index example-index-2`);
index.fields.push({
type: "Edm.DateTimeOffset",
name: "lastUpdatedOn",
filterable: true
});
await client.createOrUpdateIndex(index);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,27 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexClient,
AzureKeyCredential
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Delete Index Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Deleting Index example-index-2`);
await client.deleteIndex("example-index-2")
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,30 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexClient,
AzureKeyCredential,
SearchIndex
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Delete Index Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Index example-index-2`);
const index:SearchIndex = await client.getIndex("example-index-2");
console.log(`Deleting Index example-index-2`);
await client.deleteIndex(index);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,26 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SearchIndexClient, AzureKeyCredential, SearchIndex } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Get Index Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Index example-index`);
const index: SearchIndex = await client.getIndex("example-index");
console.log(`Name: ${index.name}`);
console.log(`Similarity Algorithm: ${index.similarity?.odatatype}`);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,30 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexClient,
AzureKeyCredential,
SearchIndexStatistics
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Get Index Statistics Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Index Statistics of example-index`);
const statistics:SearchIndexStatistics = await client.getIndexStatistics("example-index");
console.log(`Document Count: ${statistics.documentCount}`);
console.log(`Storage Size: ${statistics.storageSize}`);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,53 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexClient,
AzureKeyCredential
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Get Service Statistics Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
const {counters, limits} = await client.getServiceStatistics();
console.log(`Counters`);
console.log(`========`);
console.log(`\tDocument Counter`);
console.log(`\t\tUsage: ${counters.documentCounter.usage}`);
console.log(`\t\tQuota: ${counters.documentCounter.quota}`);
console.log(`\tIndex Counter`);
console.log(`\t\tUsage: ${counters.indexCounter.usage}`);
console.log(`\t\tQuota: ${counters.indexCounter.quota}`);
console.log(`\tIndexer Counter`);
console.log(`\t\tUsage: ${counters.indexerCounter.usage}`);
console.log(`\t\tQuota: ${counters.indexerCounter.quota}`);
console.log(`\tData Source Counter`);
console.log(`\t\tUsage: ${counters.dataSourceCounter.usage}`);
console.log(`\t\tQuota: ${counters.dataSourceCounter.quota}`);
console.log(`\tStorage Size Counter`);
console.log(`\t\tUsage: ${counters.storageSizeCounter.usage}`);
console.log(`\t\tQuota: ${counters.storageSizeCounter.quota}`);
console.log(`\tSynonym Map Counter`);
console.log(`\t\tUsage: ${counters.synonymMapCounter.usage}`);
console.log(`\t\tQuota: ${counters.synonymMapCounter.quota}`);
console.log();
console.log(`Limits`);
console.log(`======`);
console.log(`\tMax Fields Per Index: ${limits.maxFieldsPerIndex}`);
console.log(`\tMax Field Nesting Depth Per Index: ${limits.maxFieldNestingDepthPerIndex}`);
console.log(`\tMax Complex Collection Fields Per Index: ${limits.maxComplexCollectionFieldsPerIndex}`);
console.log(`\tMax Complex Objects In Collections Per Document: ${limits.maxComplexObjectsInCollectionsPerDocument}`);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,31 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SearchIndexClient, AzureKeyCredential } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running List Indexes Names Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
const result = await client.listIndexesNames();
let listOfIndexNames = await result.next();
console.log(`List of Index Names`);
console.log(`*******************`);
while (!listOfIndexNames.done) {
console.log(listOfIndexNames.value);
listOfIndexNames = await result.next();
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,33 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SearchIndexClient, AzureKeyCredential } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running List Indexes Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
const result = await client.listIndexes();
let listOfIndexes = await result.next();
console.log(`List of Indexes`);
console.log(`***************`);
while (!listOfIndexes.done) {
console.log(`Name: ${listOfIndexes.value.name}`);
console.log(`Similarity Algorithm: ${listOfIndexes.value.similarity?.odatatype}`);
console.log();
listOfIndexes = await result.next();
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,37 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SearchIndexerClient, AzureKeyCredential, SearchIndexerSkillset } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Create Or Update Skillset Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Getting Skillset my-azureblob-skillset`);
const skillset: SearchIndexerSkillset = await client.getSkillset("my-azureblob-skillset");
skillset.skills[0].outputs = [
{
name: "persons",
targetName: "people"
},
{
name: "organizations",
targetName: "organizations"
}
]
await client.createOrUpdateSkillset(skillset);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,56 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SearchIndexerClient, AzureKeyCredential, SearchIndexerSkillset } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Create Skillset Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const skillset: SearchIndexerSkillset = {
name: `my-azureblob-skillset`,
description: `Skillset description`,
skills: [
{
odatatype: "#Microsoft.Skills.Text.EntityRecognitionSkill",
inputs: [
{
name: "text",
source: "/document/merged_content"
},
{
name: "languageCode",
source: "/document/language"
}
],
outputs: [
{
name: "persons",
targetName: "people"
},
{
name: "organizations",
targetName: "organizations"
},
{
name: "locations",
targetName: "locations"
}
]
}
]
};
await client.createSkillset(skillset);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,27 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexerClient,
AzureKeyCredential
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Delete Skillset Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Deleting Indexer my-azureblob-skillset`);
await client.deleteSkillset("my-azureblob-skillset")
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,30 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexerClient,
AzureKeyCredential,
SearchIndexerSkillset
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Delete Skillset Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Getting Skillset my-azureblob-skillset`);
const skillset: SearchIndexerSkillset = await client.getSkillset("my-azureblob-skillset");
console.log(`Deleting Indexer my-azureblob-skillset`);
await client.deleteSkillset(skillset)
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,45 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexerClient,
AzureKeyCredential,
SearchIndexerSkillset
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Get Skillset Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Getting Skillset my-azureblob-skillset`);
const skillset: SearchIndexerSkillset = await client.getSkillset("my-azureblob-skillset");
console.log(`Name: ${skillset.name}`);
console.log(`Description: ${skillset.description}`);
console.log(`Skills`);
console.log(`******`);
for (let skill of skillset.skills) {
console.log(`ODataType: ${skill.odatatype}`);
console.log(`Inputs`);
for (let input of skill.inputs) {
console.log(`\tName: ${input.name}`);
console.log(`\tSource: ${input.source}`);
}
console.log(`Outputs`);
for (let output of skill.outputs) {
console.log(`\tName: ${output.name}`);
console.log(`\tTarget Name: ${output.targetName}`);
}
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,49 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexerClient,
AzureKeyCredential,
SearchIndexerSkillset
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running List Skillsets Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const listOfSkillsets: Array<SearchIndexerSkillset> = await client.listSkillsets();
console.log(`\tList of Skillsets`);
console.log(`\t******************`);
for (let skillset of listOfSkillsets) {
console.log(`Name: ${skillset.name}`);
console.log(`Description: ${skillset.description}`);
console.log(`Skills`);
console.log(`******`);
for (let skill of skillset.skills) {
console.log(`ODataType: ${skill.odatatype}`);
console.log(`Inputs`);
for (let input of skill.inputs) {
console.log(`\tName: ${input.name}`);
console.log(`\tSource: ${input.source}`);
}
console.log(`Outputs`);
for (let output of skill.outputs) {
console.log(`\tName: ${output.name}`);
console.log(`\tTarget Name: ${output.targetName}`);
}
}
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,29 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SearchIndexerClient, AzureKeyCredential } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running List Skillsets Names Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexerClient(endpoint, new AzureKeyCredential(apiKey));
const listOfSkillsetNames: string[] = await client.listSkillsetsNames();
console.log(`\tNames of Skillsets`);
console.log(`\t******************`);
for (let skName of listOfSkillsetNames) {
console.log(`${skName}`);
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,31 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexClient,
AzureKeyCredential,
SynonymMap
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Create Or Update SynonymMap Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Synonym Map my-synonymmap`);
const sm:SynonymMap = await client.getSynonymMap("my-synonymmap");
console.log(`Update synonyms Synonym Map my-synonymmap`);
sm.synonyms.push("Florida, Fld. => FL");
await client.createOrUpdateSynonymMap(sm);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,31 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexClient,
AzureKeyCredential,
SynonymMap
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Create SynonymMap Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
const sm: SynonymMap = {
name: `my-synonymmap`,
synonyms: ["United States, United States of America => USA", "Washington, Wash. => WA"]
};
await client.createSynonymMap(sm);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,27 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexClient,
AzureKeyCredential
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Delete SynonymMap Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Deleting SynonymMap my-synonymmap`);
await client.deleteSynonymMap("my-synonymmap")
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,30 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexClient,
AzureKeyCredential,
SynonymMap
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Delete SynonymMap Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Synonym Map my-synonymmap`);
const sm:SynonymMap = await client.getSynonymMap("my-synonymmap");
console.log(`Deleting SynonymMap my-synonymmap`);
await client.deleteSynonymMap(sm);
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,33 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import {
SearchIndexClient,
AzureKeyCredential,
SynonymMap
} from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running Get SynonymMap Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
console.log(`Get Synonym Map my-synonymmap`);
const sm: SynonymMap = await client.getSynonymMap("my-synonymmap");
console.log(`Name: ${sm.name}`);
console.log(`Synonyms`);
for (let synonym of sm.synonyms) {
console.log(synonym);
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,29 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SearchIndexClient, AzureKeyCredential } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running List SynonymMap Names Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
const listOfSynonymMapsNames: string[] = await client.listSynonymMapsNames();
console.log(`List of SynonymMap Names`);
console.log(`************************`);
for (let smName of listOfSynonymMapsNames) {
console.log(`${smName}`);
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -1,33 +0,0 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { SearchIndexClient, AzureKeyCredential, SynonymMap } from "@azure/search-documents";
import * as dotenv from "dotenv";
dotenv.config();
const endpoint = process.env.SEARCH_API_ENDPOINT || "";
const apiKey = process.env.SEARCH_API_KEY || "";
export async function main() {
console.log(`Running List SynonymMaps Sample....`);
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
const client = new SearchIndexClient(endpoint, new AzureKeyCredential(apiKey));
const listOfSynonymMaps: Array<SynonymMap> = await client.listSynonymMaps();
console.log(`List of SynonymMaps`);
console.log(`*******************`);
for (let sm of listOfSynonymMaps) {
console.log(`Name: ${sm.name}`);
console.log(`Synonyms`);
for (let synonym of sm.synonyms) {
console.log(synonym);
}
}
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});

Просмотреть файл

@ -0,0 +1,82 @@
---
page_type: sample
languages:
- javascript
products:
- azure
- azure-cognitive-search
- azure-search
urlFragment: search-documents-javascript
---
# Azure Search Documents client library samples for JavaScript
These sample programs show how to use the JavaScript client libraries for Azure Search Documents in some common scenarios.
| **File Name** | **Description** |
| ------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| [bufferedSenderAutoFlushSize.js][bufferedsenderautoflushsize] | Demonstrates the SearchIndexingBufferedSender with Autoflush based on size. |
| [bufferedSenderAutoFlushTimer.js][bufferedsenderautoflushtimer] | Demonstrates the SearchIndexingBufferedSender with Autoflush based on timer. |
| [bufferedSenderManualFlush.js][bufferedsendermanualflush] | Demonstrates the SearchIndexingBufferedSender with Manual Flush. |
| [dataSourceConnectionOperations.js][datasourceconnectionoperations] | Demonstrates the DataSource Connection Operations. |
| [indexOperations.js][indexoperations] | Demonstrates the Index Operations. |
| [indexerOperations.js][indexeroperations] | Demonstrates the Indexer Operations. |
| [interfaces.js][interfaces] | Defines the Hotel Interface. |
| [setup.js][setup] | Defines the utility methods. |
| [skillSetOperations.js][skillsetoperations] | Demonstrates the Skillset Operations. |
| [synonymMapOperations.js][synonymmapoperations] | Demonstrates the SynonymMap Operations. |
## Prerequisites
The sample programs are compatible with [LTS versions of Node.js](https://nodejs.org/about/releases/).
You need [an Azure subscription][freesub] and the following Azure resources to run these sample programs:
- [Azure Search Documents instance][createinstance_azuresearchdocumentsinstance]
Samples retrieve credentials to access the service endpoint from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function.
Adapting the samples to run in the browser may require some additional consideration. For details, please see the [package README][package].
## Setup
To run the samples using the published version of the package:
1. Install the dependencies using `npm`:
```bash
npm install
```
2. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically.
3. Run whichever samples you like (note that some samples may require additional setup, see the table above):
```bash
node bufferedSenderAutoFlushSize.js
```
Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform):
```bash
npx cross-env ENDPOINT="<endpoint>" SEARCH_API_ADMIN_KEY="<search api admin key>" node bufferedSenderAutoFlushSize.js
```
## Next Steps
Take a look at our [API Documentation][apiref] for more information about the APIs that are available in the clients.
[bufferedsenderautoflushsize]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/search/search-documents/samples/v11/javascript/bufferedSenderAutoFlushSize.js
[bufferedsenderautoflushtimer]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/search/search-documents/samples/v11/javascript/bufferedSenderAutoFlushTimer.js
[bufferedsendermanualflush]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/search/search-documents/samples/v11/javascript/bufferedSenderManualFlush.js
[datasourceconnectionoperations]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/search/search-documents/samples/v11/javascript/dataSourceConnectionOperations.js
[indexoperations]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/search/search-documents/samples/v11/javascript/indexOperations.js
[indexeroperations]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/search/search-documents/samples/v11/javascript/indexerOperations.js
[interfaces]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/search/search-documents/samples/v11/javascript/interfaces.js
[setup]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/search/search-documents/samples/v11/javascript/setup.js
[skillsetoperations]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/search/search-documents/samples/v11/javascript/skillSetOperations.js
[synonymmapoperations]: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/search/search-documents/samples/v11/javascript/synonymMapOperations.js
[apiref]: https://docs.microsoft.com/javascript/api/@azure/search-documents
[freesub]: https://azure.microsoft.com/free/
[createinstance_azuresearchdocumentsinstance]: https://docs.microsoft.com/azure/search/search-create-service-portal
[package]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/search/search-documents/README.md

Просмотреть файл

@ -0,0 +1,116 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @summary Demonstrates the SearchIndexingBufferedSender with Autoflush based on size.
*/
const {
SearchIndexingBufferedSender,
AzureKeyCredential,
SearchClient,
GeographyPoint,
SearchIndexClient
} = require("@azure/search-documents");
const { createIndex, documentKeyRetriever, WAIT_TIME } = require("./setup");
const { delay } = require("@azure/core-http");
const dotenv = require("dotenv");
dotenv.config();
/**
* This sample is to demonstrate the use of SearchIndexingBufferedSender.
* In this sample, the autoFlush is set to true. i.e. the user does not
* want to call the flush manually. The upload action happen automatically
* when the size of the batch is greater than threshold (which is set to 1000)
* by default.
*/
const endpoint = process.env.ENDPOINT || "";
const apiKey = process.env.SEARCH_API_ADMIN_KEY || "";
const TEST_INDEX_NAME = "example-index-sample-4";
function getDocumentsArray(size) {
const array = [];
for (let i = 1; i <= size; i++) {
array.push({
hotelId: `${i}`,
description:
"Best hotel in town if you like luxury hotels. They have an amazing infinity pool, a spa, " +
"and a really helpful concierge. The location is perfect -- right downtown, close to all " +
"the tourist attractions. We highly recommend this hotel.",
descriptionFr:
"Meilleur hôtel en ville si vous aimez les hôtels de luxe. Ils ont une magnifique piscine " +
"à débordement, un spa et un concierge très utile. L'emplacement est parfait – en plein " +
"centre, à proximité de toutes les attractions touristiques. Nous recommandons fortement " +
"cet hôtel.",
hotelName: "Fancy Stay",
category: "Luxury",
tags: ["pool", "view", "wifi", "concierge"],
parkingIncluded: false,
lastRenovationDate: new Date(2010, 5, 27),
rating: 5,
location: new GeographyPoint({
longitude: -122.131577,
latitude: 47.678581
})
});
}
return array;
}
async function main() {
if (!endpoint || !apiKey) {
console.log("Make sure to set valid values for endpoint and apiKey with proper authorization.");
return;
}
console.log(`Running SearchIndexingBufferedSender-uploadDocuments-With Auto Flush Sizes Sample`);
const credential = new AzureKeyCredential(apiKey);
const searchClient = new SearchClient(endpoint, TEST_INDEX_NAME, credential);
const indexClient = new SearchIndexClient(endpoint, credential);
await createIndex(indexClient, TEST_INDEX_NAME);
await delay(WAIT_TIME);
const bufferedClient = new SearchIndexingBufferedSender(searchClient, documentKeyRetriever, {
autoFlush: true
});
bufferedClient.on("batchAdded", (response) => {
console.log(`Batch Added Event has been receieved: ${response}`);
});
bufferedClient.on("beforeDocumentSent", (response) => {
console.log(`Before Document Sent Event has been receieved: ${response}`);
});
bufferedClient.on("batchSucceeded", (response) => {
console.log("Batch Succeeded Event has been receieved....");
console.log(response);
});
bufferedClient.on("batchFailed", (response) => {
console.log("Batch Failed Event has been receieved....");
console.log(response);
});
const documents = getDocumentsArray(1001);
bufferedClient.uploadDocuments(documents);
await WAIT_TIME;
let count = await searchClient.getDocumentsCount();
while (count !== documents.length) {
await delay(WAIT_TIME);
count = await searchClient.getDocumentsCount();
}
// When the autoFlush is set to true, the user
// has to call the dispose method to clear the
// timer.
bufferedClient.dispose();
await indexClient.deleteIndex(TEST_INDEX_NAME);
await delay(WAIT_TIME);
}
main();

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше