Skip to content

Commit 288466f

Browse files
authored
feat: Unified highlighting (#206)
The unified highlighter is only supported in elasticsearch 6.0 and later.
1 parent 7150119 commit 288466f

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/core/highlight.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const invalidEncoderParam = invalidParam(
1919
const invalidTypeParam = invalidParam(
2020
ES_REF_URL,
2121
'type',
22-
"'plain', 'postings' or 'fvh'"
22+
"'plain', 'postings', 'unified' or 'fvh'"
2323
);
2424
const invalidFragmenterParam = invalidParam(
2525
ES_REF_URL,
@@ -449,13 +449,16 @@ class Highlight {
449449
* The `unified` highlighter outputs the same highlighting when
450450
* `index_options` is set to `offsets`.
451451
*
452+
* Note: The `unified` highlighter is only supported in elasticsearch 6.0
453+
* and later.
454+
*
452455
* @example
453456
* const highlight = esb.highlight('content').type('plain', 'content');
454457
*
455-
* @param {string} type The allowed values are: `plain`, `postings` and `fvh`.
458+
* @param {string} type The allowed values are: `plain`, `postings`, `unified` and `fvh`.
456459
* @param {string=} field An optional field name
457460
* @returns {Highlight} returns `this` so that calls can be chained
458-
* @throws {Error} Type can be one of `plain`, `postings` or `fvh`.
461+
* @throws {Error} Type can be one of `plain`, `postings`, `unified` or `fvh`.
459462
*/
460463
type(type, field) {
461464
if (isNil(type)) invalidTypeParam(type);
@@ -464,6 +467,7 @@ class Highlight {
464467
if (
465468
typeLower !== 'plain' &&
466469
typeLower !== 'postings' &&
470+
typeLower !== 'unified' &&
467471
typeLower !== 'fvh'
468472
) {
469473
invalidTypeParam(type);

src/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8932,11 +8932,11 @@ declare namespace esb {
89328932
* Note: The `postings` highlighter has been removed in elasticsearch 6.0. The `unified`
89338933
* highlighter outputs the same highlighting when `index_options` is set to `offsets`.
89348934
*
8935-
* @param {string} type The allowed values are: `plain`, `postings` and `fvh`.
8935+
* @param {string} type The allowed values are: `plain`, `postings`, `unified` and `fvh`.
89368936
* @param {string=} field An optional field name
8937-
* @throws {Error} Type can be one of `plain`, `postings` or `fvh`.
8937+
* @throws {Error} Type can be one of `plain`, `postings`, `unified` or `fvh`.
89388938
*/
8939-
type(type: 'plain' | 'postings' | 'fvh', field?: string): this;
8939+
type(type: 'plain' | 'postings' | 'unified' | 'fvh', field?: string): this;
89408940

89418941
/**
89428942
* Forces the highlighting to highlight fields based on the source

test/core-test/highlight.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ test(illegalParamType, new Highlight(), 'fields', 'Array');
106106
test(illegalParamType, new Highlight(), 'highlightQuery', 'Query');
107107
test(illegalParamType, new Highlight(), 'matchedFields', 'Array');
108108
test(validatedCorrectly, highlight, 'encoder', ['default', 'html']);
109-
test(validatedCorrectly, highlight, 'type', ['plain', 'postings', 'fvh']);
109+
test(validatedCorrectly, highlight, 'type', [
110+
'plain',
111+
'postings',
112+
'unified',
113+
'fvh'
114+
]);
110115
test(validatedCorrectly, highlight, 'fragmenter', ['simple', 'span']);
111116
test(setHighlightOption, 'preTags', ['<tag1>', '<tag2>']);
112117
test('sets pre_tags(str) option', setHighlightOption, 'preTags', '<tag1>', [

0 commit comments

Comments
 (0)