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
4 changes: 2 additions & 2 deletions packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@relewise/client",
"version": "2.4.0",
"version": "2.5.0-alpha.1",
"description": "Relewise is a next generation personalization SaaS-platform, which offers functionality within product- and content recommendations and personalized search. This official SDK helps you interact with our API.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -32,7 +32,7 @@
"prebuild:types": "rimraf ./build",
"build:types": "tsc -p ./tsconfig.json --outDir build --declaration true && api-extractor run",
"clean": "rimraf ./build ./dist ./docs",
"gen-api": "swagger-typescript-api -p https://api.relewise.com/public/swagger.json -o src/models --modular --no-client --enum-names-as-values && node fix-exports.js",
"gen-api": "swagger-typescript-api -p https://stage01-api.relewise.com/public/swagger.json -o src/models --modular --no-client --enum-names-as-values && node fix-exports.js",
"gen-api-dev": "swagger-typescript-api -p swagger.json -o src/models --modular --no-client --enum-names-as-values && node fix-exports.js",
"publish": "npm run gen-api && npm run build && npm run build:types"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContentHighlightProps, ContentSearchSettingsHighlightSettings, HighlightSettings2ContentContentHighlightPropsHighlightSettings2Limits, HighlightSettings2ContentContentHighlightPropsHighlightSettings2ResponseShape, HighlightSettings2ContentContentHighlightPropsHighlightSettings2TextSnippetsSettings } from '../../models/data-contracts';
import { ContentHighlightProps, ContentSearchSettingsHighlightSettings, HighlightSettings2ContentContentHighlightPropsHighlightSettings2Limits, HighlightSettings2ContentContentHighlightPropsHighlightSettings2ResponseShape } from '../../models/data-contracts';

