Closed mhp-borisbojic closed 4 years ago
You cannot search booleans. For something like this, you wouldn't need Fuse.js at all. However, if you are indeed interested in fuzzy matching the booleans (i.e, account for typos), you could pre-process the JSON and change all the booleans to their string representation (true
→ "true"
, false
→ "false"
), and use this new JSON when searching.
Hey, thanks for the answer.
I think you didn't get me right, my intention is not to "search" for booleans.
Right now my search looks like this (Vue.js + Vuex Store):
const filteroptions = {
shouldSort: true,
tokenize: true,
findAllMatches: true,
threshold: 0.3,
location: 0,
distance: 20,
maxPatternLength: 64,
minMatchCharLength: 3,
keys: [
'id',
'title',
'tags',
],
};
const data = state.loadedIconsData;
let tempResult;
let result;
// Fuse doesn't support config based search parameters, so we have to use this workaround
if (state.searchFiter.isBrand !== false || state.searchFiter.isVehicle !== false ) {
tempResult = filter(data, { brand: state.searchFiter.isBrand, vehicle: state.searchFiter.isVehicle });
} else {
tempResult = data;
}
if (state.searchFiter.input !== '' && state.searchFiter.input.length > 2) {
const fuse = new Fuse(tempResult, filteroptions);
result = fuse.search(state.searchFiter.input);
} else {
result = tempResult;
}
I'm using Fuse for the real fuzzy search, but need to filter out some elements based on their boolean values (e.g. don't include objects that have brand === false
.
So I wonder if we could at this booleans somehow to Fuse's options, e.g. like this:
const filteroptions = {
shouldSort: true,
tokenize: true,
findAllMatches: true,
threshold: 0.3,
location: 0,
distance: 20,
maxPatternLength: 64,
minMatchCharLength: 3,
keys: [
'id',
'title',
'tags',
],
customLeaveOutSomething = {
brand: true,
public, false
}
};
Consider doing the filtering before, or after, the search; instead of filtering as part of the search. I wouldn't expect Fuse to do both.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
Hi,
I'd like to set some default boolean parameters in the config, I wonder if this is already possible in some way?
My json looks like this:
How can I search for entries that have
cool: true
orclosed: false
? Thanks!