search-client
Version:
Javascript library for executing searches in the Haive search-index via the SearchManager REST interface.
262 lines • 9.76 kB
JavaScript
/**
* The configuration describes how the specific node is to be filtered, sorted, and/or grouped.
* Applied in this order:
* - grouping: Grouping might change all items on this level (introduces an extra layer).
* If an extra group-level is introduced then it will be subject for all
* consecutive processes in this class.
* - filter: Reduces which child-categories that passes through based on filter.
* - sorting: Changes the order of the categories.
* - limit: Limits the no of categories to display.
* - expanded: If any categories are left to be shown then this setting indicates whether or not
* to show the categories in the UI. Note that this is not available for the root-
* level node, as it always shows the first-level of category-nodes.
*
* @default - All features disabled.
*/
var CategoryPresentation = /** @class */ (function () {
/**
* Creates a CategoryPresentation instance. Default: All features disabled.
* @param settings A CategoryPresentation object describing the behavior
*/
function CategoryPresentation(settings) {
settings = settings || {};
this.expanded =
typeof settings.expanded !== 'undefined' ? settings.expanded : null;
this.group = new GroupConfiguration(settings.group);
this.filter = new FilterConfiguration(settings.filter);
this.sort = new SortConfiguration(settings.sort);
this.limit = new LimitPageConfiguration(settings.limit);
}
return CategoryPresentation;
}());
export { CategoryPresentation };
/**
* Defines how grouping is to be applied on a given categories' children
* Can be set to only be executed when the number of child-categories exceeds a given number.
*/
var GroupConfiguration = /** @class */ (function () {
/**
* Creates a GroupingConfiguration instance.
*
* @param settings A GroupingPresentation object describing the behavior.
*/
function GroupConfiguration(settings) {
settings = settings || {};
this.enabled =
typeof settings.enabled !== 'undefined' ? settings.enabled : false;
this.minCount =
typeof settings.minCount !== 'undefined' ? settings.minCount : 20;
this.mode =
typeof settings.mode !== 'undefined'
? settings.mode
: GroupingMode.DisplayName;
this.match =
typeof settings.match !== 'undefined'
? typeof settings.match === 'string'
? new RegExp(settings.match)
: settings.match
: /^./;
this.matchCase =
typeof settings.matchCase !== 'undefined'
? settings.matchCase
: Casing.Title;
this.minCountPerGroup =
typeof settings.minCountPerGroup !== 'undefined'
? settings.minCountPerGroup
: 5;
}
GroupConfiguration.prototype.getMatch = function (input) {
var test = this.match.exec(input);
if (test === null) {
return null;
}
switch (this.matchCase) {
case Casing.Lower:
return test[0].toLowerCase();
case Casing.Upper:
return test[0].toUpperCase();
case Casing.Title:
return (test[0][0].toUpperCase() +
test[0].substring(1).toLowerCase());
case Casing.Unchanged:
default:
return test[0];
}
};
return GroupConfiguration;
}());
export { GroupConfiguration };
export var GroupingMode;
(function (GroupingMode) {
GroupingMode["DisplayName"] = "DisplayName";
GroupingMode["MatchCount"] = "MatchCount";
})(GroupingMode || (GroupingMode = {}));
export var Casing;
(function (Casing) {
Casing["Unchanged"] = "Unchanged";
Casing["Upper"] = "Upper";
Casing["Lower"] = "Lower";
Casing["Title"] = "Title";
})(Casing || (Casing = {}));
/**
* Defines how to filter items.
*/
var FilterConfiguration = /** @class */ (function () {
/**
* Creates a FilterConfiguration instance that describes how to filter categories.
*
* @param settings A FilterConfiguration object describing the behavior
*/
function FilterConfiguration(settings) {
settings = settings || {};
this.enabled =
typeof settings.enabled !== 'undefined' ? settings.enabled : false;
this.match =
typeof settings.match !== 'undefined'
? typeof settings.match === 'string'
? new RegExp(settings.match)
: settings.match
: new RegExp('');
this.matchMode =
typeof settings.matchMode !== 'undefined'
? settings.matchMode
: MatchMode.DisplayName;
this.maxMatchCount =
typeof settings.maxMatchCount !== 'undefined'
? settings.maxMatchCount
: -1; // disabled
this.uiHintShowFilterInputThreshold =
typeof settings.uiHintShowFilterInputThreshold !== 'undefined'
? settings.uiHintShowFilterInputThreshold
: 20;
}
return FilterConfiguration;
}());
export { FilterConfiguration };
export var MatchMode;
(function (MatchMode) {
MatchMode["Name"] = "Name";
MatchMode["DisplayName"] = "DisplayName";
})(MatchMode || (MatchMode = {}));
/**
* Defines how sorting is to be applied.
* First handles the static strings, then applies the SortPartConfigurations until there are no items left.
* Note: If there are additional items left when done above then these will be added at the bottom in the original sorting order.
*/
var SortConfiguration = /** @class */ (function () {
/**
* Creates a sort-configuration that defines how to order the items scoped.
*
* @param settings A SortConfiguration object that describes the wanted behavior
*/
function SortConfiguration(settings) {
settings = settings || {};
this.enabled =
typeof settings.enabled !== 'undefined' ? settings.enabled : false;
this.parts =
typeof settings.parts !== 'undefined'
? this.setupParts(settings.parts)
: [];
}
SortConfiguration.prototype.setupParts = function (parts) {
var ok = [];
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
var s = parts_1[_i];
ok.push(new SortPartConfiguration(s));
}
return ok;
};
return SortConfiguration;
}());
export { SortConfiguration };
/**
* Defines how sorting is to be applied for the given part.
*/
var SortPartConfiguration = /** @class */ (function () {
/**
* Creates a sort-part that defines how to order the items scoped.
*
* @param settings A SortPartConfiguration object that describes the wanted behavior
*/
function SortPartConfiguration(settings) {
settings = settings || {};
this.match =
typeof settings.match !== 'undefined' ? settings.match : /.*/;
this.matchMode =
typeof settings.matchMode !== 'undefined'
? settings.matchMode
: MatchMode.DisplayName;
this.sortMethod =
typeof settings.sortMethod !== 'undefined'
? settings.sortMethod
: SortMethod.Original;
}
return SortPartConfiguration;
}());
export { SortPartConfiguration };
/**
* Defines how to sort the part.
*
*/
export var SortMethod;
(function (SortMethod) {
/**
* Sort in the order received from the server.
*/
SortMethod["Original"] = "Original";
/**
* Sort Ascending by Name/DisplayName field.
*/
SortMethod["AlphaAsc"] = "AlphaAsc";
/**
* Sort Descending by Name/DisplayName field.
*/
SortMethod["AlphaDesc"] = "AlphaDesc";
/**
* Sort Ascending by MatchCount field.
*/
SortMethod["CountAsc"] = "CountAsc";
/**
* Sort Descending by MatchCount field.
*/
SortMethod["CountDesc"] = "CountDesc";
})(SortMethod || (SortMethod = {}));
/**
* Defines paging parameters for controlling which range of items to show.
* Used to limit the number of items to display.
* The regular use-case is to set a pageSize, which acts as the number of items to show.
* The limit is also designed to allow paging, by changing page from 1 and thus allowing
* paging the categories.
*/
var LimitPageConfiguration = /** @class */ (function () {
/**
* Creates a LimitPageConfiguration instance. Default: Show first page, with 5 items.
*
* @param settings A LimitPageConfiguration object that describes the wanted behavior
*/
function LimitPageConfiguration(settings) {
settings = settings || {};
this.enabled =
typeof settings.enabled !== 'undefined' ? settings.enabled : false;
this.page = typeof settings.page !== 'undefined' ? settings.page : 1;
function setPageSizeThrowOnNegative() {
if (settings.pageSize < 0) {
throw new Error('limit pageSize cannot be negative');
}
else {
return settings.pageSize;
}
}
this.pageSize =
typeof settings.pageSize !== 'undefined'
? setPageSizeThrowOnNegative()
: 5;
this.uiHintShowPager =
typeof settings.uiHintShowPager !== 'undefined'
? settings.uiHintShowPager
: true;
}
return LimitPageConfiguration;
}());
export { LimitPageConfiguration };
//# sourceMappingURL=CategoryPresentation.js.map