-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from Relewise/feat/highlighting
Feat: Add support for search highlighting
- Loading branch information
Showing
12 changed files
with
312 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/client/src/builders/search/contentHighlightingBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ContentHighlightProps, ContentSearchSettingsHighlightSettings, HighlightSettings2ContentContentHighlightPropsHighlightSettings2Limits, HighlightSettings2ContentContentHighlightPropsHighlightSettings2ResponseShape } from '../../models/data-contracts'; | ||
|
||
export class ContentHighlightingBuilder { | ||
private enabledState: boolean = true; | ||
private highlightable: ContentHighlightProps = { | ||
$type: 'Relewise.Client.Requests.Shared.Highlighting.ContentHighlightProps, Relewise.Client', | ||
displayName: false | ||
}; | ||
private limit: HighlightSettings2ContentContentHighlightPropsHighlightSettings2Limits = {}; | ||
private shape: HighlightSettings2ContentContentHighlightPropsHighlightSettings2ResponseShape = { | ||
includeOffsets: false | ||
}; | ||
|
||
public enabled(enabled: boolean): this { | ||
this.enabledState = enabled; | ||
|
||
return this; | ||
} | ||
|
||
public setHighlightable(highlightable: { displayName?: boolean, dataKeys?: string[] | null }): this { | ||
this.highlightable.displayName = highlightable.displayName ?? false; | ||
this.highlightable.dataKeys = highlightable.dataKeys; | ||
|
||
return this; | ||
} | ||
|
||
public setLimit(limit: { maxEntryLimit?: number | null; maxSnippetsPerEntry?: number | null; maxSnippetsPerField?: number | null; }): this { | ||
this.limit.maxEntryLimit = limit.maxEntryLimit; | ||
this.limit.maxSnippetsPerEntry = limit.maxSnippetsPerEntry; | ||
this.limit.maxSnippetsPerField = limit.maxSnippetsPerField; | ||
|
||
return this; | ||
} | ||
|
||
public setShape(shape: { includeOffsets: boolean }): this { | ||
this.shape.includeOffsets = shape.includeOffsets; | ||
|
||
return this; | ||
} | ||
|
||
public build(): ContentSearchSettingsHighlightSettings { | ||
return { | ||
$type: 'Relewise.Client.Requests.Search.Settings.ContentSearchSettings+HighlightSettings, Relewise.Client', | ||
enabled: this.enabledState, | ||
highlightable: this.highlightable, | ||
limit: this.limit, | ||
shape: this.shape | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/client/src/builders/search/productHighlightingBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { HighlightSettings2ProductProductHighlightPropsHighlightSettings2Limits, HighlightSettings2ProductProductHighlightPropsHighlightSettings2ResponseShape, ProductHighlightProps, ProductSearchSettingsHighlightSettings } from '../../models/data-contracts'; | ||
|
||
export class ProductHighlightingBuilder { | ||
private enabledState: boolean = true; | ||
private highlightable: ProductHighlightProps = { | ||
$type: 'Relewise.Client.Requests.Shared.Highlighting.ProductHighlightProps, Relewise.Client', | ||
displayName: false | ||
}; | ||
private limit: HighlightSettings2ProductProductHighlightPropsHighlightSettings2Limits = {}; | ||
private shape: HighlightSettings2ProductProductHighlightPropsHighlightSettings2ResponseShape = { | ||
includeOffsets: false | ||
}; | ||
|
||
public enabled(enabled: boolean): this { | ||
this.enabledState = enabled; | ||
|
||
return this; | ||
} | ||
|
||
public setHighlightable(highlightable: { displayName?: boolean, dataKeys?: string[] | null }): this { | ||
this.highlightable.displayName = highlightable.displayName ?? false; | ||
this.highlightable.dataKeys = highlightable.dataKeys; | ||
|
||
return this; | ||
} | ||
|
||
public setLimit(limit: { maxEntryLimit?: number | null; maxSnippetsPerEntry?: number | null; maxSnippetsPerField?: number | null; }): this { | ||
this.limit.maxEntryLimit = limit.maxEntryLimit; | ||
this.limit.maxSnippetsPerEntry = limit.maxSnippetsPerEntry; | ||
this.limit.maxSnippetsPerField = limit.maxSnippetsPerField; | ||
|
||
return this; | ||
} | ||
|
||
public setShape(shape: { includeOffsets: boolean }): this { | ||
this.shape.includeOffsets = shape.includeOffsets; | ||
|
||
return this; | ||
} | ||
|
||
public build(): ProductSearchSettingsHighlightSettings { | ||
return { | ||
$type: 'Relewise.Client.Requests.Search.Settings.ProductSearchSettings+HighlightSettings, Relewise.Client', | ||
enabled: this.enabledState, | ||
highlightable: this.highlightable, | ||
limit: this.limit, | ||
shape: this.shape | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.