Skip to content

Commit

Permalink
Add matchedSubstrings to spellCheck interface (#192)
Browse files Browse the repository at this point in the history
Raiden needs access](https://yext.slack.com/archives/C03NQ9X8ACB/p1658505872261039) to `matchedSubstrings` from the spellCheck part of the Search API response.  Since changing `correctedQuery` from a string to an object would be a breaking change, we added a new property to the spellCheck interface that holds the `matchedSubstrings`.  `matchedSubstrings` was also added to the Core response when the spellCheck object is created in `createSpellCheck`.

J=SLAP-2274
TEST=manual

It was verified that when spellCheck was provided in the Core response, that `matchedSubstrings` was also provided as its own property.
  • Loading branch information
alextaing committed Jul 26, 2022
1 parent 3ac945e commit 40504f4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
16 changes: 16 additions & 0 deletions docs/search-core.spellcheck.matchedsubstrings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/search-core](./search-core.md) &gt; [SpellCheck](./search-core.spellcheck.md) &gt; [matchedSubstrings](./search-core.spellcheck.matchedsubstrings.md)

## SpellCheck.matchedSubstrings property

An array of substring matches which correspond to the highlighting. Offset indicates the index of the match, and the length indicates the number of characters of the match.

<b>Signature:</b>

```typescript
matchedSubstrings: {
length: number;
offset: number;
}[];
```
1 change: 1 addition & 0 deletions docs/search-core.spellcheck.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface SpellCheck
| Property | Type | Description |
| --- | --- | --- |
| [correctedQuery](./search-core.spellcheck.correctedquery.md) | string | The corrected version of the originalQuery. |
| [matchedSubstrings](./search-core.spellcheck.matchedsubstrings.md) | { length: number; offset: number; }\[\] | An array of substring matches which correspond to the highlighting. Offset indicates the index of the match, and the length indicates the number of characters of the match. |
| [originalQuery](./search-core.spellcheck.originalquery.md) | string | The query that was input into the spell checker. |
| [type](./search-core.spellcheck.type.md) | [SpellCheckType](./search-core.spellchecktype.md) | The type of spell check. |

4 changes: 4 additions & 0 deletions etc/search-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ export enum Source {
// @public
export interface SpellCheck {
correctedQuery: string;
matchedSubstrings: {
length: number;
offset: number;
}[];
originalQuery: string;
type: SpellCheckType;
}
Expand Down
10 changes: 9 additions & 1 deletion src/models/searchservice/response/SpellCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ export interface SpellCheck {
/** The corrected version of the originalQuery. */
correctedQuery: string,
/** The type of spell check. */
type: SpellCheckType
type: SpellCheckType,
/**
* An array of substring matches which correspond to the highlighting.
* Offset indicates the index of the match, and the length indicates the number of characters of the match.
*/
matchedSubstrings: {
length: number,
offset: number
}[]
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/transformers/searchservice/createSpellCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export function createSpellCheck(data: any): SpellCheck {
originalQuery: data.originalQuery,
correctedQuery: data.correctedQuery.value,
type: data.type,
matchedSubstrings: data.correctedQuery.matchedSubstrings
};
}

0 comments on commit 40504f4

Please sign in to comment.