|
4 | 4 | dataset, |
5 | 5 | meilisearchClient, |
6 | 6 | } from '../../../__tests__/test.utils' |
| 7 | +import { HIGHLIGHT_PRE_TAG, HIGHLIGHT_POST_TAG } from '../../constants' |
7 | 8 |
|
8 | 9 | beforeAll(async () => { |
9 | 10 | await meilisearchClient.deleteIndex('testUid') |
@@ -49,9 +50,55 @@ describe('fetchMeilisearchResults', () => { |
49 | 50 | }) |
50 | 51 |
|
51 | 52 | expect(results[0].hits[0].id).toEqual(2) |
| 53 | + }) |
| 54 | + |
| 55 | + test('with highlighting metadata', async () => { |
| 56 | + const results = await fetchMeilisearchResults({ |
| 57 | + searchClient, |
| 58 | + queries: [ |
| 59 | + { |
| 60 | + indexName: 'testUid', |
| 61 | + query: 'Hit', |
| 62 | + }, |
| 63 | + ], |
| 64 | + }) |
| 65 | + |
52 | 66 | expect(results[0].hits[0]._highlightResult).toEqual({ |
53 | | - id: { value: '2' }, |
54 | | - label: { value: '<test>Hit</test> 2' }, |
| 67 | + id: { |
| 68 | + value: '1', |
| 69 | + fullyHighlighted: false, |
| 70 | + matchLevel: 'none', |
| 71 | + matchedWords: [], |
| 72 | + }, |
| 73 | + label: { |
| 74 | + value: `${HIGHLIGHT_PRE_TAG}Hit${HIGHLIGHT_POST_TAG} 1`, |
| 75 | + fullyHighlighted: false, |
| 76 | + matchLevel: 'partial', |
| 77 | + matchedWords: ['Hit'], |
| 78 | + }, |
55 | 79 | }) |
56 | 80 | }) |
| 81 | + |
| 82 | + // test('with fully highlighted match', async () => { |
| 83 | + // const results = await fetchMeilisearchResults({ |
| 84 | + // searchClient, |
| 85 | + // queries: [ |
| 86 | + // { |
| 87 | + // indexName: 'testUid', |
| 88 | + // query: 'Hit 2', |
| 89 | + // params: { |
| 90 | + // highlightPreTag: '<test>', |
| 91 | + // highlightPostTag: '</test>', |
| 92 | + // }, |
| 93 | + // }, |
| 94 | + // ], |
| 95 | + // }) |
| 96 | + |
| 97 | + // expect(results[0].hits[0]._highlightResult?.label).toEqual({ |
| 98 | + // value: '<test>Hit</test> <test>2</test>', |
| 99 | + // fullyHighlighted: true, |
| 100 | + // matchLevel: 'full', |
| 101 | + // matchedWords: ['Hit', '2'], |
| 102 | + // }) |
| 103 | + // }) |
57 | 104 | }) |
0 commit comments