mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 22:16:01 +00:00
fuzzy search #246
This commit is contained in:
@@ -4,11 +4,11 @@ DEVMODE=1
|
|||||||
# HIDE_APP_EDITOR=1
|
# HIDE_APP_EDITOR=1
|
||||||
|
|
||||||
|
|
||||||
DEVWEB=1
|
# DEVWEB=1
|
||||||
LOGINS=admin,test
|
# LOGINS=admin,test
|
||||||
|
|
||||||
LOGIN_PASSWORD_admin=admin
|
# LOGIN_PASSWORD_admin=admin
|
||||||
LOGIN_PERMISSIONS_admin=*
|
# LOGIN_PERMISSIONS_admin=*
|
||||||
|
|
||||||
LOGIN_PASSWORD_test=test
|
# LOGIN_PASSWORD_test=test
|
||||||
LOGIN_PERMISSIONS_test=~*, widgets/database
|
# LOGIN_PERMISSIONS_test=~*, widgets/database
|
||||||
|
|||||||
@@ -33,6 +33,27 @@ import _compact from 'lodash/compact';
|
|||||||
// return DoMatch(Filter, value) || camelMatch;
|
// return DoMatch(Filter, value) || camelMatch;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
function fuzzysearch(needle, haystack) {
|
||||||
|
var hlen = haystack.length;
|
||||||
|
var nlen = needle.length;
|
||||||
|
if (nlen > hlen) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (nlen === hlen) {
|
||||||
|
return needle === haystack;
|
||||||
|
}
|
||||||
|
outer: for (var i = 0, j = 0; i < nlen; i++) {
|
||||||
|
var nch = needle.charCodeAt(i);
|
||||||
|
while (j < hlen) {
|
||||||
|
if (haystack.charCodeAt(j++) === nch) {
|
||||||
|
continue outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
export function filterName(filter: string, ...names: string[]) {
|
export function filterName(filter: string, ...names: string[]) {
|
||||||
if (!filter) return true;
|
if (!filter) return true;
|
||||||
|
|
||||||
@@ -42,7 +63,7 @@ export function filterName(filter: string, ...names: string[]) {
|
|||||||
const namesCompacted = _compact(names);
|
const namesCompacted = _compact(names);
|
||||||
for (const token of tokens) {
|
for (const token of tokens) {
|
||||||
const tokenUpper = token.toUpperCase();
|
const tokenUpper = token.toUpperCase();
|
||||||
const found = namesCompacted.find(name => name.toUpperCase().includes(tokenUpper));
|
const found = namesCompacted.find(name => fuzzysearch(tokenUpper, name.toUpperCase()));
|
||||||
if (!found) return false;
|
if (!found) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user