mirror of
https://github.com/bitwarden/browser
synced 2025-01-29 04:29:32 +01:00
index login.uris_split
This commit is contained in:
parent
aed1c5e927
commit
b64757132f
@ -9,6 +9,8 @@ import { SearchService as SearchServiceAbstraction } from '../abstractions/searc
|
|||||||
import { DeviceType } from '../enums/deviceType';
|
import { DeviceType } from '../enums/deviceType';
|
||||||
import { FieldType } from '../enums/fieldType';
|
import { FieldType } from '../enums/fieldType';
|
||||||
|
|
||||||
|
const IgnoredTlds = ['com', 'net', 'org', 'io', 'co', 'uk', 'au', 'nz', 'fr', 'de', 'eu', 'me', 'jp', 'cn'];
|
||||||
|
|
||||||
export class SearchService implements SearchServiceAbstraction {
|
export class SearchService implements SearchServiceAbstraction {
|
||||||
private indexing = false;
|
private indexing = false;
|
||||||
private index: lunr.Index = null;
|
private index: lunr.Index = null;
|
||||||
@ -50,6 +52,31 @@ export class SearchService implements SearchServiceAbstraction {
|
|||||||
extractor: (c: CipherView) => c.login == null || !c.login.hasUris ? null :
|
extractor: (c: CipherView) => c.login == null || !c.login.hasUris ? null :
|
||||||
c.login.uris.filter((u) => u.hostname != null).map((u) => u.hostname),
|
c.login.uris.filter((u) => u.hostname != null).map((u) => u.hostname),
|
||||||
});
|
});
|
||||||
|
(builder as any).field('login.uris_split', {
|
||||||
|
boost: 2,
|
||||||
|
extractor: (c: CipherView) => {
|
||||||
|
if (c.login == null || !c.login.hasUris) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
let uriParts: string[] = [];
|
||||||
|
c.login.uris.forEach((u) => {
|
||||||
|
if (u.hostname == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const parts = u.hostname.split('.');
|
||||||
|
if (parts.length > 0 && parts.length <= 2) {
|
||||||
|
uriParts.push(parts[0]);
|
||||||
|
} else if (parts.length > 2) {
|
||||||
|
uriParts = uriParts.concat(parts.slice(0, parts.length - 2));
|
||||||
|
const lastBit = parts[parts.length - 2];
|
||||||
|
if (IgnoredTlds.indexOf(lastBit) === -1) {
|
||||||
|
uriParts.push(lastBit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return uriParts.length === 0 ? null : uriParts;
|
||||||
|
},
|
||||||
|
});
|
||||||
(builder as any).field('fields', { extractor: (c: CipherView) => this.fieldExtractor(c, false) });
|
(builder as any).field('fields', { extractor: (c: CipherView) => this.fieldExtractor(c, false) });
|
||||||
(builder as any).field('fields_joined', { extractor: (c: CipherView) => this.fieldExtractor(c, true) });
|
(builder as any).field('fields_joined', { extractor: (c: CipherView) => this.fieldExtractor(c, true) });
|
||||||
(builder as any).field('attachments', { extractor: (c: CipherView) => this.attachmentExtractor(c, false) });
|
(builder as any).field('attachments', { extractor: (c: CipherView) => this.attachmentExtractor(c, false) });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user