Hi,
I'm working on implementing a dropdown search using ChoiceJS. I've set it up, but the search functionality isn't working as expected; it only returns exact matches. I'll share a screenshot and an advanced format for reference.
{
searchChoices: function(choices) {
return function(term, callback) {
if (term.trim() === '') {
// If the search term is empty, return the original list of choices
callback(choices);
return;
}
// Split the search term into individual words
var searchTerms = term.toLowerCase().split(' ');
var filteredChoices = choices.filter(function(choice) {
// Check if all words in the search term are included in the choice label
return searchTerms.every(function(searchTerm) {
return choice.label.toLowerCase().includes(searchTerm);
});
callback(filteredChoices);
};
},
searchFloor: 0,
searchPlaceholderValue: 'Search Location',
noResultsText: 'Not Found',
searchResultLimit: 4,
placeholder: true,
placeholderValue: null,
searchEnabled: true,
searchFields: ['label'],
renderChoiceLimit: -1,
regexFilter: {
pattern: '^{{query}}$',
flags: 'i'
fuseOptions: {
isCaseSensitive: false,
includeScore: false,
shouldSort: true,
includeMatches: true,
findAllMatches: true,
minMatchCharLength: 1,
location: 0,
threshold: 0.0,
distance: 100,
useExtendedSearch: false,
ignoreLocation: false,
ignoreFieldNorm: false,
fieldNormWeight: 1,
callbackOnInit: null,
Can you try with the config in fuse option like -
threshold: 0.2,
matchAllTokens: true,
tokenize: true ,
includeScore : true,
ignoreLocation : true,
hi thanks for your reply it is working now but what im facing now is if i give some Empty spaces and feed a word it is searching and removing that word is not refreshing the list
Regards bala