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 @@
+
|
---|