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
@@ -1,4 +1,4 @@
import { ContentHighlightProps, ContentSearchSettingsHighlightSettings, HighlightSettings2ContentContentHighlightPropsHighlightSettings2Limits, HighlightSettings2ContentContentHighlightPropsHighlightSettings2ResponseShape } from '../../models/data-contracts';
import { ContentHighlightProps, ContentSearchSettingsHighlightSettings, HighlightSettings2ContentContentHighlightPropsHighlightSettings2Limits, HighlightSettings2ContentContentHighlightPropsHighlightSettings2ResponseShape, HighlightSettings2ContentContentHighlightPropsHighlightSettings2TextSnippetsSettings } from '../../models/data-contracts';

export class ContentHighlightingBuilder {
private enabledState: boolean = true;
Expand Down Expand Up @@ -32,8 +32,9 @@ export class ContentHighlightingBuilder {
return this;
}

public setShape(shape: { includeOffsets: boolean }): this {
public setShape(shape: { includeOffsets: boolean, textSnippets?: HighlightSettings2ContentContentHighlightPropsHighlightSettings2TextSnippetsSettings }): this {
this.shape.includeOffsets = shape.includeOffsets;
this.shape.textSnippets = shape.textSnippets;

return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HighlightSettings2ProductProductHighlightPropsHighlightSettings2Limits, HighlightSettings2ProductProductHighlightPropsHighlightSettings2ResponseShape, ProductHighlightProps, ProductSearchSettingsHighlightSettings } from '../../models/data-contracts';
import { HighlightSettings2ProductProductHighlightPropsHighlightSettings2Limits, HighlightSettings2ProductProductHighlightPropsHighlightSettings2ResponseShape, HighlightSettings2ProductProductHighlightPropsHighlightSettings2TextSnippetsSettings, ProductHighlightProps, ProductSearchSettingsHighlightSettings } from '../../models/data-contracts';

export class ProductHighlightingBuilder {
private enabledState: boolean = true;
Expand Down Expand Up @@ -32,8 +32,9 @@ export class ProductHighlightingBuilder {
return this;
}

public setShape(shape: { includeOffsets: boolean }): this {
public setShape(shape: { includeOffsets: boolean, textSnippets?: HighlightSettings2ProductProductHighlightPropsHighlightSettings2TextSnippetsSettings }): this {
this.shape.includeOffsets = shape.includeOffsets;
this.shape.textSnippets = shape.textSnippets;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect. Do the same for the content highlight builder :)


return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ test('Highlighting', async() => {
h.setHighlightable({ dataKeys: ['Description'] })
// 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({ includeOffsets: true })
h.setShape({ includeOffsets: true, textSnippets: { includeTextSnippets: true } })
}).build();

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]).toBe("...word should be highlighted");
})
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ test('Highlighting', async() => {
h.setHighlightable({ dataKeys: ['Description'] })
// 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({ includeOffsets: true })
h.setShape({ includeOffsets: true, textSnippets: { includeTextSnippets: true } })
}).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]).toBe("...last word is highlighted");
})
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ test('searchHightlighting', () => {
maxSnippetsPerField: 3
});
h.setShape({
includeOffsets: true
includeOffsets: true,
textSnippets: {
includeTextSnippets: true
}
});
}).build();

Expand All @@ -38,4 +41,5 @@ test('searchHightlighting', () => {
expect(subject.settings?.highlight?.limit.maxSnippetsPerEntry).toBe(2);
expect(subject.settings?.highlight?.limit.maxSnippetsPerField).toBe(3);
expect(subject.settings?.highlight?.shape.includeOffsets).toBe(true);
expect(subject.settings?.highlight?.shape.textSnippets?.includeTextSnippets).toBe(true);
});
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ test('searchHightlighting', () => {
maxSnippetsPerField: 3
});
h.setShape({
includeOffsets: true
includeOffsets: true,
textSnippets: {
includeTextSnippets: true,
}
});
}).build();

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

test('includeDisabled in ProductHasVariantsFilter', () => {
Expand Down
Loading