Skip to content

Commit eea60c3

Browse files
committed
Feat: add support for search hightlight shape snippet settings
1 parent 7f5e5ea commit eea60c3

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

packages/client/src/builders/search/productHighlightingBuilder.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HighlightSettings2ProductProductHighlightPropsHighlightSettings2Limits, HighlightSettings2ProductProductHighlightPropsHighlightSettings2ResponseShape, ProductHighlightProps, ProductSearchSettingsHighlightSettings } from '../../models/data-contracts';
1+
import { HighlightSettings2ProductProductHighlightPropsHighlightSettings2Limits, HighlightSettings2ProductProductHighlightPropsHighlightSettings2ResponseShape, HighlightSettings2ProductProductHighlightPropsHighlightSettings2TextSnippetsSettings, ProductHighlightProps, ProductSearchSettingsHighlightSettings } from '../../models/data-contracts';
22

33
export class ProductHighlightingBuilder {
44
private enabledState: boolean = true;
@@ -32,8 +32,9 @@ export class ProductHighlightingBuilder {
3232
return this;
3333
}
3434

35-
public setShape(shape: { includeOffsets: boolean }): this {
35+
public setShape(shape: { includeOffsets: boolean, textSnippets?: HighlightSettings2ProductProductHighlightPropsHighlightSettings2TextSnippetsSettings }): this {
3636
this.shape.includeOffsets = shape.includeOffsets;
37+
this.shape.textSnippets = shape.textSnippets;
3738

3839
return this;
3940
}

packages/client/tests/integration-tests/productSearch.integration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ test('Highlighting', async() => {
102102
h.setHighlightable({ dataKeys: ['Description'] })
103103
// You have to specify to include the offset.
104104
// Currently offset is the only way to get a result, so if not set, you won't get a result.
105-
h.setShape({ includeOffsets: true })
105+
h.setShape({ includeOffsets: true, textSnippets: { includeTextSnippets: true } })
106106
}).build();
107-
108107
const result = await searcher.searchProducts(request);
109108

110109
expect(result?.results![0].highlight?.offsets?.data[0].value.length).toBeGreaterThan(0);
110+
expect(result?.results![0].highlight?.snippets?.data[0].value[0]).toBe("...last word is highlighted");
111111
})

packages/client/tests/unit-tests/builders/search/productSearchBuilder.unit.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ test('searchHightlighting', () => {
120120
maxSnippetsPerField: 3
121121
});
122122
h.setShape({
123-
includeOffsets: true
123+
includeOffsets: true,
124+
textSnippets: {
125+
includeTextSnippets: true,
126+
}
124127
});
125128
}).build();
126129

@@ -132,6 +135,7 @@ test('searchHightlighting', () => {
132135
expect(subject.settings?.highlight?.limit.maxSnippetsPerEntry).toBe(2);
133136
expect(subject.settings?.highlight?.limit.maxSnippetsPerField).toBe(3);
134137
expect(subject.settings?.highlight?.shape.includeOffsets).toBe(true);
138+
expect(subject.settings?.highlight?.shape.textSnippets?.includeTextSnippets).toBe(true);
135139
});
136140

137141
test('includeDisabled in ProductHasVariantsFilter', () => {

0 commit comments

Comments
 (0)