Skip to main content

suggestions

Suggestions​

The suggest function returns suggestions for a specific attribute of a model. The value uses the query find operator to calculate the results. There ar multiple ways to specify what data is relevant to return the suggestions.

const suggestions = dcupl.fn.suggest({
attribute: 'name',
value: '/Shirt/',
});
// will return suggestions for the Regex that matches /Shirt/
// For Example: 'T-Shirt', 'Shirts', 'My Shirt'


const suggestionValue = suggestions[0].value

dcupl.query.execute({
attribute: 'name',
value: `${suggestionValue}`,
operator: 'eq',
});

Relevant Data​

Expecially when working with dcupl Lists it's often usefull to specify what data is relevant for the calculated suggestions. You can can use All Data (all), the currently filtered Dataset (filtered) or specify a specific query/querygroup that is excluded from the Data (excludeQuery) which should give you enough flexibility to complete your task.

list.catalog.fn.suggest({
attribute: 'name',
value: '/Shirt/',
relevantData: 'excludeQuery',
excludeQuery: {
groupKey: 'name', // current behaviour of the dcupl console
},
});

Transform​

You can apply different transformers modify your result set. Transforming the data & search term to lowercase (lowercase), removing whitespaces from the beginning/end (trim) and in also in between (removeWhitespace)

dcupl.fn.suggest({
attribute: 'name',
value: '/Shirt/',
transform: ['lowercase', 'removeWhitespace', 'trim'],
});

Exclusion​

Per default 'null' and 'undefined' values are not returned when calculating suggestions. But you can re-enable them using excludeNulls: false and excludeUndefineds: false

dcupl.fn.suggest({
attribute: 'name',
value: '/Shirt/',
excludeNulls: false,
excludeUndefineds: false,
});

Max Values​

The maximum values calculated can be changed via the max property. Changing this value to a higher number may result in performance issues depending on your dataset.

dcupl.fn.suggest({
attribute: 'name',
value: '/Shirt/',
max: 20,
});

Getting Results in advance​

The calculateResultKeys allows you to control if the suggestions already return the keys of items where the suggestion will match when applied as a query. It's an array of keys you may want to resolve using dcupl.query.many(...). Depending on your data is may be an expensive task to run.

dcupl.fn.suggest({
attribute: 'name',
value: '/Shirt/',
max: 20,
});