Skip to content

Commit

Permalink
Added support for direct answers to return raw HTML of converted Rich…
Browse files Browse the repository at this point in the history
…Textv2 and markdown in snippets

J=BACK-2241

TEST=manual

Tested using a modified version of the test site in the search-core repository. Also verified that the value field in direct answer snippet contained converted HTML for queries.
  • Loading branch information
saahithjanapati committed Jun 14, 2023
1 parent 1d659de commit fee65a6
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/models/searchservice/response/Snippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
* @public
*/
export interface Snippet {
/** The snippet's body of text */
/** The raw snippet value, or HTML if
* - entity is of type HTML
* - the conversion to HTML is enabled in search configuration
* */
value: string,
/** The locations in the document text of the {@link DirectAnswer.value} */
matchedSubstrings: { offset: number, length: number }[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ export enum BuiltInFieldType {
Integer = 'integer',
SingleLineText = 'single_line_text',
RichText = 'rich_text',
MultiLineText = 'multi_line_text'
MultiLineText = 'multi_line_text',
RichText_v2 = 'rich_text_v2',
Html = 'html',
Markdown = 'markdown'
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface DirectAnswer<T = unknown> {
*
* @remarks
* A value will not be present if the {@link DirectAnswer."type"} is 'FEATURED_SNIPPET'
* and {@link DirectAnswer.fieldType} is 'rich_text'.
* and {@link DirectAnswer.fieldType} is 'rich_text', 'markdown', 'html' or 'rich_text_v2'.
*/
value?: T,
/** The entity associated with the direct answer. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { BuiltInFieldType } from './BuiltInFieldType';
import { EnumOrLiteral } from '../../../utils/EnumOrLiteral';
import {
MultiLineTextSnippetDirectAnswer,
RichTextSnippetDirectAnswer
RichTextSnippetDirectAnswer,
RichTextV2SnippetDirectAnswer,
HTMLSnippetDirectAnswer,
MarkdownSnippetDirectAnswer
} from './featuredsnippetdirectanswers';

/**
Expand All @@ -17,7 +20,12 @@ export interface BaseFeaturedSnippetDirectAnswer<T = unknown> extends DirectAnsw
/** {@inheritDoc DirectAnswerType.FeaturedSnippet} */
type: DirectAnswerType.FeaturedSnippet,
/** {@inheritDoc DirectAnswer.fieldType} */
fieldType: EnumOrLiteral<BuiltInFieldType.MultiLineText | BuiltInFieldType.RichText>,
fieldType: EnumOrLiteral<
BuiltInFieldType.MultiLineText |

Check warning on line 24 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 6

Check warning on line 24 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 6

Check warning on line 24 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / linting / linting

Expected indentation of 2 spaces but found 6

Check warning on line 24 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 6

Check warning on line 24 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 6
BuiltInFieldType.RichText |

Check warning on line 25 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 6

Check warning on line 25 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 6

Check warning on line 25 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / linting / linting

Expected indentation of 2 spaces but found 6

Check warning on line 25 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 6

Check warning on line 25 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 6
BuiltInFieldType.RichText_v2 |

Check warning on line 26 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 6

Check warning on line 26 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 6

Check warning on line 26 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / linting / linting

Expected indentation of 2 spaces but found 6

Check warning on line 26 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 6

Check warning on line 26 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 6
BuiltInFieldType.Html |

Check warning on line 27 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 6

Check warning on line 27 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 6

Check warning on line 27 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / linting / linting

Expected indentation of 2 spaces but found 6

Check warning on line 27 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 6

Check warning on line 27 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 6
BuiltInFieldType.Markdown>,

Check warning on line 28 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 6

Check warning on line 28 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 6

Check warning on line 28 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / linting / linting

Expected indentation of 2 spaces but found 6

Check warning on line 28 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 6

Check warning on line 28 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 6
/** The snippet where the direct answer was found. */
snippet: Snippet
}
Expand All @@ -28,4 +36,8 @@ export interface BaseFeaturedSnippetDirectAnswer<T = unknown> extends DirectAnsw
* @public
*/
export type FeaturedSnippetDirectAnswer =
MultiLineTextSnippetDirectAnswer | RichTextSnippetDirectAnswer;
MultiLineTextSnippetDirectAnswer |
RichTextSnippetDirectAnswer |

Check warning on line 40 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 4

Check warning on line 40 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 4

Check warning on line 40 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / linting / linting

Expected indentation of 2 spaces but found 4

Check warning on line 40 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 4

Check warning on line 40 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 4
RichTextV2SnippetDirectAnswer |

Check warning on line 41 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 4

Check warning on line 41 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 4

Check warning on line 41 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / linting / linting

Expected indentation of 2 spaces but found 4

Check warning on line 41 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 4

Check warning on line 41 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 4
HTMLSnippetDirectAnswer |

Check warning on line 42 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 4

Check warning on line 42 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 4

Check warning on line 42 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / linting / linting

Expected indentation of 2 spaces but found 4

Check warning on line 42 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 4

Check warning on line 42 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 4
MarkdownSnippetDirectAnswer;

Check warning on line 43 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 4

Check warning on line 43 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 4

Check warning on line 43 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / linting / linting

Expected indentation of 2 spaces but found 4

Check warning on line 43 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 4

Check warning on line 43 in src/models/searchservice/response/directanswer/FeaturedSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { EnumOrLiteral } from '../../../../utils/EnumOrLiteral';
import { BuiltInFieldType } from '../BuiltInFieldType';
import { BaseFeaturedSnippetDirectAnswer } from '../FeaturedSnippetDirectAnswer';

/**
* A {@link BaseFeaturedSnippetDirectAnswer} with 'html' field type.
* "value" field is omitted for featured snippet direct answer of this field type.
*
* @public
*/
export interface HTMLSnippetDirectAnswer extends Omit<BaseFeaturedSnippetDirectAnswer<string>, 'value'> {
/** {@inheritDoc DirectAnswer.fieldType} */
fieldType: EnumOrLiteral<BuiltInFieldType.Html>

Check warning on line 13 in src/models/searchservice/response/directanswer/featuredsnippetdirectanswers/HTMLSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 4

Check warning on line 13 in src/models/searchservice/response/directanswer/featuredsnippetdirectanswers/HTMLSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 4

Check warning on line 13 in src/models/searchservice/response/directanswer/featuredsnippetdirectanswers/HTMLSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / linting / linting

Expected indentation of 2 spaces but found 4

Check warning on line 13 in src/models/searchservice/response/directanswer/featuredsnippetdirectanswers/HTMLSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (14.x)

Expected indentation of 2 spaces but found 4

Check warning on line 13 in src/models/searchservice/response/directanswer/featuredsnippetdirectanswers/HTMLSnippetDirectAnswer.ts

View workflow job for this annotation

GitHub Actions / call_run_tests / tests (16.x)

Expected indentation of 2 spaces but found 4
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { EnumOrLiteral } from '../../../../utils/EnumOrLiteral';
import { BuiltInFieldType } from '../BuiltInFieldType';
import { BaseFeaturedSnippetDirectAnswer } from '../FeaturedSnippetDirectAnswer';

/**
* A {@link BaseFeaturedSnippetDirectAnswer} with 'markdown' field type.
* "value" field is omitted for featured snippet direct answer of this field type.
*
* @public
*/
export interface MarkdownSnippetDirectAnswer extends Omit<BaseFeaturedSnippetDirectAnswer<string>, 'value'> {
/** {@inheritDoc DirectAnswer.fieldType} */
fieldType: EnumOrLiteral<BuiltInFieldType.Markdown>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { EnumOrLiteral } from '../../../../utils/EnumOrLiteral';
import { BuiltInFieldType } from '../BuiltInFieldType';
import { BaseFeaturedSnippetDirectAnswer } from '../FeaturedSnippetDirectAnswer';

/**
* A {@link BaseFeaturedSnippetDirectAnswer} with 'rich_text_v2' field type.
* "value" field is omitted for featured snippet direct answer of this field type.
*
* @public
*/
export interface RichTextV2SnippetDirectAnswer extends Omit<BaseFeaturedSnippetDirectAnswer<string>, 'value'> {
/** {@inheritDoc DirectAnswer.fieldType} */
fieldType: EnumOrLiteral<BuiltInFieldType.RichText_v2>
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export { RichTextSnippetDirectAnswer } from './RichTextSnippetDirectAnswer';
export { MultiLineTextSnippetDirectAnswer } from './MultiLineTextSnippetDirectAnswer';
export { RichTextV2SnippetDirectAnswer } from './RichTextV2SnippetDirectAnswer';
export {HTMLSnippetDirectAnswer} from './HTMLSnippetDirectAnswer';
export {MarkdownSnippetDirectAnswer} from './MarkdownSnippetDirectAnswer';
6 changes: 5 additions & 1 deletion src/transformers/searchservice/createDirectAnswer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export function createDirectAnswer(data: any): FeaturedSnippetDirectAnswer | Fie
};
} else if (isFeaturedSnippetDirectAnswer) {
const fieldType = commonDirectAnswerData.fieldType;
if (fieldType != BuiltInFieldType.MultiLineText && fieldType != BuiltInFieldType.RichText) {
if (fieldType != BuiltInFieldType.MultiLineText &&
fieldType != BuiltInFieldType.RichText &&
fieldType != BuiltInFieldType.RichText_v2 &&
fieldType != BuiltInFieldType.Html &&
fieldType != BuiltInFieldType.Markdown) {
throw new Error(`Unexpected fieldType for featured snippet direct answer: ${fieldType}`);
}
return {
Expand Down

0 comments on commit fee65a6

Please sign in to comment.