Skip to content

Commit

Permalink
adding support for unified highlight type
Browse files Browse the repository at this point in the history
  • Loading branch information
chrinor2002 committed Dec 4, 2024
1 parent 7150119 commit 90095d2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/core/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const invalidEncoderParam = invalidParam(
const invalidTypeParam = invalidParam(
ES_REF_URL,
'type',
"'plain', 'postings' or 'fvh'"
"'plain', 'postings', 'unified' or 'fvh'"
);
const invalidFragmenterParam = invalidParam(
ES_REF_URL,
Expand Down Expand Up @@ -452,10 +452,10 @@ class Highlight {
* @example
* const highlight = esb.highlight('content').type('plain', 'content');
*
* @param {string} type The allowed values are: `plain`, `postings` and `fvh`.
* @param {string} type The allowed values are: `plain`, `postings`, `unified` and `fvh`.
* @param {string=} field An optional field name
* @returns {Highlight} returns `this` so that calls can be chained
* @throws {Error} Type can be one of `plain`, `postings` or `fvh`.
* @throws {Error} Type can be one of `plain`, `postings`, `unified` or `fvh`.
*/
type(type, field) {
if (isNil(type)) invalidTypeParam(type);
Expand All @@ -464,6 +464,7 @@ class Highlight {
if (
typeLower !== 'plain' &&
typeLower !== 'postings' &&
typeLower !== 'unified' &&
typeLower !== 'fvh'
) {
invalidTypeParam(type);
Expand Down
6 changes: 3 additions & 3 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8932,11 +8932,11 @@ declare namespace esb {
* Note: The `postings` highlighter has been removed in elasticsearch 6.0. The `unified`
* highlighter outputs the same highlighting when `index_options` is set to `offsets`.
*
* @param {string} type The allowed values are: `plain`, `postings` and `fvh`.
* @param {string} type The allowed values are: `plain`, `postings`, `unified` and `fvh`.
* @param {string=} field An optional field name
* @throws {Error} Type can be one of `plain`, `postings` or `fvh`.
* @throws {Error} Type can be one of `plain`, `postings`, `unified` or `fvh`.
*/
type(type: 'plain' | 'postings' | 'fvh', field?: string): this;
type(type: 'plain' | 'postings' | 'unified' | 'fvh', field?: string): this;

/**
* Forces the highlighting to highlight fields based on the source
Expand Down
7 changes: 6 additions & 1 deletion test/core-test/highlight.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ test(illegalParamType, new Highlight(), 'fields', 'Array');
test(illegalParamType, new Highlight(), 'highlightQuery', 'Query');
test(illegalParamType, new Highlight(), 'matchedFields', 'Array');
test(validatedCorrectly, highlight, 'encoder', ['default', 'html']);
test(validatedCorrectly, highlight, 'type', ['plain', 'postings', 'fvh']);
test(validatedCorrectly, highlight, 'type', [
'plain',
'postings',
'unified',
'fvh'
]);
test(validatedCorrectly, highlight, 'fragmenter', ['simple', 'span']);
test(setHighlightOption, 'preTags', ['<tag1>', '<tag2>']);
test('sets pre_tags(str) option', setHighlightOption, 'preTags', '<tag1>', [
Expand Down

0 comments on commit 90095d2

Please sign in to comment.