From 74818b934c8fce936e1b4f71a6bb45ca4c9cf71b Mon Sep 17 00:00:00 2001 From: Anna Lapre <98433280+alapre@users.noreply.github.com> Date: Thu, 15 Aug 2024 16:56:34 -0400 Subject: [PATCH] search-core: add support for FunctionVertical (#271) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR adds a Source enum type for Function Vertical, updates ResultFactory.ts to handle a function vertical response, and adds auto test. Test: manual, auto
 Tested with auto test and through test site, ensuring function vertical data appear in the response. --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- docs/search-core.source.md | 13 +++++++ etc/search-core.api.md | 1 + package-lock.json | 4 +-- package.json | 2 +- src/models/searchservice/response/Source.ts | 2 ++ .../searchservice/ResultsFactory.ts | 12 ++++++- test-site/index.html | 1 + test-site/js-index.html | 1 + test-site/package-lock.json | 2 +- test-site/src/js/index.js | 9 ++++- test-site/src/js/requests/verticalRequest.js | 7 ++-- test-site/src/ts/index.ts | 11 ++++-- test-site/src/ts/requests/verticalRequest.ts | 7 ++-- .../searchservice/ResultsFactory.ts | 34 +++++++++++++++++++ 14 files changed, 94 insertions(+), 12 deletions(-) diff --git a/docs/search-core.source.md b/docs/search-core.source.md index b53ed076..349db6fd 100644 --- a/docs/search-core.source.md +++ b/docs/search-core.source.md @@ -14,7 +14,20 @@ export declare enum Source ## Enumeration Members +<<<<<<< HEAD
+======= +| Member | Value | Description | +| --- | --- | --- | +| Algolia | "ALGOLIA" | The result is from Algolia. | +| Bing | "BING_CSE" | The result is from Bing Search Engine. | +| Custom | "CUSTOM_SEARCHER" | The result was from a custom source. | +| DocumentVertical | "DOCUMENT_VERTICAL" | The result is from a document vertical. | +| FunctionVertical | "FUNCTION_VERTICAL" | The result is from a function vertical. | +| Google | "GOOGLE_CSE" | The result is from Google Custom Search Engine. | +| KnowledgeManager | "KNOWLEDGE_MANAGER" | The result is from a Knowledge Graph. | +| Zendesk | "ZENDESK" | The result is from Zendesk. | +>>>>>>> 97e068e (search-core: add support for FunctionVertical (#271)) Member diff --git a/etc/search-core.api.md b/etc/search-core.api.md index dac8becf..e049deca 100644 --- a/etc/search-core.api.md +++ b/etc/search-core.api.md @@ -761,6 +761,7 @@ export enum SortType { export enum Source { Custom = "CUSTOM_SEARCHER", DocumentVertical = "DOCUMENT_VERTICAL", + FunctionVertical = "FUNCTION_VERTICAL", Google = "GOOGLE_CSE", KnowledgeManager = "KNOWLEDGE_MANAGER" } diff --git a/package-lock.json b/package-lock.json index c9adb1f5..07b83e13 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@yext/search-core", - "version": "2.6.0-beta.2", + "version": "2.6.0-beta.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@yext/search-core", - "version": "2.6.0-beta.2", + "version": "2.6.0-beta.3", "license": "BSD-3-Clause", "dependencies": { "@babel/runtime-corejs3": "^7.12.5", diff --git a/package.json b/package.json index b611ea3d..34ca301e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@yext/search-core", - "version": "2.6.0-beta.2", + "version": "2.6.0-beta.3", "description": "Typescript Networking Library for the Yext Search API", "main": "./dist/commonjs/src/index.js", "module": "./dist/esm/src/index.js", diff --git a/src/models/searchservice/response/Source.ts b/src/models/searchservice/response/Source.ts index 08288cb8..2f0c500e 100644 --- a/src/models/searchservice/response/Source.ts +++ b/src/models/searchservice/response/Source.ts @@ -12,4 +12,6 @@ export enum Source { Custom = 'CUSTOM_SEARCHER', /** The result is from a document vertical. */ DocumentVertical = 'DOCUMENT_VERTICAL', + /** The result is from a function vertical. */ + FunctionVertical = 'FUNCTION_VERTICAL', } diff --git a/src/transformers/searchservice/ResultsFactory.ts b/src/transformers/searchservice/ResultsFactory.ts index d8909582..1b4270a9 100644 --- a/src/transformers/searchservice/ResultsFactory.ts +++ b/src/transformers/searchservice/ResultsFactory.ts @@ -20,6 +20,8 @@ export class ResultsFactory { return this.fromGoogleCustomSearchEngine(result, resultIndex); case Source.DocumentVertical: return this.fromDocumentVertical(result, resultIndex); + case Source.FunctionVertical: + return this.fromFunctionVertical(result, resultIndex); default: return this.fromCustomSource(result, resultIndex); } @@ -72,10 +74,18 @@ export class ResultsFactory { } private static fromCustomSource(result: any, index: number): Result { + return this.fromCustomDataHelper(result, index, Source.Custom); + } + + private static fromFunctionVertical(result: any, index: number): Result { + return this.fromCustomDataHelper(result, index, Source.FunctionVertical); + } + + private static fromCustomDataHelper(result: any, index: number, source: Source): Result { const rawData = result.data ?? result; return { rawData: rawData, - source: Source.Custom, + source: source, index: index, name: rawData.name, description: rawData.description, // Do we want to truncate this like in the SDK? diff --git a/test-site/index.html b/test-site/index.html index 5d5914e6..9de8956f 100644 --- a/test-site/index.html +++ b/test-site/index.html @@ -14,5 +14,6 @@ + diff --git a/test-site/js-index.html b/test-site/js-index.html index 5058203f..8c0dee64 100644 --- a/test-site/js-index.html +++ b/test-site/js-index.html @@ -13,5 +13,6 @@ + diff --git a/test-site/package-lock.json b/test-site/package-lock.json index 3356406c..42e3e7a6 100644 --- a/test-site/package-lock.json +++ b/test-site/package-lock.json @@ -18,7 +18,7 @@ }, "..": { "name": "@yext/search-core", - "version": "2.6.0-beta", + "version": "2.6.0-beta.3", "extraneous": true, "license": "BSD-3-Clause", "dependencies": { diff --git a/test-site/src/js/index.js b/test-site/src/js/index.js index ace12653..ddc361ca 100644 --- a/test-site/src/js/index.js +++ b/test-site/src/js/index.js @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { provideCore } from '@yext/search-core'; -import verticalRequest from './requests/verticalRequest'; +import { verticalRequest, functionVerticalRequest } from './requests/verticalRequest'; import universalRequest from './requests/universalRequest'; import questionRequest from './requests/questionRequest'; import { univeralAutocompleteRequest, verticalAutocompleteRequest, filterSearchRequest } from './requests/autocompleteRequests'; @@ -69,6 +69,13 @@ export async function generativeDirectAnswer() { updateUI(data, startTime, 'Core Generative Direct Answer Response:'); } +export async function functionVerticalSearch() { + loadingSpinner(); + const startTime = new Date().getTime(); + const results = await globalCore.verticalSearch(functionVerticalRequest); + updateUI(results, startTime, 'Core Function Vertical Response:'); +} + function loadingSpinner() { element.textContent = 'Loading...'; } diff --git a/test-site/src/js/requests/verticalRequest.js b/test-site/src/js/requests/verticalRequest.js index 9c594d51..e5805288 100644 --- a/test-site/src/js/requests/verticalRequest.js +++ b/test-site/src/js/requests/verticalRequest.js @@ -1,6 +1,6 @@ import { QueryTrigger } from '@yext/search-core'; -const verticalRequest = { +export const verticalRequest = { verticalKey: 'people', query: 'virginia', queryTrigger: QueryTrigger.Initialize, @@ -12,4 +12,7 @@ const verticalRequest = { referrerPageUrl: 'www.google.com/answers/not/ads' }; -export default verticalRequest; \ No newline at end of file +export const functionVerticalRequest = { + verticalKey: 'function_vertical', + query: 'virginia', +}; \ No newline at end of file diff --git a/test-site/src/ts/index.ts b/test-site/src/ts/index.ts index 50381a5f..ad0c4b4f 100644 --- a/test-site/src/ts/index.ts +++ b/test-site/src/ts/index.ts @@ -1,5 +1,5 @@ import { provideCore, SearchConfig, SearchCore, UniversalSearchRequest, UniversalSearchResponse } from '@yext/search-core'; -import verticalRequest from './requests/verticalRequest'; +import { verticalRequest, functionVerticalRequest } from './requests/verticalRequest'; import universalRequest from './requests/universalRequest'; import questionRequest from './requests/questionRequest'; import { univeralAutocompleteRequest, verticalAutocompleteRequest, filterSearchRequest } from './requests/autocompleteRequests'; @@ -8,7 +8,7 @@ import initDirectAnswers from './initDirectAnswers'; const coreConfig: SearchConfig = { apiKey: process.env.API_KEY, - experienceKey: 'slanswers', + experienceKey: 'developer-support-test', locale: 'en', experienceVersion: 'PRODUCTION', }; @@ -44,6 +44,13 @@ export async function verticalSearch(): Promise { updateUI(results, startTime, 'Core Vertical Response:'); } +export async function functionVerticalSearch(): Promise { + loadingSpinner(); + const startTime = new Date().getTime(); + const results = await globalCore.verticalSearch(functionVerticalRequest); + updateUI(results, startTime, 'Core Function Vertical Response:'); +} + export async function submitQuestion(): Promise { loadingSpinner(); const startTime = new Date().getTime(); diff --git a/test-site/src/ts/requests/verticalRequest.ts b/test-site/src/ts/requests/verticalRequest.ts index 1079b41d..355d7565 100644 --- a/test-site/src/ts/requests/verticalRequest.ts +++ b/test-site/src/ts/requests/verticalRequest.ts @@ -1,6 +1,6 @@ import { QueryTrigger, VerticalSearchRequest } from '@yext/search-core'; -const verticalRequest: VerticalSearchRequest = { +export const verticalRequest: VerticalSearchRequest = { verticalKey: 'people', query: 'virginia', queryTrigger: QueryTrigger.Initialize, @@ -17,4 +17,7 @@ const verticalRequest: VerticalSearchRequest = { } }; -export default verticalRequest; \ No newline at end of file +export const functionVerticalRequest: VerticalSearchRequest = { + verticalKey: 'function_vertical', + query: 'virginia', +}; \ No newline at end of file diff --git a/tests/transformers/searchservice/ResultsFactory.ts b/tests/transformers/searchservice/ResultsFactory.ts index 627184bd..749ceefa 100644 --- a/tests/transformers/searchservice/ResultsFactory.ts +++ b/tests/transformers/searchservice/ResultsFactory.ts @@ -105,3 +105,37 @@ it('properly transforms backend results from custom source', () => { const actualResults = ResultsFactory.create(genericData, Source.Custom); expect(expectedResults).toMatchObject(actualResults); }); + +it('properly transforms backend results from function vertical', () => { + const genericData = [{ + data: { + answer: 'You should still self\-quarantine for 14 days since your last exposure.', + c_organization: 'CDC', + id: 'iwasaroundsomeonewhohascovid19andmycovid19testcame', + website: 'https://www.cdc.gov/coronavirus/2019-ncov/faq.html', + name: 'Do I still need to quarantine for 14 days?', + description: 'COVID question 2' + }, + highlightedFields: {} + }]; + + const expectedResults = [{ + description: 'COVID question 2', + id: 'iwasaroundsomeonewhohascovid19andmycovid19testcame', + index: 1, + link: 'https://www.cdc.gov/coronavirus/2019-ncov/faq.html', + name: 'Do I still need to quarantine for 14 days?', + rawData: { + answer: 'You should still self\-quarantine for 14 days since your last exposure.', + c_organization: 'CDC', + id: 'iwasaroundsomeonewhohascovid19andmycovid19testcame', + website: 'https://www.cdc.gov/coronavirus/2019-ncov/faq.html', + name: 'Do I still need to quarantine for 14 days?', + description: 'COVID question 2' + }, + source: Source.FunctionVertical + }]; + + const actualResults = ResultsFactory.create(genericData, Source.FunctionVertical); + expect(expectedResults).toMatchObject(actualResults); +});