From 03959118b2126deecb81a8053fd2bc16b8ee1924 Mon Sep 17 00:00:00 2001 From: Sarangan Rajamanickam Date: Thu, 21 Jan 2021 21:10:58 -0800 Subject: [PATCH] Custom Code Changes --- sdk/search/search-documents/src/index.ts | 35 +++++- .../search-documents/src/searchClient.ts | 2 +- .../search-documents/src/searchIndexClient.ts | 6 +- .../src/searchIndexerClient.ts | 8 +- .../search-documents/src/serviceModels.ts | 30 ++--- .../search-documents/src/serviceUtils.ts | 110 ++++++++++++++---- 6 files changed, 145 insertions(+), 46 deletions(-) diff --git a/sdk/search/search-documents/src/index.ts b/sdk/search/search-documents/src/index.ts index 271876fb2b8a..9d584a37c038 100644 --- a/sdk/search/search-documents/src/index.ts +++ b/sdk/search/search-documents/src/index.ts @@ -129,6 +129,7 @@ export { } from "./generated/data/models"; export { RegexFlags, + KnownRegexFlags, LuceneStandardAnalyzer, StopAnalyzer, MappingCharFilter, @@ -187,6 +188,7 @@ export { AnalyzeResult, AnalyzedTokenInfo, ConditionalSkill, + CustomEntityLookupSkill, KeyPhraseExtractionSkill, OcrSkill, ImageAnalysisSkill, @@ -199,20 +201,31 @@ export { TextTranslationSkill, WebApiSkill, SentimentSkillLanguage, + KnownSentimentSkillLanguage, SplitSkillLanguage, + KnownSplitSkillLanguage, TextSplitMode, + KnownTextSplitMode, TextTranslationSkillLanguage, + KnownTextTranslationSkillLanguage, DefaultCognitiveServicesAccount, CognitiveServicesAccountKey, InputFieldMappingEntry, OutputFieldMappingEntry, EntityCategory, + KnownEntityCategory, EntityRecognitionSkillLanguage, + KnownEntityRecognitionSkillLanguage, ImageAnalysisSkillLanguage, + KnownImageAnalysisSkillLanguage, ImageDetail, + KnownImageDetail, VisualFeature, + KnownVisualFeature, KeyPhraseExtractionSkillLanguage, + KnownKeyPhraseExtractionSkillLanguage, OcrSkillLanguage, + KnownOcrSkillLanguage, FieldMapping, IndexingParameters, IndexingSchedule, @@ -226,6 +239,7 @@ export { SearchIndexerWarning, SearchIndexerDataContainer, SearchIndexerDataSourceType, + KnownSearchIndexerDataSourceType, SoftDeleteColumnDeletionDetectionPolicy, SqlIntegratedChangeTrackingPolicy, HighWaterMarkChangeDetectionPolicy, @@ -233,13 +247,32 @@ export { ServiceLimits, ResourceCounter, LexicalAnalyzerName, + KnownLexicalAnalyzerName, ClassicSimilarity, BM25Similarity, IndexingParametersConfiguration, BlobIndexerDataToExtract, + KnownBlobIndexerDataToExtract, IndexerExecutionEnvironment, BlobIndexerImageAction, + KnownBlobIndexerImageAction, BlobIndexerParsingMode, - BlobIndexerPDFTextRotationAlgorithm + KnownBlobIndexerParsingMode, + BlobIndexerPDFTextRotationAlgorithm, + KnownBlobIndexerPDFTextRotationAlgorithm, + TokenFilter as BaseTokenFilter, + Similarity, + LexicalTokenizer as BaseLexicalTokenizer, + CognitiveServicesAccount as BaseCognitiveServicesAccount, + SearchIndexerSkill as BaseSearchIndexerSkill, + ScoringFunction as BaseScoringFunction, + DataChangeDetectionPolicy as BaseDataChangeDetectionPolicy, + LexicalAnalyzer as BaseLexicalAnalyzer, + CharFilter as BaseCharFilter, + DataDeletionDetectionPolicy as BaseDataDeletionDetectionPolicy, + CustomEntityLookupSkillLanguage, + KnownCustomEntityLookupSkillLanguage, + CustomEntity, + CustomEntityAlias } from "./generated/service/models"; export { AzureKeyCredential } from "@azure/core-auth"; diff --git a/sdk/search/search-documents/src/searchClient.ts b/sdk/search/search-documents/src/searchClient.ts index 9e49b506fea8..88b222dddfd8 100644 --- a/sdk/search/search-documents/src/searchClient.ts +++ b/sdk/search/search-documents/src/searchClient.ts @@ -148,7 +148,7 @@ export class SearchClient { pipeline.requestPolicyFactories.unshift(odataMetadataPolicy("none")); } - this.client = new GeneratedClient(this.apiVersion, this.endpoint, this.indexName, pipeline); + this.client = new GeneratedClient(this.endpoint, this.indexName, this.apiVersion, pipeline); } /** diff --git a/sdk/search/search-documents/src/searchIndexClient.ts b/sdk/search/search-documents/src/searchIndexClient.ts index e5034b84c56d..e58ccaf86d37 100644 --- a/sdk/search/search-documents/src/searchIndexClient.ts +++ b/sdk/search/search-documents/src/searchIndexClient.ts @@ -137,7 +137,7 @@ export class SearchIndexClient { pipeline.requestPolicyFactories.unshift(odataMetadataPolicy("minimal")); } - this.client = new GeneratedClient(this.apiVersion, this.endpoint, pipeline); + this.client = new GeneratedClient(this.endpoint, this.apiVersion, pipeline); } private async *listIndexesPage( @@ -473,7 +473,7 @@ export class SearchIndexClient { const etag = typeof index === "string" ? undefined : options.onlyIfUnchanged ? index.etag : undefined; - await this.client.indexes.deleteMethod(indexName, { + await this.client.indexes.delete(indexName, { ...operationOptionsToRequestOptionsBase(updatedOptions), ifMatch: etag }); @@ -507,7 +507,7 @@ export class SearchIndexClient { ? synonymMap.etag : undefined; - await this.client.synonymMaps.deleteMethod(synonymMapName, { + await this.client.synonymMaps.delete(synonymMapName, { ...operationOptionsToRequestOptionsBase(updatedOptions), ifMatch: etag }); diff --git a/sdk/search/search-documents/src/searchIndexerClient.ts b/sdk/search/search-documents/src/searchIndexerClient.ts index c18421a95862..cc7f46eba1e1 100644 --- a/sdk/search/search-documents/src/searchIndexerClient.ts +++ b/sdk/search/search-documents/src/searchIndexerClient.ts @@ -128,7 +128,7 @@ export class SearchIndexerClient { pipeline.requestPolicyFactories.unshift(odataMetadataPolicy("minimal")); } - this.client = new GeneratedClient(this.apiVersion, this.endpoint, pipeline); + this.client = new GeneratedClient(this.endpoint, this.apiVersion, pipeline); } /** @@ -574,7 +574,7 @@ export class SearchIndexerClient { ? indexer.etag : undefined; - await this.client.indexers.deleteMethod(indexerName, { + await this.client.indexers.delete(indexerName, { ...operationOptionsToRequestOptionsBase(updatedOptions), ifMatch: etag }); @@ -612,7 +612,7 @@ export class SearchIndexerClient { ? dataSourceConnection.etag : undefined; - await this.client.dataSources.deleteMethod(dataSourceConnectionName, { + await this.client.dataSources.delete(dataSourceConnectionName, { ...operationOptionsToRequestOptionsBase(updatedOptions), ifMatch: etag }); @@ -646,7 +646,7 @@ export class SearchIndexerClient { ? skillset.etag : undefined; - await this.client.skillsets.deleteMethod(skillsetName, { + await this.client.skillsets.delete(skillsetName, { ...operationOptionsToRequestOptionsBase(updatedOptions), ifMatch: etag }); diff --git a/sdk/search/search-documents/src/serviceModels.ts b/sdk/search/search-documents/src/serviceModels.ts index 0fce983cb574..c3a1c97103eb 100644 --- a/sdk/search/search-documents/src/serviceModels.ts +++ b/sdk/search/search-documents/src/serviceModels.ts @@ -71,7 +71,8 @@ import { ServiceLimits, FieldMapping, IndexingParameters, - IndexingSchedule + IndexingSchedule, + CustomEntityLookupSkill } from "./generated/service/models"; import { PagedAsyncIterableIterator } from "@azure/core-paging"; @@ -415,7 +416,7 @@ export interface CustomAnalyzer { * The name of the tokenizer to use to divide continuous text into a sequence of tokens, such as * breaking a sentence into words. KnownTokenizerNames is an enum containing known values. */ - tokenizerName: string; + tokenizer: string; /** * A list of token filters used to filter out or modify the tokens generated by a tokenizer. For * example, you can specify a lowercase filter that converts all characters to lowercase. The @@ -454,7 +455,8 @@ export type SearchIndexerSkill = | SentimentSkill | SplitSkill | TextTranslationSkill - | WebApiSkill; + | WebApiSkill + | CustomEntityLookupSkill; /** * Contains the possible cases for CognitiveServicesAccount. @@ -850,7 +852,7 @@ export interface SynonymMap { * keys is not available for free search services, and is only available for paid services * created on or after January 1, 2019. */ - encryptionKey?: SearchResourceEncryptionKey; + encryptionKey?: SearchResourceEncryptionKey | null; /** * The ETag of the synonym map. */ @@ -899,7 +901,7 @@ export interface SearchIndex { /** * Options to control Cross-Origin Resource Sharing (CORS) for the index. */ - corsOptions?: CorsOptions; + corsOptions?: CorsOptions | null; /** * The suggesters for the index. */ @@ -930,7 +932,7 @@ export interface SearchIndex { * keys is not available for free search services, and is only available for paid services * created on or after January 1, 2019. */ - encryptionKey?: SearchResourceEncryptionKey; + encryptionKey?: SearchResourceEncryptionKey | null; /** * The type of similarity algorithm to be used when scoring and ranking the documents matching a * search query. The similarity algorithm can only be defined at index creation time and cannot @@ -970,11 +972,11 @@ export interface SearchIndexer { /** * The schedule for this indexer. */ - schedule?: IndexingSchedule; + schedule?: IndexingSchedule | null; /** * Parameters for indexer execution. */ - parameters?: IndexingParameters; + parameters?: IndexingParameters | null; /** * Defines mappings between fields in the data source and corresponding target fields in the * index. @@ -987,7 +989,7 @@ export interface SearchIndexer { /** * A value indicating whether the indexer is disabled. Default is false. Default value: false. */ - isDisabled?: boolean; + isDisabled?: boolean | null; /** * The ETag of the indexer. */ @@ -1003,7 +1005,7 @@ export interface SearchIndexer { * customer-managed keys is not available for free search services, and is only available for * paid services created on or after January 1, 2019. */ - encryptionKey?: SearchResourceEncryptionKey; + encryptionKey?: SearchResourceEncryptionKey | null; } /** @@ -1072,7 +1074,7 @@ export interface SearchIndexerSkillset { * definition will be unaffected. Encryption with customer-managed keys is not available for free * search services, and is only available for paid services created on or after January 1, 2019. */ - encryptionKey?: SearchResourceEncryptionKey; + encryptionKey?: SearchResourceEncryptionKey | null; } /** @@ -1786,11 +1788,11 @@ export interface SearchIndexerDataSourceConnection { /** * The data change detection policy for the datasource. */ - dataChangeDetectionPolicy?: DataChangeDetectionPolicy; + dataChangeDetectionPolicy?: DataChangeDetectionPolicy | null; /** * The data deletion detection policy for the datasource. */ - dataDeletionDetectionPolicy?: DataDeletionDetectionPolicy; + dataDeletionDetectionPolicy?: DataDeletionDetectionPolicy | null; /** * The ETag of the DataSource. */ @@ -1806,6 +1808,6 @@ export interface SearchIndexerDataSourceConnection { * available for free search services, and is only available for paid services created on or * after January 1, 2019. */ - encryptionKey?: SearchResourceEncryptionKey; + encryptionKey?: SearchResourceEncryptionKey | null; } // END manually modified generated interfaces diff --git a/sdk/search/search-documents/src/serviceUtils.ts b/sdk/search/search-documents/src/serviceUtils.ts index dd1c61962b94..0699aed659a9 100644 --- a/sdk/search/search-documents/src/serviceUtils.ts +++ b/sdk/search/search-documents/src/serviceUtils.ts @@ -26,7 +26,25 @@ import { BM25Similarity, ClassicSimilarity, TokenFilterUnion, - SearchResourceEncryptionKey as GeneratedSearchResourceEncryptionKey + SearchResourceEncryptionKey as GeneratedSearchResourceEncryptionKey, + ConditionalSkill, + KeyPhraseExtractionSkill, + OcrSkill, + ImageAnalysisSkill, + LanguageDetectionSkill, + ShaperSkill, + MergeSkill, + EntityRecognitionSkill, + SentimentSkill, + SplitSkill, + CustomEntityLookupSkill, + TextTranslationSkill, + WebApiSkill, + LuceneStandardAnalyzer, + StopAnalyzer, + PatternAnalyzer as GeneratedPatternAnalyzer, + CustomAnalyzer, + PatternTokenizer } from "./generated/service/models"; import { LexicalAnalyzer, @@ -48,7 +66,8 @@ import { DataChangeDetectionPolicy, DataDeletionDetectionPolicy, SimilarityAlgorithm, - SearchResourceEncryptionKey + SearchResourceEncryptionKey, + PatternAnalyzer } from "./serviceModels"; import { SuggestDocumentsResult, SuggestResult, SearchResult } from "./indexModels"; import { @@ -63,8 +82,46 @@ export function convertSkillsToPublic(skills: SearchIndexerSkillUnion[]): Search const result: SearchIndexerSkill[] = []; for (const skill of skills) { - if (skill.odatatype !== "SearchIndexerSkill") { - result.push(skill); + switch (skill.odatatype) { + case "#Microsoft.Skills.Util.ConditionalSkill": + result.push(skill as ConditionalSkill); + break; + case "#Microsoft.Skills.Text.KeyPhraseExtractionSkill": + result.push(skill as KeyPhraseExtractionSkill); + break; + case "#Microsoft.Skills.Vision.OcrSkill": + result.push(skill as OcrSkill); + break; + case "#Microsoft.Skills.Vision.ImageAnalysisSkill": + result.push(skill as ImageAnalysisSkill); + break; + case "#Microsoft.Skills.Text.LanguageDetectionSkill": + result.push(skill as LanguageDetectionSkill); + break; + case "#Microsoft.Skills.Util.ShaperSkill": + result.push(skill as ShaperSkill); + break; + case "#Microsoft.Skills.Text.MergeSkill": + result.push(skill as MergeSkill); + break; + case "#Microsoft.Skills.Text.EntityRecognitionSkill": + result.push(skill as EntityRecognitionSkill); + break; + case "#Microsoft.Skills.Text.SentimentSkill": + result.push(skill as SentimentSkill); + break; + case "#Microsoft.Skills.Text.SplitSkill": + result.push(skill as SplitSkill); + break; + case "#Microsoft.Skills.Text.CustomEntityLookupSkill": + result.push(skill as CustomEntityLookupSkill); + break; + case "#Microsoft.Skills.Text.TranslationSkill": + result.push(skill as TextTranslationSkill); + break; + case "#Microsoft.Skills.Custom.WebApiSkill": + result.push(skill as WebApiSkill); + break; } } return result; @@ -132,7 +189,7 @@ export function convertAnalyzersToGenerated( case "#Microsoft.Azure.Search.CustomAnalyzer": result.push({ ...analyzer, - tokenizer: analyzer.tokenizerName + tokenizer: analyzer.tokenizer }); break; } @@ -151,20 +208,24 @@ export function convertAnalyzersToPublic( for (const analyzer of analyzers) { switch (analyzer.odatatype) { case "#Microsoft.Azure.Search.StandardAnalyzer": + result.push(analyzer as LuceneStandardAnalyzer); + break; case "#Microsoft.Azure.Search.StopAnalyzer": - result.push(analyzer); + result.push(analyzer as StopAnalyzer); break; case "#Microsoft.Azure.Search.PatternAnalyzer": result.push({ ...analyzer, - flags: analyzer.flags ? (analyzer.flags.split("|") as RegexFlags[]) : undefined - }); + flags: (analyzer as GeneratedPatternAnalyzer).flags + ? ((analyzer as GeneratedPatternAnalyzer).flags!.split("|") as RegexFlags[]) + : undefined + } as PatternAnalyzer); break; case "#Microsoft.Azure.Search.CustomAnalyzer": result.push({ ...analyzer, - tokenizerName: analyzer.tokenizer - }); + tokenizer: (analyzer as CustomAnalyzer).tokenizer + } as CustomAnalyzer); break; } } @@ -181,9 +242,9 @@ export function convertFieldsToPublic(fields: GeneratedSearchField[]): SearchFie if (field.type === "Collection(Edm.ComplexType)" || field.type === "Edm.ComplexType") { result = field as ComplexField; } else { - const anayzerName: LexicalAnalyzerName | undefined = field.analyzer; - const searchAnalyzerName: LexicalAnalyzerName | undefined = field.searchAnalyzer; - const indexAnalyzerName: LexicalAnalyzerName | undefined = field.indexAnalyzer; + const anayzerName: LexicalAnalyzerName | undefined | null = field.analyzer; + const searchAnalyzerName: LexicalAnalyzerName | undefined | null = field.searchAnalyzer; + const indexAnalyzerName: LexicalAnalyzerName | undefined | null = field.indexAnalyzer; const synonymMapNames: string[] | undefined = field.synonymMaps; const { retrievable, ...restField } = field; @@ -259,9 +320,11 @@ export function convertTokenizersToPublic( if (tokenizer.odatatype === "#Microsoft.Azure.Search.PatternTokenizer") { result.push({ ...tokenizer, - flags: tokenizer.flags ? (tokenizer.flags.split("|") as RegexFlags[]) : undefined + flags: (tokenizer as PatternTokenizer).flags + ? ((tokenizer as PatternTokenizer).flags!.split("|") as RegexFlags[]) + : undefined }); - } else if (tokenizer.odatatype !== "LexicalTokenizer") { + } else { result.push(tokenizer); } } @@ -311,8 +374,8 @@ export function extractOperationOptions( } export function convertEncryptionKeyToPublic( - encryptionKey?: GeneratedSearchResourceEncryptionKey -): SearchResourceEncryptionKey | undefined { + encryptionKey?: GeneratedSearchResourceEncryptionKey | null +): SearchResourceEncryptionKey | undefined | null { if (!encryptionKey) { return encryptionKey; } @@ -332,8 +395,8 @@ export function convertEncryptionKeyToPublic( } export function convertEncryptionKeyToGenerated( - encryptionKey?: SearchResourceEncryptionKey -): GeneratedSearchResourceEncryptionKey | undefined { + encryptionKey?: SearchResourceEncryptionKey | null +): GeneratedSearchResourceEncryptionKey | undefined | null { if (!encryptionKey) { return encryptionKey; } @@ -482,6 +545,7 @@ export function generatedSynonymMapToPublicSynonymMap(synonymMap: GeneratedSynon export function publicSynonymMapToGeneratedSynonymMap(synonymMap: SynonymMap): GeneratedSynonymMap { const result: GeneratedSynonymMap = { name: synonymMap.name, + format: "solr", encryptionKey: convertEncryptionKeyToGenerated(synonymMap.encryptionKey), etag: synonymMap.etag, synonyms: synonymMap.synonyms.join("\n") @@ -549,8 +613,8 @@ export function generatedDataSourceToPublicDataSource( } export function convertDataChangeDetectionPolicyToPublic( - dataChangeDetectionPolicy?: DataChangeDetectionPolicyUnion -): DataChangeDetectionPolicy | undefined { + dataChangeDetectionPolicy?: DataChangeDetectionPolicyUnion | null +): DataChangeDetectionPolicy | undefined | null { if (!dataChangeDetectionPolicy) { return dataChangeDetectionPolicy; } @@ -566,8 +630,8 @@ export function convertDataChangeDetectionPolicyToPublic( } export function convertDataDeletionDetectionPolicyToPublic( - dataDeletionDetectionPolicy?: DataDeletionDetectionPolicyUnion -): DataDeletionDetectionPolicy | undefined { + dataDeletionDetectionPolicy?: DataDeletionDetectionPolicyUnion | null +): DataDeletionDetectionPolicy | undefined | null { if (!dataDeletionDetectionPolicy) { return dataDeletionDetectionPolicy; }