Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convenience Method to create a synonymmap object #15129

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sdk/search/search-documents/review/search-documents.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ export interface CreateOrUpdateSynonymMapOptions extends OperationOptions {
// @public
export type CreateSkillsetOptions = OperationOptions;

// @public
export function createSynonymMapFromFile(name: string, filePath: string): SynonymMap;

// @public
export type CreateSynonymMapOptions = OperationOptions;

Expand Down
1 change: 1 addition & 0 deletions sdk/search/search-documents/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,4 @@ export {
SearchIndexerKnowledgeStoreTableProjectionSelector
} from "./generated/service/models";
export { AzureKeyCredential } from "@azure/core-auth";
export { createSynonymMapFromFile } from "./serviceUtils";
16 changes: 16 additions & 0 deletions sdk/search/search-documents/src/serviceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import {
SuggestDocumentsResult as GeneratedSuggestDocumentsResult,
SearchResult as GeneratedSearchResult
} from "./generated/data/models";
import * as fs from "fs";
sarangan12 marked this conversation as resolved.
Show resolved Hide resolved

export function convertSkillsToPublic(skills: SearchIndexerSkillUnion[]): SearchIndexerSkill[] {
if (!skills) {
Expand Down Expand Up @@ -664,3 +665,18 @@ export function getRandomIntegerInclusive(min: number, max: number): number {
const offset = Math.floor(Math.random() * (max - min + 1));
return offset + min;
}

/**
* Helper method to create a SynonymMap object.
sarangan12 marked this conversation as resolved.
Show resolved Hide resolved
*
* @param name - Name of the SynonymMap.
* @param filePath - Path of the file that contains the Synonyms (seperated by new lines)
* @returns SynonymMap object
*/
export function createSynonymMapFromFile(name: string, filePath: string): SynonymMap {
sarangan12 marked this conversation as resolved.
Show resolved Hide resolved
const synonyms: string[] = fs.readFileSync(filePath, "utf-8").split("\n");
sarangan12 marked this conversation as resolved.
Show resolved Hide resolved
return {
name,
synonyms
};
}