Skip to content

Commit caf6095

Browse files
committed
edits
1 parent 79890d8 commit caf6095

File tree

2 files changed

+97
-19
lines changed

2 files changed

+97
-19
lines changed

articles/search/includes/quickstarts/semantic-ranker-javascript.md

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The quickstart assumes the following is available on your computer:
4343
npm install @azure/identity @azure/search-documents dotenv
4444
```
4545

46-
1. Rename `sample.env` to `.env`, and provide your search service endpoint. You can get the endpoint from the Azure portal on the search service **Overview** page.
46+
1. Create `.env`, and provide your search service endpoint. You can get the endpoint from the Azure portal on the search service **Overview** page.
4747

4848
```ini
4949
AZURE_SEARCH_ENDPOINT=YOUR-SEARCH-SERVICE-ENDPOINT
@@ -72,8 +72,8 @@ import { DefaultAzureCredential } from "@azure/identity";
7272
7373
// Configuration - use environment variables
7474
export const searchEndpoint = process.env.AZURE_SEARCH_ENDPOINT || "PUT-YOUR-SEARCH-SERVICE-ENDPOINT-HERE";
75-
export const searchApiKey = process.env.AZURE_SEARCH_API_KEY || "PUT-YOUR-SEARCH-SERVICE-ADMIN-API-KEY-HERE";
7675
export const indexName = process.env.AZURE_SEARCH_INDEX_NAME || "hotels-sample-index";
76+
export const semanticConfigurationName = process.env.SEMANTIC_CONFIGURATION_NAME || "semantic-config";
7777
7878
// Create credential
7979
export const credential = new DefaultAzureCredential();
@@ -137,30 +137,67 @@ In this section, you get settings for the existing `hotels-sample-index` index o
137137
import {
138138
SearchIndexClient
139139
} from "@azure/search-documents";
140-
import { searchEndpoint, indexName, credential } from "./config.js";
140+
import { searchEndpoint, indexName, credential, semanticConfigurationName } from "./config.js";
141141
142-
const indexClient = new SearchIndexClient(searchEndpoint, credential);
142+
try {
143143
144-
console.log('Getting semantic search index settings...');
144+
const indexClient = new SearchIndexClient(searchEndpoint, credential);
145145
146-
// Get the existing schema
147-
const index = await indexClient.getIndex(indexName);
146+
const existingIndex = await indexClient.getIndex(indexName);
148147
149-
console.log(`Index name: ${index.name}`);
150-
console.log(`Number of fields: ${index.fields.length}`);
148+
const fields = {
149+
titleField: {
150+
name: "HotelName"
151+
},
152+
keywordsFields: [{
153+
name: "Tags"
154+
}],
155+
contentFields: [{
156+
name: "Description"
157+
}]
158+
};
159+
160+
const newSemanticConfiguration = {
161+
name: semanticConfigurationName,
162+
prioritizedFields: fields
163+
};
164+
165+
// Add the new semantic configuration to the existing index
166+
if (existingIndex.semanticSearch && existingIndex.semanticSearch.configurations) {
167+
existingIndex.semanticSearch.configurations.push(newSemanticConfiguration);
168+
} else {
169+
const configExists = existingIndex.semanticSearch?.configurations?.some(
170+
config => config.name === semanticConfigurationName
171+
);
172+
if (!configExists) {
173+
existingIndex.semanticSearch = {
174+
configurations: [newSemanticConfiguration]
175+
};
176+
}
177+
}
151178
152-
for(const field of index.fields) {
153-
console.log(`Field: ${field.name}, Type: ${field.type}, Searchable: ${field.searchable}`);
154-
}
179+
await indexClient.createOrUpdateIndex(existingIndex);
155180
156-
if(index.semanticSearch && index.semanticSearch.configurations) {
157-
console.log(`Semantic search configurations: ${index.semanticSearch.configurations.length}`);
158-
for(const config of index.semanticSearch.configurations) {
159-
console.log(`Configuration name: ${config.name}`);
160-
console.log(`Title field: ${config.prioritizedFields.titleField?.name}`);
181+
const updatedIndex = await indexClient.getIndex(indexName);
182+
183+
console.log(`Semantic configurations:`);
184+
console.log("-".repeat(40));
185+
186+
if (updatedIndex.semanticSearch && updatedIndex.semanticSearch.configurations) {
187+
for (const config of updatedIndex.semanticSearch.configurations) {
188+
console.log(`Configuration name: ${config.name}`);
189+
console.log(`Title field: ${config.prioritizedFields.titleField?.name}`);
190+
console.log(`Keywords fields: ${config.prioritizedFields.keywordsFields?.map(f => f.name).join(", ")}`);
191+
console.log(`Content fields: ${config.prioritizedFields.contentFields?.map(f => f.name).join(", ")}`);
192+
console.log("-".repeat(40));
193+
}
194+
} else {
195+
console.log("No semantic configurations found.");
161196
}
162-
} else {
163-
console.log("No semantic configuration exists for this index.");
197+
198+
console.log("Semantic configuration updated successfully.");
199+
} catch (error) {
200+
console.error("Error updating semantic configuration:", error);
164201
}
165202
```
166203

articles/search/includes/quickstarts/semantic-ranker-typescript.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,47 @@ If you signed in to the [Azure portal](https://portal.azure.com), you're signed
139139
}
140140
```
141141
142+
143+
## Get configuration for the index
144+
145+
In this section, you get settings for the existing `hotels-sample-index` index on your search service.
146+
147+
1. Create a file in `./src` called `getIndexSettings.ts` and copy in the following code.
148+
149+
```typescript
150+
import {
151+
SearchIndexClient
152+
} from "@azure/search-documents";
153+
import { searchEndpoint, indexName, credential } from "./config.js";
154+
155+
const indexClient = new SearchIndexClient(searchEndpoint, credential);
156+
157+
console.log('Updating semantic search index...');
158+
159+
// Get the existing schema
160+
const index = await indexClient.getIndex(indexName);
161+
162+
console.log(`Index name: ${index.name}`);
163+
console.log(`Number of fields: ${index.fields.length}`);
164+
165+
for(const field of index.fields) {
166+
167+
// @ts-ignore
168+
console.log(`Field: ${field.name}, Type: ${field.type}, Searchable: ${field.searchable}`);
169+
}
170+
171+
if(index.semanticSearch && index.semanticSearch.configurations) {
172+
console.log(`Semantic search configurations: ${index.semanticSearch.configurations.length}`);
173+
for(const config of index.semanticSearch.configurations) {
174+
console.log(`Configuration name: ${config.name}`);
175+
console.log(`Title field: ${config.prioritizedFields.titleField?.name}`);
176+
}
177+
} else {
178+
console.log("No semantic configuration exists for this index.");
179+
}
180+
```
181+
182+
142183
1. Run the code:
143184
144185
```bash

0 commit comments

Comments
 (0)