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
14
index.js
14
index.js
|
@ -26,14 +26,12 @@ module.exports = class Query {
|
||||||
this.data = this.data.filter(item => item[key] === term);
|
this.data = this.data.filter(item => item[key] === term);
|
||||||
break;
|
break;
|
||||||
case 'string':
|
case 'string':
|
||||||
if (term.length >= 3) {
|
this.data = this.data.filter(item => {
|
||||||
this.data = this.data.filter(item => {
|
let regFind = new RegExp(term, 'gi');
|
||||||
let regFind = new RegExp(term, 'gi');
|
let termMatches = (item[key].match(regFind) || []).length;
|
||||||
let termMatches = (item[key].match(regFind) || []).length;
|
item.sortScore += termMatches;
|
||||||
item.sortScore += termMatches;
|
return termMatches;
|
||||||
return termMatches;
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
Loading…
Add table
Reference in a new issue