joined fields and attachments indexing
This commit is contained in:
parent
bdb2efd770
commit
2efe788d96
|
@ -50,30 +50,11 @@ 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('fields', {
|
(builder as any).field('fields', { extractor: (c: CipherView) => this.fieldExtractor(c, false) });
|
||||||
extractor: (c: CipherView) => {
|
(builder as any).field('fields_joined', { extractor: (c: CipherView) => this.fieldExtractor(c, true) });
|
||||||
if (!c.hasFields) {
|
(builder as any).field('attachments', { extractor: (c: CipherView) => this.attachmentExtractor(c, false) });
|
||||||
return null;
|
(builder as any).field('attachments_joined',
|
||||||
}
|
{ extractor: (c: CipherView) => this.attachmentExtractor(c, true) });
|
||||||
const fields = c.fields.filter((f) => f.type === FieldType.Text).map((f) => {
|
|
||||||
let field = '';
|
|
||||||
if (f.name != null) {
|
|
||||||
field += f.name;
|
|
||||||
}
|
|
||||||
if (f.value != null) {
|
|
||||||
if (field !== '') {
|
|
||||||
field += ' ';
|
|
||||||
}
|
|
||||||
field += f.value;
|
|
||||||
}
|
|
||||||
return field;
|
|
||||||
});
|
|
||||||
return fields.filter((f) => f.trim() !== '');
|
|
||||||
},
|
|
||||||
});
|
|
||||||
(builder as any).field('attachments', {
|
|
||||||
extractor: (c: CipherView) => !c.hasAttachments ? null : c.attachments.map((a) => a.fileName),
|
|
||||||
});
|
|
||||||
const ciphers = await this.cipherService.getAllDecrypted();
|
const ciphers = await this.cipherService.getAllDecrypted();
|
||||||
ciphers.forEach((c) => builder.add(c));
|
ciphers.forEach((c) => builder.add(c));
|
||||||
this.index = builder.build();
|
this.index = builder.build();
|
||||||
|
@ -162,4 +143,45 @@ export class SearchService implements SearchServiceAbstraction {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fieldExtractor(c: CipherView, joined: boolean) {
|
||||||
|
if (!c.hasFields) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
let fields: string[] = [];
|
||||||
|
c.fields.forEach((f) => {
|
||||||
|
if (f.name != null) {
|
||||||
|
fields.push(f.name);
|
||||||
|
}
|
||||||
|
if (f.type === FieldType.Text && f.value != null) {
|
||||||
|
fields.push(f.value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fields = fields.filter((f) => f.trim() !== '');
|
||||||
|
if (fields.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return joined ? fields.join(' ') : fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
private attachmentExtractor(c: CipherView, joined: boolean) {
|
||||||
|
if (!c.hasAttachments) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
let attachments: string[] = [];
|
||||||
|
c.attachments.forEach((a) => {
|
||||||
|
if (a != null && a.fileName != null) {
|
||||||
|
if (joined && a.fileName.indexOf('.') > -1) {
|
||||||
|
attachments.push(a.fileName.substr(0, a.fileName.lastIndexOf('.')));
|
||||||
|
} else {
|
||||||
|
attachments.push(a.fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
attachments = attachments.filter((f) => f.trim() !== '');
|
||||||
|
if (attachments.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return joined ? attachments.join(' ') : attachments;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue