mirror of https://github.com/keeweb/keeweb.git
fix #1022: fuzzy search
This commit is contained in:
parent
3b8e6d7585
commit
a4b9d1e98b
|
@ -175,6 +175,7 @@
|
|||
"searchCase": "Match case",
|
||||
"searchRegex": "RegEx",
|
||||
"searchRank": "Auto",
|
||||
"searchExact": "Exact",
|
||||
|
||||
"openOpen": "Open",
|
||||
"openNew": "New",
|
||||
|
|
|
@ -327,8 +327,22 @@ class AppModel {
|
|||
|
||||
prepareFilter(filter) {
|
||||
filter = { ...filter };
|
||||
|
||||
filter.textLower = filter.text ? filter.text.toLowerCase() : '';
|
||||
filter.textParts = null;
|
||||
filter.textLowerParts = null;
|
||||
|
||||
const exact = filter.advanced && filter.advanced.exact;
|
||||
if (!exact && filter.text) {
|
||||
const textParts = filter.text.split(/\s+/).filter(s => s);
|
||||
if (textParts.length) {
|
||||
filter.textParts = textParts;
|
||||
filter.textLowerParts = filter.textLower.split(/\s+/).filter(s => s);
|
||||
}
|
||||
}
|
||||
|
||||
filter.tagLower = filter.tag ? filter.tag.toLowerCase() : '';
|
||||
|
||||
return filter;
|
||||
}
|
||||
|
||||
|
|
|
@ -195,18 +195,49 @@ class EntryModel extends Model {
|
|||
}
|
||||
|
||||
matches(filter) {
|
||||
return (
|
||||
!filter ||
|
||||
((!filter.tagLower || this.searchTags.indexOf(filter.tagLower) >= 0) &&
|
||||
(!filter.textLower ||
|
||||
(filter.advanced
|
||||
? this.matchesAdv(filter)
|
||||
: this.searchText.indexOf(filter.textLower) >= 0)) &&
|
||||
(!filter.color ||
|
||||
(filter.color === true && this.searchColor) ||
|
||||
this.searchColor === filter.color) &&
|
||||
(!filter.autoType || this.autoTypeEnabled))
|
||||
);
|
||||
if (!filter) {
|
||||
return true;
|
||||
}
|
||||
if (filter.tagLower) {
|
||||
if (this.searchTags.indexOf(filter.tagLower) < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (filter.textLower) {
|
||||
if (filter.advanced) {
|
||||
if (!this.matchesAdv(filter)) {
|
||||
return false;
|
||||
}
|
||||
} else if (filter.textLowerParts) {
|
||||
const parts = filter.textLowerParts;
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
if (this.searchText.indexOf(parts[i]) < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (this.searchText.indexOf(filter.textLower) < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (filter.color) {
|
||||
if (filter.color === true) {
|
||||
if (!this.searchColor) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (this.searchColor !== filter.color) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (filter.autoType) {
|
||||
if (!this.autoTypeEnabled) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
matchesAdv(filter) {
|
||||
|
@ -220,11 +251,21 @@ class EntryModel extends Model {
|
|||
}
|
||||
match = this.matchRegex;
|
||||
} else if (adv.cs) {
|
||||
search = filter.text;
|
||||
match = this.matchString;
|
||||
if (filter.textParts) {
|
||||
search = filter.textParts;
|
||||
match = this.matchStringMulti;
|
||||
} else {
|
||||
search = filter.text;
|
||||
match = this.matchString;
|
||||
}
|
||||
} else {
|
||||
search = filter.textLower;
|
||||
match = this.matchStringLower;
|
||||
if (filter.textLowerParts) {
|
||||
search = filter.textLowerParts;
|
||||
match = this.matchStringLowerMulti;
|
||||
} else {
|
||||
search = filter.textLower;
|
||||
match = this.matchStringLower;
|
||||
}
|
||||
}
|
||||
if (this.matchEntry(this.entry, adv, match, search)) {
|
||||
return true;
|
||||
|
@ -246,6 +287,22 @@ class EntryModel extends Model {
|
|||
return str.indexOf(find) >= 0;
|
||||
}
|
||||
|
||||
matchStringMulti(str, find) {
|
||||
for (let i = 0; i < find.length; i++) {
|
||||
const item = find[i];
|
||||
if (str.isProtected) {
|
||||
if (!str.includes(item)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (str.indexOf(item) < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
matchStringLower(str, findLower) {
|
||||
if (str.isProtected) {
|
||||
return str.includesLower(findLower);
|
||||
|
@ -253,6 +310,23 @@ class EntryModel extends Model {
|
|||
return str.toLowerCase().indexOf(findLower) >= 0;
|
||||
}
|
||||
|
||||
matchStringLowerMulti(str, findLower) {
|
||||
str = str.toLowerCase();
|
||||
for (let i = 0; i < findLower.length; i++) {
|
||||
const item = findLower[i];
|
||||
if (str.isProtected) {
|
||||
if (!str.includesLower(item)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (str.indexOf(item) < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
matchRegex(str, regex) {
|
||||
if (str.isProtected) {
|
||||
str = str.getText();
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
{{#if adv.regex}}checked{{/if}}><label for="list__search-adv-check-regex">{{res 'searchRegex'}}</label></div>
|
||||
<div class="list__search-check"><input type="checkbox" id="list__search-adv-check-history" data-id="history"
|
||||
{{#if adv.history}}checked{{/if}}><label for="list__search-adv-check-history">{{Res 'history'}}</label></div>
|
||||
<div class="list__search-check"><input type="checkbox" id="list__search-adv-check-exact" data-id="exact"
|
||||
{{#if adv.exact}}checked{{/if}}><label for="list__search-adv-check-exact">{{res 'searchExact'}}</label></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
Release notes
|
||||
-------------
|
||||
##### v1.12.0 (TBD)
|
||||
`-` #1022: fuzzy search
|
||||
|
||||
##### v1.11.5 (2019-09-29)
|
||||
`-` fix #1279: error opening files with saved keyfiles
|
||||
|
||||
|
|
Loading…
Reference in New Issue