export class ContentHighlightingBuilder {
private enabledState: boolean = true;
Expand All @@ -7,9 +7,7 @@ export class ContentHighlightingBuilder {
displayName: false
};
private limit: HighlightSettings2ContentContentHighlightPropsHighlightSettings2Limits = {};
private shape: HighlightSettings2ContentContentHighlightPropsHighlightSettings2ResponseShape = {
includeOffsets: false
};
private shape: HighlightSettings2ContentContentHighlightPropsHighlightSettings2ResponseShape = { };

public enabled(enabled: boolean): this {
this.enabledState = enabled;
Expand All @@ -30,9 +28,8 @@ export class ContentHighlightingBuilder {
return this;
}

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

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

export class ProductHighlightingBuilder {
private enabledState: boolean = true;
Expand All @@ -8,7 +8,6 @@ export class ProductHighlightingBuilder {
};
private limit: HighlightSettings2ProductProductHighlightPropsHighlightSettings2Limits = {};
private shape: HighlightSettings2ProductProductHighlightPropsHighlightSettings2ResponseShape = {
includeOffsets: false
};

public enabled(enabled: boolean): this {
Expand All @@ -30,9 +29,8 @@ export class ProductHighlightingBuilder {
return this;
}

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

return this;
}
Expand Down
60 changes: 42 additions & 18 deletions packages/client/src/models/data-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ export type BrandFacet = StringValueFacet;
export type BrandFacetResult = StringBrandNameAndIdResultValueFacetResult;

export type BrandIdFilter = Filter & {
brandIds: string[];
brandIds?: string[] | null;
};

export type BrandIdRelevanceModifier = RelevanceModifier & {
Expand Down Expand Up @@ -2357,8 +2357,22 @@ export interface HighlightResultOffset {
}

export interface HighlightResultSnippet {
displayName: string[];
data: StringStringArrayKeyValuePair[];
displayName: HighlightResultSnippetDisplayNameSnippetMatch[];
data: StringFieldSnippetMatchArrayKeyValuePair[];
}

export type HighlightResultSnippetDisplayNameSnippetMatch = HighlightResultSnippetSnippetMatch;

export type HighlightResultSnippetFieldSnippetMatch = HighlightResultSnippetSnippetMatch;

export interface HighlightResultSnippetMatchMatchedWord {
offset?: Int32Range | null;
}

export interface HighlightResultSnippetSnippetMatch {
$type: string;
text: string;
matchedWords?: HighlightResultSnippetMatchMatchedWord[] | null;
}

export interface HighlightSettings2ContentContentHighlightPropsHighlightSettings2Limits {
Expand All @@ -2378,14 +2392,19 @@ export interface HighlightSettings2ContentContentHighlightPropsHighlightSettings
maxSentencesToIncludeAfterMatch?: number | null;
}

export interface HighlightSettings2ContentContentHighlightPropsHighlightSettings2OffsetSettings {
include: boolean;
}

export interface HighlightSettings2ContentContentHighlightPropsHighlightSettings2ResponseShape {
includeOffsets: boolean;
textSnippets?: HighlightSettings2ContentContentHighlightPropsHighlightSettings2TextSnippetsSettings | null;
offsets?: HighlightSettings2ContentContentHighlightPropsHighlightSettings2OffsetSettings | null;
snippets?: HighlightSettings2ContentContentHighlightPropsHighlightSettings2SnippetsSettings | null;
}

export interface HighlightSettings2ContentContentHighlightPropsHighlightSettings2TextSnippetsSettings {
includeTextSnippets: boolean;
includeEllipses: boolean;
export interface HighlightSettings2ContentContentHighlightPropsHighlightSettings2SnippetsSettings {
include: boolean;
useEllipses: boolean;
includeMatchedWords: boolean;
}

export interface HighlightSettings2ProductProductHighlightPropsHighlightSettings2Limits {
Expand All @@ -2405,14 +2424,19 @@ export interface HighlightSettings2ProductProductHighlightPropsHighlightSettings
maxSentencesToIncludeAfterMatch?: number | null;
}

export interface HighlightSettings2ProductProductHighlightPropsHighlightSettings2OffsetSettings {
include: boolean;
}

export interface HighlightSettings2ProductProductHighlightPropsHighlightSettings2ResponseShape {
includeOffsets: boolean;
textSnippets?: HighlightSettings2ProductProductHighlightPropsHighlightSettings2TextSnippetsSettings | null;
offsets?: HighlightSettings2ProductProductHighlightPropsHighlightSettings2OffsetSettings | null;
snippets?: HighlightSettings2ProductProductHighlightPropsHighlightSettings2SnippetsSettings | null;
}

export interface HighlightSettings2ProductProductHighlightPropsHighlightSettings2TextSnippetsSettings {
includeTextSnippets: boolean;
includeEllipses: boolean;
export interface HighlightSettings2ProductProductHighlightPropsHighlightSettings2SnippetsSettings {
include: boolean;
useEllipses: boolean;
includeMatchedWords: boolean;
}

export type HtmlParser = Parser;
Expand Down Expand Up @@ -5324,6 +5348,11 @@ export interface StringDataObjectValueFacetResult {
field: "Category" | "Assortment" | "ListPrice" | "SalesPrice" | "Brand" | "Data" | "VariantSpecification" | "User";
}

export interface StringFieldSnippetMatchArrayKeyValuePair {
key: string;
value: HighlightResultSnippetFieldSnippetMatch[];
}

export interface StringProductCategoryDataValueFacet {
$type: string;
key: string;
Expand Down Expand Up @@ -5367,11 +5396,6 @@ export interface StringRange1ArrayKeyValuePair {
value: Int32Range[];
}

export interface StringStringArrayKeyValuePair {
key: string;
value: string[];
}

export interface StringStringKeyValuePair {
key: string;
value: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ test('Highlighting', async() => {
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.
h.setShape({ includeOffsets: true, textSnippets: { includeTextSnippets: true, includeEllipses: true } })
h.setShape({
offsets: { include: true },
snippets: { include: true, includeMatchedWords: true, useEllipses: 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");
expect(result?.results![0].highlight?.snippets?.data[0].value[0].text).toBe("...word should be highlighted");
})
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,13 @@ test('Highlighting', async() => {
h.setHighlightable({ 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({ includeOffsets: true, textSnippets: { includeTextSnippets: true, includeEllipses: true } })
h.setShape({
offsets: { include: true },
snippets: { include: true, includeMatchedWords: true, useEllipses: 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("SomeValue");
expect(result?.results![0].highlight?.snippets?.data[0].value[0].text).toBe("SomeValue");
})
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ test('searchHightlighting', () => {
maxSnippetsPerField: 3
});
h.setShape({
includeOffsets: true,
textSnippets: {
includeEllipses: true,
includeTextSnippets: true
}
offsets: { include: true },
snippets: { include: true, includeMatchedWords: true, useEllipses: true }
});
}).build();

Expand All @@ -41,6 +38,6 @@ test('searchHightlighting', () => {
expect(subject.settings?.highlight?.limit.maxEntryLimit).toBe(1);
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);
expect(subject.settings?.highlight?.shape.offsets?.include).toBe(true);
expect(subject.settings?.highlight?.shape.snippets?.include).toBe(true);
});
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,8 @@ test('searchHightlighting', () => {
maxSnippetsPerField: 3
});
h.setShape({
includeOffsets: true,
textSnippets: {
includeEllipses: true,
includeTextSnippets: true,
}
offsets: { include: true },
snippets: { include: true, includeMatchedWords: true, useEllipses: true }
});
}).build();

Expand All @@ -135,8 +132,8 @@ test('searchHightlighting', () => {
expect(subject.settings?.highlight?.limit.maxEntryLimit).toBe(1);
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);
expect(subject.settings?.highlight?.shape.offsets?.include).toBe(true);
expect(subject.settings?.highlight?.shape.snippets?.include).toBe(true);
});

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