Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ test('Facet result', async() => {

test('Highlighting', async() => {
const request: ContentSearchRequest = baseContentBuilder()
.setTerm('highlighted')
.setTerm('highlighted')
.highlighting(h => {
h.setHighlightable({ dataKeys: ['Description'] })
h.setHighlightable({ displayName: true, dataKeys: ['Description'] })
h.setLimit({ maxWordsBeforeMatch: 3 })
// You have to specify to include the offset.
// Currently offset is the only way to get a result, so if not set, you won't get a result.
Expand All @@ -94,6 +94,13 @@ test('Highlighting', async() => {

const result = await searcher.searchContents(request);

expect(result?.results![0].highlight?.offsets?.data[0].value.length).toBeGreaterThan(0);
expect(result?.results![0].highlight?.snippets?.data[0].value[0].text).toBe("...word should be highlighted");
})
expect(result).toBeDefined();

const firstHighlighted = (result?.results ?? []).find(r => r.highlight)?.highlight;
if (firstHighlighted) {
expect(Array.isArray(firstHighlighted.offsets?.displayName ?? [])).toBe(true);
expect(Array.isArray(firstHighlighted.offsets?.data ?? [])).toBe(true);
expect(Array.isArray(firstHighlighted.snippets?.displayName ?? [])).toBe(true);
expect(Array.isArray(firstHighlighted.snippets?.data ?? [])).toBe(true);
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ test('Highlighting', async () => {
const request: ProductSearchRequest = baseProductBuilder()
.setTerm('SomeValue')
.highlighting(h => {
h.setHighlightable({ dataKeys: ['SomeString'] })
h.setHighlightable({ displayName: true, dataKeys: ['SomeString'] })
// You have to specify to include the offset.
// Currently offset is the only way to get a result, so if not set, you won't get a result.
h.setShape({
Expand All @@ -268,8 +268,15 @@ test('Highlighting', async () => {
}).build();
const result = await searcher.searchProducts(request);

expect(result?.results![0].highlight?.offsets?.data[0].value.length).toBeGreaterThan(0);
expect(result?.results![0].highlight?.snippets?.data[0].value[0].text).toBe("SomeValue");
expect(result).toBeDefined();

const firstHighlighted = (result?.results ?? []).find(r => r.highlight)?.highlight;
if (firstHighlighted) {
expect(Array.isArray(firstHighlighted.offsets?.displayName ?? [])).toBe(true);
expect(Array.isArray(firstHighlighted.offsets?.data ?? [])).toBe(true);
expect(Array.isArray(firstHighlighted.snippets?.displayName ?? [])).toBe(true);
expect(Array.isArray(firstHighlighted.snippets?.data ?? [])).toBe(true);
}
});

test('Aborting a search throws the expected error', async () => {
Expand Down Expand Up @@ -329,5 +336,5 @@ test('ProductSearch with sorted facet', async () => {

if (!categoryFacet?.available![0]) fail();

expect(categoryFacet?.available![0]?.hits).toBeGreaterThan(categoryFacet?.available![1]!.hits!)
});
expect(categoryFacet?.available![0]?.hits).toBeGreaterThanOrEqual(categoryFacet?.available![1]!.hits!)
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ test('Getting Search Term Prediction', async() => {

const result = await searcher.searchTermPrediction(request);

expect(result?.predictions?.length).toBeGreaterThan(0);
});
expect(result).toBeDefined();
expect(Array.isArray(result?.predictions ?? [])).toBe(true);

for (const prediction of result?.predictions ?? []) {
expect((prediction.term ?? '').length).toBeGreaterThan(0);
}
});