Search works with any length of term
This commit is contained in:
parent
b5767a6ad0
commit
810e7c7b5a
1 changed files with 6 additions and 8 deletions
2
index.js
2
index.js
|
@ -26,14 +26,12 @@ module.exports = class Query {
|
|||
this.data = this.data.filter(item => item[key] === term);
|
||||
break;
|
||||
case 'string':
|
||||
if (term.length >= 3) {
|
||||
this.data = this.data.filter(item => {
|
||||
let regFind = new RegExp(term, 'gi');
|
||||
let termMatches = (item[key].match(regFind) || []).length;
|
||||
item.sortScore += termMatches;
|
||||
return termMatches;
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
|
|
Loading…
Add table
Reference in a new issue