From 4b688b6218337b96da8522c3c08b171e23e4045a Mon Sep 17 00:00:00 2001 From: Connor Anderson Date: Wed, 27 Sep 2023 15:58:25 -0400 Subject: [PATCH] add document vertical support --- docs/search-core.document_2.documentscore.md | 13 ++++++++++++ docs/search-core.document_2.md | 21 +++++++++++++++++++ docs/search-core.document_2.segments.md | 13 ++++++++++++ docs/search-core.md | 2 ++ docs/search-core.result.document.md | 13 ++++++++++++ docs/search-core.result.documents.md | 13 ++++++++++++ docs/search-core.result.md | 3 +++ docs/search-core.result.segment.md | 13 ++++++++++++ docs/search-core.segment.md | 21 +++++++++++++++++++ docs/search-core.segment.score.md | 13 ++++++++++++ docs/search-core.segment.text.md | 13 ++++++++++++ docs/search-core.source.md | 1 + etc/search-core.api.md | 17 +++++++++++++++ package-lock.json | 4 ++-- package.json | 2 +- src/models/index.ts | 2 ++ src/models/searchservice/response/Document.ts | 13 ++++++++++++ src/models/searchservice/response/Result.ts | 16 +++++++++++++- src/models/searchservice/response/Segment.ts | 11 ++++++++++ src/models/searchservice/response/Source.ts | 4 +++- .../searchservice/ResultsFactory.ts | 18 ++++++++++++++++ 21 files changed, 221 insertions(+), 5 deletions(-) create mode 100644 docs/search-core.document_2.documentscore.md create mode 100644 docs/search-core.document_2.md create mode 100644 docs/search-core.document_2.segments.md create mode 100644 docs/search-core.result.document.md create mode 100644 docs/search-core.result.documents.md create mode 100644 docs/search-core.result.segment.md create mode 100644 docs/search-core.segment.md create mode 100644 docs/search-core.segment.score.md create mode 100644 docs/search-core.segment.text.md create mode 100644 src/models/searchservice/response/Document.ts create mode 100644 src/models/searchservice/response/Segment.ts diff --git a/docs/search-core.document_2.documentscore.md b/docs/search-core.document_2.documentscore.md new file mode 100644 index 00000000..c048b4ae --- /dev/null +++ b/docs/search-core.document_2.documentscore.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [Document\_2](./search-core.document_2.md) > [documentScore](./search-core.document_2.documentscore.md) + +## Document\_2.documentScore property + +The score calculated from whatever document search strategy was used. + +Signature: + +```typescript +documentScore: number; +``` diff --git a/docs/search-core.document_2.md b/docs/search-core.document_2.md new file mode 100644 index 00000000..eae472b0 --- /dev/null +++ b/docs/search-core.document_2.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [Document\_2](./search-core.document_2.md) + +## Document\_2 interface + +Details about the document and the document search algorithm + +Signature: + +```typescript +export interface Document +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [documentScore](./search-core.document_2.documentscore.md) | number | The score calculated from whatever document search strategy was used. | +| [segments](./search-core.document_2.segments.md) | [Segment](./search-core.segment.md)\[\] | All the relevant segments extracted from the document. | + diff --git a/docs/search-core.document_2.segments.md b/docs/search-core.document_2.segments.md new file mode 100644 index 00000000..c23eb2a6 --- /dev/null +++ b/docs/search-core.document_2.segments.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [Document\_2](./search-core.document_2.md) > [segments](./search-core.document_2.segments.md) + +## Document\_2.segments property + +All the relevant segments extracted from the document. + +Signature: + +```typescript +segments: Segment[]; +``` diff --git a/docs/search-core.md b/docs/search-core.md index ccbb1740..c96301f0 100644 --- a/docs/search-core.md +++ b/docs/search-core.md @@ -63,6 +63,7 @@ | [DisjunctionStaticFilter](./search-core.disjunctionstaticfilter.md) | A static filter composed by combining filters with the logical OR operator. The combined filters can either be field value filters or other disjunction filters. | | [DisplayableFacet](./search-core.displayablefacet.md) | A [Facet](./search-core.facet.md) which contains extra fields meant to be displayed to the end user. | | [DisplayableFacetOption](./search-core.displayablefacetoption.md) | A [FacetOption](./search-core.facetoption.md) with extra data meant to be displayed to the end user. | +| [Document\_2](./search-core.document_2.md) | Details about the document and the document search algorithm | | [EmailDirectAnswer](./search-core.emaildirectanswer.md) | A [BaseFieldValueDirectAnswer](./search-core.basefieldvaluedirectanswer.md) interface with 'email' field type. | | [Endpoints](./search-core.endpoints.md) | Overrides for the URLs which are used when making requests to the Search API. | | [FacebookUrlDirectAnswer](./search-core.facebookurldirectanswer.md) | A direct answer for a facebook url field. | @@ -105,6 +106,7 @@ | [SearchParameterField](./search-core.searchparameterfield.md) | Indicates which entity field to perform the autocomplete request on. | | [SearchRequest](./search-core.searchrequest.md) | Options for a Search API request. | | [SearchService](./search-core.searchservice.md) | A service which performs Yext Search. | +| [Segment](./search-core.segment.md) | A result produced by a document vertical. | | [ServingConfig](./search-core.servingconfig.md) | The configuration options for getting the endpoints. | | [Snippet](./search-core.snippet.md) | The section of text where a [FeaturedSnippetDirectAnswer](./search-core.featuredsnippetdirectanswer.md) was found. | | [SortBy](./search-core.sortby.md) | Represents a criterion that can be used to sort results. | diff --git a/docs/search-core.result.document.md b/docs/search-core.result.document.md new file mode 100644 index 00000000..4d8e99d4 --- /dev/null +++ b/docs/search-core.result.document.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [Result](./search-core.result.md) > [document](./search-core.result.document.md) + +## Result.document property + +A relevant document associated with the result. Present for document verticals grouped by Document. + +Signature: + +```typescript +document?: Document; +``` diff --git a/docs/search-core.result.documents.md b/docs/search-core.result.documents.md new file mode 100644 index 00000000..b1d36c83 --- /dev/null +++ b/docs/search-core.result.documents.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [Result](./search-core.result.md) > [documents](./search-core.result.documents.md) + +## Result.documents property + +All relevant documents associated with the result. Present for document verticals grouped by Entity. + +Signature: + +```typescript +documents?: Document[]; +``` diff --git a/docs/search-core.result.md b/docs/search-core.result.md index f7df95d7..8c22cd40 100644 --- a/docs/search-core.result.md +++ b/docs/search-core.result.md @@ -19,6 +19,8 @@ export interface Result> | [description?](./search-core.result.description.md) | string | (Optional) A description of the result. | | [distance?](./search-core.result.distance.md) | number | (Optional) The distance from the user to the result in meters. | | [distanceFromFilter?](./search-core.result.distancefromfilter.md) | number | (Optional) The distance from a [AppliedQueryFilter](./search-core.appliedqueryfilter.md) location to the result in meters. | +| [document?](./search-core.result.document.md) | Document | (Optional) A relevant document associated with the result. Present for document verticals grouped by Document. | +| [documents?](./search-core.result.documents.md) | Document\[\] | (Optional) All relevant documents associated with the result. Present for document verticals grouped by Entity. | | [entityType?](./search-core.result.entitytype.md) | string | (Optional) The entity type of the result. | | [highlightedFields?](./search-core.result.highlightedfields.md) | [HighlightedFields](./search-core.highlightedfields.md) | (Optional) The [highlighted fields](./search-core.highlightedfields.md) emphasized by the api. | | [id?](./search-core.result.id.md) | string | (Optional) The result ID which depends on the Result Source. | @@ -26,5 +28,6 @@ export interface Result> | [link?](./search-core.result.link.md) | string | (Optional) A hyperlink associated with the result. | | [name?](./search-core.result.name.md) | string | (Optional) The name of the result. | | [rawData](./search-core.result.rawdata.md) | T | Raw entity profile data in the shape of key-value pairs. | +| [segment?](./search-core.result.segment.md) | [Segment](./search-core.segment.md) | (Optional) A relevant segment associated with the result. Present for document verticals grouped by Segment. | | [source](./search-core.result.source.md) | [Source](./search-core.source.md) | Represents the source of a [Result](./search-core.result.md). | diff --git a/docs/search-core.result.segment.md b/docs/search-core.result.segment.md new file mode 100644 index 00000000..e7b561ce --- /dev/null +++ b/docs/search-core.result.segment.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [Result](./search-core.result.md) > [segment](./search-core.result.segment.md) + +## Result.segment property + +A relevant segment associated with the result. Present for document verticals grouped by Segment. + +Signature: + +```typescript +segment?: Segment; +``` diff --git a/docs/search-core.segment.md b/docs/search-core.segment.md new file mode 100644 index 00000000..c8755534 --- /dev/null +++ b/docs/search-core.segment.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [Segment](./search-core.segment.md) + +## Segment interface + +A result produced by a document vertical. + +Signature: + +```typescript +export interface Segment +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [score](./search-core.segment.score.md) | number | The similarity score of the segment from 0 to 1 | +| [text](./search-core.segment.text.md) | string | The value of the segment as plain text. | + diff --git a/docs/search-core.segment.score.md b/docs/search-core.segment.score.md new file mode 100644 index 00000000..52919b8a --- /dev/null +++ b/docs/search-core.segment.score.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [Segment](./search-core.segment.md) > [score](./search-core.segment.score.md) + +## Segment.score property + +The similarity score of the segment from 0 to 1 + +Signature: + +```typescript +score: number; +``` diff --git a/docs/search-core.segment.text.md b/docs/search-core.segment.text.md new file mode 100644 index 00000000..1eab48f6 --- /dev/null +++ b/docs/search-core.segment.text.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@yext/search-core](./search-core.md) > [Segment](./search-core.segment.md) > [text](./search-core.segment.text.md) + +## Segment.text property + +The value of the segment as plain text. + +Signature: + +```typescript +text: string; +``` diff --git a/docs/search-core.source.md b/docs/search-core.source.md index 23a39cf7..6dc1c3cd 100644 --- a/docs/search-core.source.md +++ b/docs/search-core.source.md @@ -19,6 +19,7 @@ export declare enum Source | 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. | | 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. | diff --git a/etc/search-core.api.md b/etc/search-core.api.md index 2d46a534..e0828374 100644 --- a/etc/search-core.api.md +++ b/etc/search-core.api.md @@ -255,6 +255,13 @@ export interface DisplayableFacetOption extends FacetOption { selected: boolean; } +// @public +interface Document_2 { + documentScore: number; + segments: Segment[]; +} +export { Document_2 as Document } + // @public export interface EmailDirectAnswer extends BaseFieldValueDirectAnswer { // (undocumented) @@ -594,6 +601,8 @@ export interface Result> { description?: string; distance?: number; distanceFromFilter?: number; + document?: Document; + documents?: Document[]; entityType?: string; highlightedFields?: HighlightedFields; id?: string; @@ -601,6 +610,7 @@ export interface Result> { link?: string; name?: string; rawData: T; + segment?: Segment; source: Source; } @@ -681,6 +691,12 @@ export interface SearchService { verticalSearch(request: VerticalSearchRequest): Promise; } +// @public +export interface Segment { + score: number; + text: string; +} + // @public export interface ServingConfig { cloudRegion?: CloudRegion; @@ -715,6 +731,7 @@ export enum Source { Algolia = "ALGOLIA", Bing = "BING_CSE", Custom = "CUSTOM_SEARCHER", + DocumentVertical = "DOCUMENT_VERTICAL", Google = "GOOGLE_CSE", KnowledgeManager = "KNOWLEDGE_MANAGER", Zendesk = "ZENDESK" diff --git a/package-lock.json b/package-lock.json index 1f7ce0ed..bd800263 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@yext/search-core", - "version": "2.4.0", + "version": "2.5.0-alpha.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@yext/search-core", - "version": "2.4.0", + "version": "2.5.0-alpha.0", "license": "BSD-3-Clause", "dependencies": { "@babel/runtime-corejs3": "^7.12.5", diff --git a/package.json b/package.json index e3fed112..e5417ac8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@yext/search-core", - "version": "2.4.0", + "version": "2.5.0-alpha.0", "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/index.ts b/src/models/index.ts index 2c095d9c..bdbae09d 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -82,6 +82,8 @@ export { VerticalSearchResponse } from './searchservice/response/VerticalSearchR export { Snippet } from './searchservice/response/Snippet'; export { ErrorType } from './searchservice/response/ErrorType'; export { FailedVertical } from './searchservice/response/FailedVertical'; +export { Segment } from './searchservice/response/Segment'; +export { Document } from './searchservice/response/Document'; // Search service common models export { Matcher } from './searchservice/common/Matcher'; diff --git a/src/models/searchservice/response/Document.ts b/src/models/searchservice/response/Document.ts new file mode 100644 index 00000000..ed7b17b4 --- /dev/null +++ b/src/models/searchservice/response/Document.ts @@ -0,0 +1,13 @@ +import { Segment } from './Segment'; + +/** + * Details about the document and the document search algorithm + * + * @public + */ +export interface Document { + /** The score calculated from whatever document search strategy was used. */ + documentScore: number, + /** All the relevant segments extracted from the document. */ + segments: Segment[] +} \ No newline at end of file diff --git a/src/models/searchservice/response/Result.ts b/src/models/searchservice/response/Result.ts index c7996647..349b44ae 100644 --- a/src/models/searchservice/response/Result.ts +++ b/src/models/searchservice/response/Result.ts @@ -1,5 +1,6 @@ import { HighlightedFields } from './HighlightedFields'; import { Source } from './Source'; +import { Segment } from './Segment'; /** * An individual search result. @@ -39,5 +40,18 @@ export interface Result> { /** The {@link HighlightedFields | highlighted fields} emphasized by the api. */ highlightedFields?: HighlightedFields, /** The entity type of the result. */ - entityType?: string + entityType?: string, + /** A relevant segment associated with the result. Present for document verticals grouped by + * Segment. */ + segment?: Segment, + /** + * A relevant document associated with the result. Present for document verticals grouped by + * Document. + */ + document?: Document, + /** + * All relevant documents associated with the result. Present for document verticals grouped by + * Entity. + */ + documents?: Document[] } \ No newline at end of file diff --git a/src/models/searchservice/response/Segment.ts b/src/models/searchservice/response/Segment.ts new file mode 100644 index 00000000..bc8c5c8a --- /dev/null +++ b/src/models/searchservice/response/Segment.ts @@ -0,0 +1,11 @@ +/** + * A result produced by a document vertical. + * + * @public + */ +export interface Segment { + /** The value of the segment as plain text. */ + text: string, + /** The similarity score of the segment from 0 to 1 */ + score: number +} \ No newline at end of file diff --git a/src/models/searchservice/response/Source.ts b/src/models/searchservice/response/Source.ts index cdd8833f..ddbebe9d 100644 --- a/src/models/searchservice/response/Source.ts +++ b/src/models/searchservice/response/Source.ts @@ -15,5 +15,7 @@ export enum Source { /** The result is from Algolia. */ Algolia = 'ALGOLIA', /** The result was from a custom source. */ - Custom = 'CUSTOM_SEARCHER' + Custom = 'CUSTOM_SEARCHER', + /** The result is from a document vertical. */ + DocumentVertical = 'DOCUMENT_VERTICAL', } \ No newline at end of file diff --git a/src/transformers/searchservice/ResultsFactory.ts b/src/transformers/searchservice/ResultsFactory.ts index c4025336..944e1c4d 100644 --- a/src/transformers/searchservice/ResultsFactory.ts +++ b/src/transformers/searchservice/ResultsFactory.ts @@ -24,6 +24,8 @@ export class ResultsFactory { return this.fromZendeskSearchEngine(result, resultIndex); case Source.Algolia: return this.fromAlgoliaSearchEngine(result, resultIndex); + case Source.DocumentVertical: + return this.fromDocumentVertical(result, resultIndex); default: return this.fromCustomSource(result, resultIndex); } @@ -47,6 +49,22 @@ export class ResultsFactory { }; } + private static fromDocumentVertical(result: any, index: number): Result { + const rawData = result.data ?? result; + return { + rawData: rawData, + source: Source.DocumentVertical, + name: rawData.name, + description: rawData.description, + link: rawData.website, + id: rawData.id, + index: index, + segment: result.segment, + document: result.document, + documents: result.documents + }; + } + private static fromGoogleCustomSearchEngine(result: any, index: number): Result { const rawData = result.data ?? result; return {