Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
QueryEvents,
IBuildingQueryEventArgs,
Initialization,
} from 'coveo-search-ui';
export interface IItemGroupingOptions {
fieldToGroup: string;
fieldForRanking: string;
}
export class ItemGrouping extends Component {
static ID = 'ItemGrouping';
static options: IItemGroupingOptions = {
fieldToGroup: ComponentOptions.buildStringOption({
defaultValue: '@groupid',
}),
fieldForRanking: ComponentOptions.buildStringOption({
defaultValue: '@color'
})
};
constructor(public element: HTMLElement, public options: IItemGroupingOptions, public bindings: IComponentBindings) {
super(element, ItemGrouping.ID, bindings);
this.options = ComponentOptions.initComponentOptions(element, ItemGrouping, options);
this.bind.onRootElement(QueryEvents.buildingQuery, (args: IBuildingQueryEventArgs) => this.handleBuildingQuery(args));
this.bind.onRootElement(QueryEvents.doneBuildingQuery, (args: IBuildingQueryEventArgs) => this.handleDoneBuildingQuery(args));
}
// Define the field to be used for grouping
export interface IItemGroupingOptions {
fieldToGroup: string;
fieldForRanking: string;
}
export class ItemGrouping extends Component {
static ID = 'ItemGrouping';
static options: IItemGroupingOptions = {
fieldToGroup: ComponentOptions.buildStringOption({
defaultValue: '@groupid',
}),
fieldForRanking: ComponentOptions.buildStringOption({
defaultValue: '@color'
})
};
constructor(public element: HTMLElement, public options: IItemGroupingOptions, public bindings: IComponentBindings) {
super(element, ItemGrouping.ID, bindings);
this.options = ComponentOptions.initComponentOptions(element, ItemGrouping, options);
this.bind.onRootElement(QueryEvents.buildingQuery, (args: IBuildingQueryEventArgs) => this.handleBuildingQuery(args));
this.bind.onRootElement(QueryEvents.doneBuildingQuery, (args: IBuildingQueryEventArgs) => this.handleDoneBuildingQuery(args));
}
// Define the field to be used for grouping
private handleBuildingQuery(args: IBuildingQueryEventArgs) {
args.queryBuilder.filterField = this.options.fieldToGroup;
args.queryBuilder.maximumAge = 0;
}