@azure/search-documents 12.2.0-alpha.20250424.1 → 12.2.0-alpha.20250501.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +173 -199
- package/dist/browser/odata.d.ts +3 -1
- package/dist/browser/odata.d.ts.map +1 -1
- package/dist/browser/odata.js +3 -1
- package/dist/browser/odata.js.map +1 -1
- package/dist/browser/searchClient.d.ts +35 -37
- package/dist/browser/searchClient.d.ts.map +1 -1
- package/dist/browser/searchClient.js +35 -37
- package/dist/browser/searchClient.js.map +1 -1
- package/dist/browser/searchIndexClient.d.ts +3 -6
- package/dist/browser/searchIndexClient.d.ts.map +1 -1
- package/dist/browser/searchIndexClient.js +3 -6
- package/dist/browser/searchIndexClient.js.map +1 -1
- package/dist/browser/searchIndexerClient.d.ts +3 -6
- package/dist/browser/searchIndexerClient.d.ts.map +1 -1
- package/dist/browser/searchIndexerClient.js +3 -6
- package/dist/browser/searchIndexerClient.js.map +1 -1
- package/dist/commonjs/odata.d.ts +3 -1
- package/dist/commonjs/odata.d.ts.map +1 -1
- package/dist/commonjs/odata.js +3 -1
- package/dist/commonjs/odata.js.map +1 -1
- package/dist/commonjs/searchClient.d.ts +35 -37
- package/dist/commonjs/searchClient.d.ts.map +1 -1
- package/dist/commonjs/searchClient.js +35 -37
- package/dist/commonjs/searchClient.js.map +1 -1
- package/dist/commonjs/searchIndexClient.d.ts +3 -6
- package/dist/commonjs/searchIndexClient.d.ts.map +1 -1
- package/dist/commonjs/searchIndexClient.js +3 -6
- package/dist/commonjs/searchIndexClient.js.map +1 -1
- package/dist/commonjs/searchIndexerClient.d.ts +3 -6
- package/dist/commonjs/searchIndexerClient.d.ts.map +1 -1
- package/dist/commonjs/searchIndexerClient.js +3 -6
- package/dist/commonjs/searchIndexerClient.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/esm/odata.d.ts +3 -1
- package/dist/esm/odata.d.ts.map +1 -1
- package/dist/esm/odata.js +3 -1
- package/dist/esm/odata.js.map +1 -1
- package/dist/esm/searchClient.d.ts +35 -37
- package/dist/esm/searchClient.d.ts.map +1 -1
- package/dist/esm/searchClient.js +35 -37
- package/dist/esm/searchClient.js.map +1 -1
- package/dist/esm/searchIndexClient.d.ts +3 -6
- package/dist/esm/searchIndexClient.d.ts.map +1 -1
- package/dist/esm/searchIndexClient.js +3 -6
- package/dist/esm/searchIndexClient.js.map +1 -1
- package/dist/esm/searchIndexerClient.d.ts +3 -6
- package/dist/esm/searchIndexerClient.d.ts.map +1 -1
- package/dist/esm/searchIndexerClient.js +3 -6
- package/dist/esm/searchIndexerClient.js.map +1 -1
- package/dist/react-native/odata.d.ts +3 -1
- package/dist/react-native/odata.d.ts.map +1 -1
- package/dist/react-native/odata.js +3 -1
- package/dist/react-native/odata.js.map +1 -1
- package/dist/react-native/searchClient.d.ts +35 -37
- package/dist/react-native/searchClient.d.ts.map +1 -1
- package/dist/react-native/searchClient.js +35 -37
- package/dist/react-native/searchClient.js.map +1 -1
- package/dist/react-native/searchIndexClient.d.ts +3 -6
- package/dist/react-native/searchIndexClient.d.ts.map +1 -1
- package/dist/react-native/searchIndexClient.js +3 -6
- package/dist/react-native/searchIndexClient.js.map +1 -1
- package/dist/react-native/searchIndexerClient.d.ts +3 -6
- package/dist/react-native/searchIndexerClient.d.ts.map +1 -1
- package/dist/react-native/searchIndexerClient.js +3 -6
- package/dist/react-native/searchIndexerClient.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -88,13 +88,13 @@ _Note: The example Azure CLI snippet above retrieves an admin key so it's easier
|
|
|
88
88
|
|
|
89
89
|
Once you have an api-key, you can use it as follows:
|
|
90
90
|
|
|
91
|
-
```
|
|
92
|
-
|
|
91
|
+
```ts snippet:ReadmeSampleCreateClient_APIKey
|
|
92
|
+
import {
|
|
93
93
|
SearchClient,
|
|
94
|
+
AzureKeyCredential,
|
|
94
95
|
SearchIndexClient,
|
|
95
96
|
SearchIndexerClient,
|
|
96
|
-
|
|
97
|
-
} = require("@azure/search-documents");
|
|
97
|
+
} from "@azure/search-documents";
|
|
98
98
|
|
|
99
99
|
// To query and manipulate documents
|
|
100
100
|
const searchClient = new SearchClient(
|
|
@@ -116,14 +116,14 @@ To authenticate in a [National Cloud](https://learn.microsoft.com/azure/active-d
|
|
|
116
116
|
|
|
117
117
|
- Set the `Audience` in `SearchClientOptions`
|
|
118
118
|
|
|
119
|
-
```
|
|
120
|
-
|
|
119
|
+
```ts snippet:ReadmeSampleCreateClient_NationalCloud
|
|
120
|
+
import {
|
|
121
121
|
SearchClient,
|
|
122
|
-
SearchIndexClient,
|
|
123
|
-
SearchIndexerClient,
|
|
124
122
|
AzureKeyCredential,
|
|
125
123
|
KnownSearchAudience,
|
|
126
|
-
|
|
124
|
+
SearchIndexClient,
|
|
125
|
+
SearchIndexerClient,
|
|
126
|
+
} from "@azure/search-documents";
|
|
127
127
|
|
|
128
128
|
// To query and manipulate documents
|
|
129
129
|
const searchClient = new SearchClient(
|
|
@@ -208,142 +208,137 @@ The following examples demonstrate the basics - please [check out our samples](h
|
|
|
208
208
|
|
|
209
209
|
### Create an Index
|
|
210
210
|
|
|
211
|
-
```
|
|
212
|
-
|
|
211
|
+
```ts snippet:ReadmeSampleCreateIndex
|
|
212
|
+
import { SearchIndexClient, AzureKeyCredential } from "@azure/search-documents";
|
|
213
213
|
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
async function main() {
|
|
217
|
-
const result = await client.createIndex({
|
|
218
|
-
name: "example-index",
|
|
219
|
-
fields: [
|
|
220
|
-
{
|
|
221
|
-
type: "Edm.String",
|
|
222
|
-
name: "id",
|
|
223
|
-
key: true,
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
type: "Edm.Double",
|
|
227
|
-
name: "awesomenessLevel",
|
|
228
|
-
sortable: true,
|
|
229
|
-
filterable: true,
|
|
230
|
-
facetable: true,
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
type: "Edm.String",
|
|
234
|
-
name: "description",
|
|
235
|
-
searchable: true,
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
type: "Edm.ComplexType",
|
|
239
|
-
name: "details",
|
|
240
|
-
fields: [
|
|
241
|
-
{
|
|
242
|
-
type: "Collection(Edm.String)",
|
|
243
|
-
name: "tags",
|
|
244
|
-
searchable: true,
|
|
245
|
-
},
|
|
246
|
-
],
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
type: "Edm.Int32",
|
|
250
|
-
name: "hiddenWeight",
|
|
251
|
-
hidden: true,
|
|
252
|
-
},
|
|
253
|
-
],
|
|
254
|
-
});
|
|
214
|
+
const indexClient = new SearchIndexClient("<endpoint>", new AzureKeyCredential("<apiKey>"));
|
|
255
215
|
|
|
256
|
-
|
|
257
|
-
|
|
216
|
+
const result = await indexClient.createIndex({
|
|
217
|
+
name: "example-index",
|
|
218
|
+
fields: [
|
|
219
|
+
{
|
|
220
|
+
type: "Edm.String",
|
|
221
|
+
name: "id",
|
|
222
|
+
key: true,
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
type: "Edm.Double",
|
|
226
|
+
name: "awesomenessLevel",
|
|
227
|
+
sortable: true,
|
|
228
|
+
filterable: true,
|
|
229
|
+
facetable: true,
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
type: "Edm.String",
|
|
233
|
+
name: "description",
|
|
234
|
+
searchable: true,
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
type: "Edm.ComplexType",
|
|
238
|
+
name: "details",
|
|
239
|
+
fields: [
|
|
240
|
+
{
|
|
241
|
+
type: "Collection(Edm.String)",
|
|
242
|
+
name: "tags",
|
|
243
|
+
searchable: true,
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
type: "Edm.Int32",
|
|
249
|
+
name: "hiddenWeight",
|
|
250
|
+
hidden: true,
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
});
|
|
258
254
|
|
|
259
|
-
|
|
255
|
+
console.log(`Index created with name ${result.name}`);
|
|
260
256
|
```
|
|
261
257
|
|
|
262
258
|
### Retrieve a specific document from an index
|
|
263
259
|
|
|
264
260
|
A specific document can be retrieved by its primary key value:
|
|
265
261
|
|
|
266
|
-
```
|
|
267
|
-
|
|
262
|
+
```ts snippet:ReadmeSampleGetDocument
|
|
263
|
+
import { SearchClient, AzureKeyCredential } from "@azure/search-documents";
|
|
268
264
|
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
265
|
+
const searchClient = new SearchClient(
|
|
266
|
+
"<endpoint>",
|
|
267
|
+
"<indexName>",
|
|
268
|
+
new AzureKeyCredential("<apiKey>"),
|
|
269
|
+
);
|
|
275
270
|
|
|
276
|
-
|
|
271
|
+
const result = await searchClient.getDocument("1234");
|
|
277
272
|
```
|
|
278
273
|
|
|
279
274
|
### Adding documents into an index
|
|
280
275
|
|
|
281
276
|
You can upload multiple documents into index inside a batch:
|
|
282
277
|
|
|
283
|
-
```
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const client = new SearchClient("<endpoint>", "<indexName>", new AzureKeyCredential("<apiKey>"));
|
|
287
|
-
|
|
288
|
-
async function main() {
|
|
289
|
-
const uploadResult = await client.uploadDocuments([
|
|
290
|
-
// JSON objects matching the shape of the client's index
|
|
291
|
-
{},
|
|
292
|
-
{},
|
|
293
|
-
{},
|
|
294
|
-
]);
|
|
295
|
-
for (const result of uploadResult.results) {
|
|
296
|
-
console.log(`Uploaded ${result.key}; succeeded? ${result.succeeded}`);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
278
|
+
```ts snippet:ReadmeSampleUploadDocuments
|
|
279
|
+
import { SearchClient, AzureKeyCredential } from "@azure/search-documents";
|
|
299
280
|
|
|
300
|
-
|
|
281
|
+
const searchClient = new SearchClient(
|
|
282
|
+
"<endpoint>",
|
|
283
|
+
"<indexName>",
|
|
284
|
+
new AzureKeyCredential("<apiKey>"),
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
const uploadResult = await searchClient.uploadDocuments([
|
|
288
|
+
// JSON objects matching the shape of the client's index
|
|
289
|
+
{},
|
|
290
|
+
{},
|
|
291
|
+
{},
|
|
292
|
+
]);
|
|
293
|
+
for (const result of uploadResult.results) {
|
|
294
|
+
console.log(`Uploaded ${result.key}; succeeded? ${result.succeeded}`);
|
|
295
|
+
}
|
|
301
296
|
```
|
|
302
297
|
|
|
303
298
|
### Perform a search on documents
|
|
304
299
|
|
|
305
300
|
To list all results of a particular query, you can use `search` with a search string that uses [simple query syntax](https://learn.microsoft.com/azure/search/query-simple-syntax):
|
|
306
301
|
|
|
307
|
-
```
|
|
308
|
-
|
|
302
|
+
```ts snippet:ReadmeSampleSearch
|
|
303
|
+
import { SearchClient, AzureKeyCredential } from "@azure/search-documents";
|
|
309
304
|
|
|
310
|
-
const
|
|
305
|
+
const searchClient = new SearchClient(
|
|
306
|
+
"<endpoint>",
|
|
307
|
+
"<indexName>",
|
|
308
|
+
new AzureKeyCredential("<apiKey>"),
|
|
309
|
+
);
|
|
311
310
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
console.log(result);
|
|
316
|
-
}
|
|
311
|
+
const searchResults = await searchClient.search("wifi -luxury");
|
|
312
|
+
for await (const result of searchResults.results) {
|
|
313
|
+
console.log(result);
|
|
317
314
|
}
|
|
318
|
-
|
|
319
|
-
main();
|
|
320
315
|
```
|
|
321
316
|
|
|
322
317
|
For a more advanced search that uses [Lucene syntax](https://learn.microsoft.com/azure/search/query-lucene-syntax), specify `queryType` to be `full`:
|
|
323
318
|
|
|
324
|
-
```
|
|
325
|
-
|
|
319
|
+
```ts snippet:ReadmeSampleSearchLucene
|
|
320
|
+
import { SearchClient, AzureKeyCredential } from "@azure/search-documents";
|
|
326
321
|
|
|
327
|
-
const
|
|
322
|
+
const searchClient = new SearchClient(
|
|
323
|
+
"<endpoint>",
|
|
324
|
+
"<indexName>",
|
|
325
|
+
new AzureKeyCredential("<apiKey>"),
|
|
326
|
+
);
|
|
328
327
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
console.log(result);
|
|
336
|
-
}
|
|
328
|
+
const searchResults = await searchClient.search('Category:budget AND "recently renovated"^3', {
|
|
329
|
+
queryType: "full",
|
|
330
|
+
searchMode: "all",
|
|
331
|
+
});
|
|
332
|
+
for await (const result of searchResults.results) {
|
|
333
|
+
console.log(result);
|
|
337
334
|
}
|
|
338
|
-
|
|
339
|
-
main();
|
|
340
335
|
```
|
|
341
336
|
|
|
342
337
|
#### Querying with TypeScript
|
|
343
338
|
|
|
344
339
|
In TypeScript, `SearchClient` takes a generic parameter that is the model shape of your index documents. This allows you to perform strongly typed lookup of fields returned in results. TypeScript is also able to check for fields returned when specifying a `select` parameter.
|
|
345
340
|
|
|
346
|
-
```ts
|
|
341
|
+
```ts snippet:ReadmeSampleSearchWithTypes
|
|
347
342
|
import { SearchClient, AzureKeyCredential, SelectFields } from "@azure/search-documents";
|
|
348
343
|
|
|
349
344
|
// An example schema for documents in the index
|
|
@@ -361,71 +356,67 @@ interface Hotel {
|
|
|
361
356
|
}>;
|
|
362
357
|
}
|
|
363
358
|
|
|
364
|
-
const
|
|
359
|
+
const searchClient = new SearchClient<Hotel>(
|
|
365
360
|
"<endpoint>",
|
|
366
361
|
"<indexName>",
|
|
367
362
|
new AzureKeyCredential("<apiKey>"),
|
|
368
363
|
);
|
|
369
364
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
// These are other ways to declare the correct type for `select`.
|
|
378
|
-
const select = ["hotelId", "hotelName", "rooms/beds"] as const;
|
|
379
|
-
// This declaration lets you opt out of narrowing the TypeScript type of your documents,
|
|
380
|
-
// though the AI Search service will still only return these fields.
|
|
381
|
-
const selectWide: SelectFields<Hotel>[] = ["hotelId", "hotelName", "rooms/beds"];
|
|
382
|
-
// This is an invalid declaration. Passing this to `select` will result in a compiler error
|
|
383
|
-
// unless you opt out of including the model in the client constructor.
|
|
384
|
-
const selectInvalid = ["hotelId", "hotelName", "rooms/beds"];
|
|
385
|
-
|
|
386
|
-
for await (const result of searchResults.results) {
|
|
387
|
-
// result.document has hotelId, hotelName, and rating.
|
|
388
|
-
// Trying to access result.document.description would emit a TS error.
|
|
389
|
-
console.log(result.document.hotelName);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
365
|
+
const searchResults = await searchClient.search("wifi -luxury", {
|
|
366
|
+
// Only fields in Hotel can be added to this array.
|
|
367
|
+
// TS will complain if one is misspelled.
|
|
368
|
+
select: ["hotelId", "hotelName", "rooms/beds"],
|
|
369
|
+
});
|
|
392
370
|
|
|
393
|
-
|
|
371
|
+
// These are other ways to declare the correct type for `select`.
|
|
372
|
+
const select = ["hotelId", "hotelName", "rooms/beds"] as const;
|
|
373
|
+
// This declaration lets you opt out of narrowing the TypeScript type of your documents,
|
|
374
|
+
// though the AI Search service will still only return these fields.
|
|
375
|
+
const selectWide: SelectFields<Hotel>[] = ["hotelId", "hotelName", "rooms/beds"];
|
|
376
|
+
// This is an invalid declaration. Passing this to `select` will result in a compiler error
|
|
377
|
+
// unless you opt out of including the model in the client constructor.
|
|
378
|
+
const selectInvalid = ["hotelId", "hotelName", "rooms/beds"];
|
|
379
|
+
|
|
380
|
+
for await (const result of searchResults.results) {
|
|
381
|
+
// result.document has hotelId, hotelName, and rating.
|
|
382
|
+
// Trying to access result.document.description would emit a TS error.
|
|
383
|
+
console.log(result.document.hotelName);
|
|
384
|
+
}
|
|
394
385
|
```
|
|
395
386
|
|
|
396
387
|
#### Querying with OData filters
|
|
397
388
|
|
|
398
389
|
Using the `filter` query parameter allows you to query an index using the syntax of an [OData \$filter expression](https://learn.microsoft.com/azure/search/search-query-odata-filter).
|
|
399
390
|
|
|
400
|
-
```
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
const
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
const searchResults = await client.search("WiFi", {
|
|
409
|
-
filter: odata`Rooms/any(room: room/BaseRate lt ${baseRateMax}) and Rating ge ${ratingMin}`,
|
|
410
|
-
orderBy: ["Rating desc"],
|
|
411
|
-
select: ["hotelId", "hotelName", "Rating"],
|
|
412
|
-
});
|
|
413
|
-
for await (const result of searchResults.results) {
|
|
414
|
-
// Each result will have "HotelId", "HotelName", and "Rating"
|
|
415
|
-
// in addition to the standard search result property "score"
|
|
416
|
-
console.log(result);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
391
|
+
```ts snippet:ReadmeSampleSearchWithOData
|
|
392
|
+
import { SearchClient, AzureKeyCredential, odata } from "@azure/search-documents";
|
|
393
|
+
|
|
394
|
+
const searchClient = new SearchClient(
|
|
395
|
+
"<endpoint>",
|
|
396
|
+
"<indexName>",
|
|
397
|
+
new AzureKeyCredential("<apiKey>"),
|
|
398
|
+
);
|
|
419
399
|
|
|
420
|
-
|
|
400
|
+
const baseRateMax = 200;
|
|
401
|
+
const ratingMin = 4;
|
|
402
|
+
const searchResults = await searchClient.search("WiFi", {
|
|
403
|
+
filter: odata`Rooms/any(room: room/BaseRate lt ${baseRateMax}) and Rating ge ${ratingMin}`,
|
|
404
|
+
orderBy: ["Rating desc"],
|
|
405
|
+
select: ["hotelId", "hotelName", "Rating"],
|
|
406
|
+
});
|
|
407
|
+
for await (const result of searchResults.results) {
|
|
408
|
+
// Each result will have "HotelId", "HotelName", and "Rating"
|
|
409
|
+
// in addition to the standard search result property "score"
|
|
410
|
+
console.log(result);
|
|
411
|
+
}
|
|
421
412
|
```
|
|
422
413
|
|
|
423
414
|
#### Querying with vectors
|
|
424
415
|
|
|
425
416
|
Text embeddings can be queried using the `vector` search parameter. See [Query vectors](https://learn.microsoft.com/azure/search/vector-search-how-to-query) and [Filter vector queries](https://learn.microsoft.com/azure/search/vector-search-filters) for more information.
|
|
426
417
|
|
|
427
|
-
```
|
|
428
|
-
|
|
418
|
+
```ts snippet:ReadmeSampleSearchWithVector
|
|
419
|
+
import { SearchClient, AzureKeyCredential } from "@azure/search-documents";
|
|
429
420
|
|
|
430
421
|
const searchClient = new SearchClient(
|
|
431
422
|
"<endpoint>",
|
|
@@ -433,61 +424,44 @@ const searchClient = new SearchClient(
|
|
|
433
424
|
new AzureKeyCredential("<apiKey>"),
|
|
434
425
|
);
|
|
435
426
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
console.log(result);
|
|
455
|
-
}
|
|
427
|
+
const queryVector: number[] = [
|
|
428
|
+
// Embedding of the query "What are the most luxurious hotels?"
|
|
429
|
+
];
|
|
430
|
+
const searchResults = await searchClient.search("*", {
|
|
431
|
+
vectorSearchOptions: {
|
|
432
|
+
queries: [
|
|
433
|
+
{
|
|
434
|
+
kind: "vector",
|
|
435
|
+
vector: queryVector,
|
|
436
|
+
fields: ["descriptionVector"],
|
|
437
|
+
kNearestNeighborsCount: 3,
|
|
438
|
+
},
|
|
439
|
+
],
|
|
440
|
+
},
|
|
441
|
+
});
|
|
442
|
+
for await (const result of searchResults.results) {
|
|
443
|
+
// These results are the nearest neighbors to the query vector
|
|
444
|
+
console.log(result);
|
|
456
445
|
}
|
|
457
|
-
|
|
458
|
-
main();
|
|
459
446
|
```
|
|
460
447
|
|
|
461
448
|
#### Querying with facets
|
|
462
449
|
|
|
463
450
|
[Facets](https://learn.microsoft.com/azure/search/search-filters-facets) are used to help a user of your application refine a search along pre-configured dimensions. [Facet syntax](https://learn.microsoft.com/rest/api/searchservice/search-documents#facetstring-zero-or-more) provides the options to sort and bucket facet values.
|
|
464
451
|
|
|
465
|
-
```
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
const client = new SearchClient("<endpoint>", "<indexName>", new AzureKeyCredential("<apiKey>"));
|
|
469
|
-
|
|
470
|
-
async function main() {
|
|
471
|
-
const searchResults = await client.search("WiFi", {
|
|
472
|
-
facets: ["category,count:3,sort:count", "rooms/baseRate,interval:100"],
|
|
473
|
-
});
|
|
474
|
-
console.log(searchResults.facets);
|
|
475
|
-
// Output will look like:
|
|
476
|
-
// {
|
|
477
|
-
// 'rooms/baseRate': [
|
|
478
|
-
// { count: 16, value: 0 },
|
|
479
|
-
// { count: 17, value: 100 },
|
|
480
|
-
// { count: 17, value: 200 }
|
|
481
|
-
// ],
|
|
482
|
-
// category: [
|
|
483
|
-
// { count: 5, value: 'Budget' },
|
|
484
|
-
// { count: 5, value: 'Luxury' },
|
|
485
|
-
// { count: 5, value: 'Resort and Spa' }
|
|
486
|
-
// ]
|
|
487
|
-
// }
|
|
488
|
-
}
|
|
452
|
+
```ts snippet:ReadmeSampleSearchWithFacets
|
|
453
|
+
import { SearchClient, AzureKeyCredential } from "@azure/search-documents";
|
|
489
454
|
|
|
490
|
-
|
|
455
|
+
const searchClient = new SearchClient(
|
|
456
|
+
"<endpoint>",
|
|
457
|
+
"<indexName>",
|
|
458
|
+
new AzureKeyCredential("<apiKey>"),
|
|
459
|
+
);
|
|
460
|
+
|
|
461
|
+
const searchResults = await searchClient.search("WiFi", {
|
|
462
|
+
facets: ["category,count:3,sort:count", "rooms/baseRate,interval:100"],
|
|
463
|
+
});
|
|
464
|
+
console.log(searchResults.facets);
|
|
491
465
|
```
|
|
492
466
|
|
|
493
467
|
When retrieving results, a `facets` property will be available that will indicate the number of results that fall into each facet bucket. This can be used to drive refinement (e.g. issuing a follow-up search that filters on the `Rating` being greater than or equal to 3 and less than 4.)
|
|
@@ -498,7 +472,7 @@ When retrieving results, a `facets` property will be available that will indicat
|
|
|
498
472
|
|
|
499
473
|
Enabling logging can help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
|
|
500
474
|
|
|
501
|
-
```
|
|
475
|
+
```ts snippet:SetLogLevel
|
|
502
476
|
import { setLogLevel } from "@azure/logger";
|
|
503
477
|
|
|
504
478
|
setLogLevel("info");
|
package/dist/browser/odata.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Escapes an odata filter expression to avoid errors with quoting string literals.
|
|
3
3
|
* Example usage:
|
|
4
|
-
* ```ts
|
|
4
|
+
* ```ts snippet:ReadmeSampleOdataUsage
|
|
5
|
+
* import { odata } from "@azure/search-documents";
|
|
6
|
+
*
|
|
5
7
|
* const baseRateMax = 200;
|
|
6
8
|
* const ratingMin = 4;
|
|
7
9
|
* const filter = odata`Rooms/any(room: room/BaseRate lt ${baseRateMax}) and Rating ge ${ratingMin}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odata.d.ts","sourceRoot":"","sources":["../../src/odata.ts"],"names":[],"mappings":"AAyBA
|
|
1
|
+
{"version":3,"file":"odata.d.ts","sourceRoot":"","sources":["../../src/odata.ts"],"names":[],"mappings":"AAyBA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAajF"}
|
package/dist/browser/odata.js
CHANGED
|
@@ -20,7 +20,9 @@ function escapeQuotesIfString(input, previous) {
|
|
|
20
20
|
/**
|
|
21
21
|
* Escapes an odata filter expression to avoid errors with quoting string literals.
|
|
22
22
|
* Example usage:
|
|
23
|
-
* ```ts
|
|
23
|
+
* ```ts snippet:ReadmeSampleOdataUsage
|
|
24
|
+
* import { odata } from "@azure/search-documents";
|
|
25
|
+
*
|
|
24
26
|
* const baseRateMax = 200;
|
|
25
27
|
* const ratingMin = 4;
|
|
26
28
|
* const filter = odata`Rooms/any(room: room/BaseRate lt ${baseRateMax}) and Rating ge ${ratingMin}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"odata.js","sourceRoot":"","sources":["../../src/odata.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,SAAS,sBAAsB,CAAC,KAAc;IAC5C,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAc,EAAE,QAAgB;IAC5D,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACnC,0CAA0C;QAC1C,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACnC,MAAM,GAAG,IAAI,MAAM,GAAG,CAAC;QACzB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"odata.js","sourceRoot":"","sources":["../../src/odata.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,SAAS,sBAAsB,CAAC,KAAc;IAC5C,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAc,EAAE,QAAgB;IAC5D,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACnC,0CAA0C;QAC1C,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACnC,MAAM,GAAG,IAAI,MAAM,GAAG,CAAC;QACzB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,KAAK,CAAC,OAA6B,EAAE,GAAG,MAAiB;IACvE,MAAM,OAAO,GAAG,EAAE,CAAC;IACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QACzB,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;YACtB,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;gBAClD,OAAO,CAAC,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAClD,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5D,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nfunction formatNullAndUndefined(input: unknown): string | unknown {\n if (input === null || input === undefined) {\n return \"null\";\n }\n\n return input;\n}\n\nfunction escapeQuotesIfString(input: unknown, previous: string): string | unknown {\n let result = input;\n\n if (typeof input === \"string\") {\n result = input.replace(/'/g, \"''\");\n // check if we need to escape this literal\n if (!previous.trim().endsWith(\"'\")) {\n result = `'${result}'`;\n }\n }\n\n return result;\n}\n\n/**\n * Escapes an odata filter expression to avoid errors with quoting string literals.\n * Example usage:\n * ```ts snippet:ReadmeSampleOdataUsage\n * import { odata } from \"@azure/search-documents\";\n *\n * const baseRateMax = 200;\n * const ratingMin = 4;\n * const filter = odata`Rooms/any(room: room/BaseRate lt ${baseRateMax}) and Rating ge ${ratingMin}`;\n * ```\n * For more information on supported syntax see: https://learn.microsoft.com/en-us/azure/search/search-query-odata-filter\n * @param strings - Array of strings for the expression\n * @param values - Array of values for the expression\n */\nexport function odata(strings: TemplateStringsArray, ...values: unknown[]): string {\n const results = [];\n for (let i = 0; i < strings.length; i++) {\n results.push(strings[i]);\n if (i < values.length) {\n if (values[i] === null || values[i] === undefined) {\n results.push(formatNullAndUndefined(values[i]));\n } else {\n results.push(escapeQuotesIfString(values[i], strings[i]));\n }\n }\n }\n return results.join(\"\");\n}\n"]}
|
|
@@ -61,26 +61,32 @@ export declare class SearchClient<TModel extends object> implements IndexDocumen
|
|
|
61
61
|
* Creates an instance of SearchClient.
|
|
62
62
|
*
|
|
63
63
|
* Example usage:
|
|
64
|
-
* ```ts
|
|
65
|
-
*
|
|
64
|
+
* ```ts snippet:ReadmeSampleSearchClient
|
|
65
|
+
* import { SearchClient, AzureKeyCredential } from "@azure/search-documents";
|
|
66
66
|
*
|
|
67
|
-
* const
|
|
67
|
+
* const searchClient = new SearchClient(
|
|
68
68
|
* "<endpoint>",
|
|
69
69
|
* "<indexName>",
|
|
70
|
-
* new AzureKeyCredential("<
|
|
70
|
+
* new AzureKeyCredential("<apiKey>"),
|
|
71
71
|
* );
|
|
72
72
|
* ```
|
|
73
73
|
*
|
|
74
74
|
* Optionally, the type of the model can be used to enable strong typing and type hints:
|
|
75
|
-
* ```ts
|
|
75
|
+
* ```ts snippet:ReadmeSampleSearchClientWithModel
|
|
76
|
+
* import { SearchClient, AzureKeyCredential } from "@azure/search-documents";
|
|
77
|
+
*
|
|
76
78
|
* type TModel = {
|
|
77
79
|
* keyName: string;
|
|
78
80
|
* field1?: string | null;
|
|
79
|
-
* field2?: {
|
|
81
|
+
* field2?: {
|
|
82
|
+
* anotherField?: string | null;
|
|
83
|
+
* } | null;
|
|
80
84
|
* };
|
|
81
85
|
*
|
|
82
|
-
* const
|
|
83
|
-
*
|
|
86
|
+
* const searchClient = new SearchClient<TModel>(
|
|
87
|
+
* "<endpoint>",
|
|
88
|
+
* "<indexName>",
|
|
89
|
+
* new AzureKeyCredential("<apiKey>"),
|
|
84
90
|
* );
|
|
85
91
|
* ```
|
|
86
92
|
*
|
|
@@ -107,31 +113,27 @@ export declare class SearchClient<TModel extends object> implements IndexDocumen
|
|
|
107
113
|
* @param suggesterName - The name of the suggester as specified in the suggesters collection that's part of the index definition.
|
|
108
114
|
* @param options - Options to the autocomplete operation.
|
|
109
115
|
* @example
|
|
110
|
-
* ```ts
|
|
111
|
-
* import {
|
|
112
|
-
* AzureKeyCredential,
|
|
113
|
-
* SearchClient,
|
|
114
|
-
* SearchFieldArray,
|
|
115
|
-
* } from "@azure/search-documents";
|
|
116
|
+
* ```ts snippet:ReadmeSampleAutocomplete
|
|
117
|
+
* import { SearchClient, AzureKeyCredential, SearchFieldArray } from "@azure/search-documents";
|
|
116
118
|
*
|
|
117
119
|
* type TModel = {
|
|
118
120
|
* key: string;
|
|
119
|
-
* azure?: {
|
|
121
|
+
* azure?: {
|
|
122
|
+
* sdk: string | null;
|
|
123
|
+
* } | null;
|
|
120
124
|
* };
|
|
121
125
|
*
|
|
122
126
|
* const client = new SearchClient<TModel>(
|
|
123
127
|
* "endpoint.azure",
|
|
124
128
|
* "indexName",
|
|
125
|
-
* new AzureKeyCredential("key")
|
|
129
|
+
* new AzureKeyCredential("key"),
|
|
126
130
|
* );
|
|
127
131
|
*
|
|
128
132
|
* const searchFields: SearchFieldArray<TModel> = ["azure/sdk"];
|
|
129
133
|
*
|
|
130
|
-
* const autocompleteResult = await client.autocomplete(
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* { searchFields }
|
|
134
|
-
* );
|
|
134
|
+
* const autocompleteResult = await client.autocomplete("searchText", "suggesterName", {
|
|
135
|
+
* searchFields,
|
|
136
|
+
* });
|
|
135
137
|
* ```
|
|
136
138
|
*/
|
|
137
139
|
autocomplete(searchText: string, suggesterName: string, options?: AutocompleteOptions<TModel>): Promise<AutocompleteResult>;
|
|
@@ -145,22 +147,20 @@ export declare class SearchClient<TModel extends object> implements IndexDocumen
|
|
|
145
147
|
* @param searchText - Text to search
|
|
146
148
|
* @param options - Options for the search operation.
|
|
147
149
|
* @example
|
|
148
|
-
* ```ts
|
|
149
|
-
* import {
|
|
150
|
-
* AzureKeyCredential,
|
|
151
|
-
* SearchClient,
|
|
152
|
-
* SearchFieldArray,
|
|
153
|
-
* } from "@azure/search-documents";
|
|
150
|
+
* ```ts snippet:ReadmeSampleSearchTModel
|
|
151
|
+
* import { SearchClient, AzureKeyCredential, SearchFieldArray } from "@azure/search-documents";
|
|
154
152
|
*
|
|
155
153
|
* type TModel = {
|
|
156
154
|
* key: string;
|
|
157
|
-
* azure?: {
|
|
155
|
+
* azure?: {
|
|
156
|
+
* sdk: string | null;
|
|
157
|
+
* } | null;
|
|
158
158
|
* };
|
|
159
159
|
*
|
|
160
160
|
* const client = new SearchClient<TModel>(
|
|
161
161
|
* "endpoint.azure",
|
|
162
162
|
* "indexName",
|
|
163
|
-
* new AzureKeyCredential("key")
|
|
163
|
+
* new AzureKeyCredential("key"),
|
|
164
164
|
* );
|
|
165
165
|
*
|
|
166
166
|
* const select = ["azure/sdk"] as const;
|
|
@@ -180,22 +180,20 @@ export declare class SearchClient<TModel extends object> implements IndexDocumen
|
|
|
180
180
|
* @param suggesterName - The name of the suggester as specified in the suggesters collection that's part of the index definition.
|
|
181
181
|
* @param options - Options for the suggest operation
|
|
182
182
|
* @example
|
|
183
|
-
* ```ts
|
|
184
|
-
* import {
|
|
185
|
-
* AzureKeyCredential,
|
|
186
|
-
* SearchClient,
|
|
187
|
-
* SearchFieldArray,
|
|
188
|
-
* } from "@azure/search-documents";
|
|
183
|
+
* ```ts snippet:ReadmeSampleSuggest
|
|
184
|
+
* import { SearchClient, AzureKeyCredential, SearchFieldArray } from "@azure/search-documents";
|
|
189
185
|
*
|
|
190
186
|
* type TModel = {
|
|
191
187
|
* key: string;
|
|
192
|
-
* azure?: {
|
|
188
|
+
* azure?: {
|
|
189
|
+
* sdk: string | null;
|
|
190
|
+
* } | null;
|
|
193
191
|
* };
|
|
194
192
|
*
|
|
195
193
|
* const client = new SearchClient<TModel>(
|
|
196
194
|
* "endpoint.azure",
|
|
197
195
|
* "indexName",
|
|
198
|
-
* new AzureKeyCredential("key")
|
|
196
|
+
* new AzureKeyCredential("key"),
|
|
199
197
|
* );
|
|
200
198
|
*
|
|
201
199
|
* const select = ["azure/sdk"] as const;
|