mirror of
https://github.com/bitwarden/browser.git
synced 2024-08-26 23:09:46 +02:00
[ps-136] Ignore accented characters in vault search (#804)
* query accented characters now possible * Added accented ignore to other fields * Added pipeline function to remove accented characters * lint fix * Corrected spelling
This commit is contained in:
parent
2f54893854
commit
9a933640dc
|
@ -24,6 +24,8 @@ export class SearchService implements SearchServiceAbstraction {
|
||||||
if (["zh-CN", "zh-TW"].indexOf(i18nService.locale) !== -1) {
|
if (["zh-CN", "zh-TW"].indexOf(i18nService.locale) !== -1) {
|
||||||
this.searchableMinLength = 1;
|
this.searchableMinLength = 1;
|
||||||
}
|
}
|
||||||
|
//register lunr pipeline function
|
||||||
|
lunr.Pipeline.registerFunction(this.normalizeAccentsPipelineFunction, "normalizeAccents");
|
||||||
}
|
}
|
||||||
|
|
||||||
clearIndex(): void {
|
clearIndex(): void {
|
||||||
|
@ -49,9 +51,12 @@ export class SearchService implements SearchServiceAbstraction {
|
||||||
this.indexedEntityId = indexedEntityId;
|
this.indexedEntityId = indexedEntityId;
|
||||||
this.index = null;
|
this.index = null;
|
||||||
const builder = new lunr.Builder();
|
const builder = new lunr.Builder();
|
||||||
|
builder.pipeline.add(this.normalizeAccentsPipelineFunction);
|
||||||
builder.ref("id");
|
builder.ref("id");
|
||||||
builder.field("shortid", { boost: 100, extractor: (c: CipherView) => c.id.substr(0, 8) });
|
builder.field("shortid", { boost: 100, extractor: (c: CipherView) => c.id.substr(0, 8) });
|
||||||
builder.field("name", { boost: 10 });
|
builder.field("name", {
|
||||||
|
boost: 10,
|
||||||
|
});
|
||||||
builder.field("subtitle", {
|
builder.field("subtitle", {
|
||||||
boost: 5,
|
boost: 5,
|
||||||
extractor: (c: CipherView) => {
|
extractor: (c: CipherView) => {
|
||||||
|
@ -281,4 +286,19 @@ export class SearchService implements SearchServiceAbstraction {
|
||||||
});
|
});
|
||||||
return uris.length > 0 ? uris : null;
|
return uris.length > 0 ? uris : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private normalizeAccentsPipelineFunction(token: lunr.Token): any {
|
||||||
|
const searchableFields = ["name", "login.username", "subtitle", "notes"];
|
||||||
|
const fields = (token as any).metadata["fields"];
|
||||||
|
const checkFields = fields.every((i: any) => searchableFields.includes(i));
|
||||||
|
|
||||||
|
if (checkFields) {
|
||||||
|
return token
|
||||||
|
.toString()
|
||||||
|
.normalize("NFD")
|
||||||
|
.replace(/[\u0300-\u036f]/g, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
return token;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user