Skip to content

Commit

Permalink
add document vertical support
Browse files Browse the repository at this point in the history
  • Loading branch information
cea2aj committed Sep 27, 2023
1 parent f9371f1 commit 4b688b6
Show file tree
Hide file tree
Showing 21 changed files with 221 additions and 5 deletions.
13 changes: 13 additions & 0 deletions docs/search-core.document_2.documentscore.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/search-core](./search-core.md) &gt; [Document\_2](./search-core.document_2.md) &gt; [documentScore](./search-core.document_2.documentscore.md)

## Document\_2.documentScore property

The score calculated from whatever document search strategy was used.

<b>Signature:</b>

```typescript
documentScore: number;
```
21 changes: 21 additions & 0 deletions docs/search-core.document_2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/search-core](./search-core.md) &gt; [Document\_2](./search-core.document_2.md)

## Document\_2 interface

Details about the document and the document search algorithm

<b>Signature:</b>

```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. |

13 changes: 13 additions & 0 deletions docs/search-core.document_2.segments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/search-core](./search-core.md) &gt; [Document\_2](./search-core.document_2.md) &gt; [segments](./search-core.document_2.segments.md)

## Document\_2.segments property

All the relevant segments extracted from the document.

<b>Signature:</b>

```typescript
segments: Segment[];
```
2 changes: 2 additions & 0 deletions docs/search-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down Expand Up @@ -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. |
Expand Down
13 changes: 13 additions & 0 deletions docs/search-core.result.document.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/search-core](./search-core.md) &gt; [Result](./search-core.result.md) &gt; [document](./search-core.result.document.md)

## Result.document property

A relevant document associated with the result. Present for document verticals grouped by Document.

<b>Signature:</b>

```typescript
document?: Document;
```
13 changes: 13 additions & 0 deletions docs/search-core.result.documents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/search-core](./search-core.md) &gt; [Result](./search-core.result.md) &gt; [documents](./search-core.result.documents.md)

## Result.documents property

All relevant documents associated with the result. Present for document verticals grouped by Entity.

<b>Signature:</b>

```typescript
documents?: Document[];
```
3 changes: 3 additions & 0 deletions docs/search-core.result.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ export interface Result<T = Record<string, unknown>>
| [description?](./search-core.result.description.md) | string | <i>(Optional)</i> A description of the result. |
| [distance?](./search-core.result.distance.md) | number | <i>(Optional)</i> The distance from the user to the result in meters. |
| [distanceFromFilter?](./search-core.result.distancefromfilter.md) | number | <i>(Optional)</i> The distance from a [AppliedQueryFilter](./search-core.appliedqueryfilter.md) location to the result in meters. |
| [document?](./search-core.result.document.md) | Document | <i>(Optional)</i> A relevant document associated with the result. Present for document verticals grouped by Document. |
| [documents?](./search-core.result.documents.md) | Document\[\] | <i>(Optional)</i> All relevant documents associated with the result. Present for document verticals grouped by Entity. |
| [entityType?](./search-core.result.entitytype.md) | string | <i>(Optional)</i> The entity type of the result. |
| [highlightedFields?](./search-core.result.highlightedfields.md) | [HighlightedFields](./search-core.highlightedfields.md) | <i>(Optional)</i> The [highlighted fields](./search-core.highlightedfields.md) emphasized by the api. |
| [id?](./search-core.result.id.md) | string | <i>(Optional)</i> The result ID which depends on the Result Source. |
| [index?](./search-core.result.index.md) | number | <i>(Optional)</i> The index of the result among the other results in the search. |
| [link?](./search-core.result.link.md) | string | <i>(Optional)</i> A hyperlink associated with the result. |
| [name?](./search-core.result.name.md) | string | <i>(Optional)</i> 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) | <i>(Optional)</i> 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)<!-- -->. |

13 changes: 13 additions & 0 deletions docs/search-core.result.segment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/search-core](./search-core.md) &gt; [Result](./search-core.result.md) &gt; [segment](./search-core.result.segment.md)

## Result.segment property

A relevant segment associated with the result. Present for document verticals grouped by Segment.

<b>Signature:</b>

```typescript
segment?: Segment;
```
21 changes: 21 additions & 0 deletions docs/search-core.segment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/search-core](./search-core.md) &gt; [Segment](./search-core.segment.md)

## Segment interface

A result produced by a document vertical.

<b>Signature:</b>

```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. |

13 changes: 13 additions & 0 deletions docs/search-core.segment.score.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/search-core](./search-core.md) &gt; [Segment](./search-core.segment.md) &gt; [score](./search-core.segment.score.md)

## Segment.score property

The similarity score of the segment from 0 to 1

<b>Signature:</b>

```typescript
score: number;
```
13 changes: 13 additions & 0 deletions docs/search-core.segment.text.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/search-core](./search-core.md) &gt; [Segment](./search-core.segment.md) &gt; [text](./search-core.segment.text.md)

## Segment.text property

The value of the segment as plain text.

<b>Signature:</b>

```typescript
text: string;
```
1 change: 1 addition & 0 deletions docs/search-core.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export declare enum Source
| Algolia | <code>&quot;ALGOLIA&quot;</code> | The result is from Algolia. |
| Bing | <code>&quot;BING_CSE&quot;</code> | The result is from Bing Search Engine. |
| Custom | <code>&quot;CUSTOM_SEARCHER&quot;</code> | The result was from a custom source. |
| DocumentVertical | <code>&quot;DOCUMENT_VERTICAL&quot;</code> | The result is from a document vertical. |
| Google | <code>&quot;GOOGLE_CSE&quot;</code> | The result is from Google Custom Search Engine. |
| KnowledgeManager | <code>&quot;KNOWLEDGE_MANAGER&quot;</code> | The result is from a Knowledge Graph. |
| Zendesk | <code>&quot;ZENDESK&quot;</code> | The result is from Zendesk. |
Expand Down
17 changes: 17 additions & 0 deletions etc/search-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]> {
// (undocumented)
Expand Down Expand Up @@ -594,13 +601,16 @@ export interface Result<T = Record<string, unknown>> {
description?: string;
distance?: number;
distanceFromFilter?: number;
document?: Document;
documents?: Document[];
entityType?: string;
highlightedFields?: HighlightedFields;
id?: string;
index?: number;
link?: string;
name?: string;
rawData: T;
segment?: Segment;
source: Source;
}

Expand Down Expand Up @@ -681,6 +691,12 @@ export interface SearchService {
verticalSearch(request: VerticalSearchRequest): Promise<VerticalSearchResponse>;
}

// @public
export interface Segment {
score: number;
text: string;
}

// @public
export interface ServingConfig {
cloudRegion?: CloudRegion;
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
13 changes: 13 additions & 0 deletions src/models/searchservice/response/Document.ts
Original file line number Diff line number Diff line change
@@ -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[]
}
16 changes: 15 additions & 1 deletion src/models/searchservice/response/Result.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HighlightedFields } from './HighlightedFields';
import { Source } from './Source';
import { Segment } from './Segment';

/**
* An individual search result.
Expand Down Expand Up @@ -39,5 +40,18 @@ export interface Result<T = Record<string, unknown>> {
/** 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[]
}
11 changes: 11 additions & 0 deletions src/models/searchservice/response/Segment.ts
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 3 additions & 1 deletion src/models/searchservice/response/Source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
18 changes: 18 additions & 0 deletions src/transformers/searchservice/ResultsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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 {
Expand Down

0 comments on commit 4b688b6

Please sign in to comment.