diff --git a/src/App.vue b/src/App.vue index 07bfe41..332c09b 100644 --- a/src/App.vue +++ b/src/App.vue @@ -242,32 +242,7 @@ export default class App extends Vue { } private getSearchItemText(item: Searchable) { - if (item instanceof Package) { - return [ - item.name, - item.description, - item.author, - ].concat(item.keywords); - } - if (item instanceof Crafter) { - return [ - `author:${item.name}`, - `crafter:${item.name}`, - `contributor:${item.name}`, - `collaborator:${item.name}`, - item.name, - item.email, - item.url, - item.initials, - ]; - } - if (item instanceof SearchItem) { - return [ - `#${item.value}`, - `keyword:${item.value}`, - `tag:${item.value}`, - ]; - } + return item.getSearchItemText(); } private isPackage(item: SearchItem | Package | Crafter): boolean { diff --git a/types/Crafter.ts b/types/Crafter.ts index 5408553..319f470 100644 --- a/types/Crafter.ts +++ b/types/Crafter.ts @@ -87,6 +87,26 @@ export default class Crafter implements Searchable { return false; } + public getSearchItemText(): string[] { + const text: string[] = []; + if (this.name) { + text.push( + this.name, + `author:${this.name}`, + `crafter:${this.name}`, + `contributor:${this.name}`, + `collaborator:${this.name}`, + ); + } + text.push( + this.name || '', + this.email || '', + this.url || '', + this.initials || '', + ); + return text; + } + public equals(other: Crafter): boolean { if (this.email && other.email) { return this.email === other.email; diff --git a/types/Package.ts b/types/Package.ts index 276a2dc..1a4a721 100644 --- a/types/Package.ts +++ b/types/Package.ts @@ -115,6 +115,14 @@ export default class Package implements PackageMetaDataDTO, Searchable { return false; } + public getSearchItemText(): string[] { + return [ + this.name || '', + this.description || '', + this.author ? this.author.toString() : '', + ].concat(this.keywords || []); + } + public get crafters(): Crafter[] { if (this.craftersList.length) { return this.craftersList; diff --git a/types/SearchItem.ts b/types/SearchItem.ts index 296555e..40f720d 100644 --- a/types/SearchItem.ts +++ b/types/SearchItem.ts @@ -25,4 +25,12 @@ export class SearchItem implements Searchable { } return false; } + + public getSearchItemText(): string[] { + return [ + `#${this.value}`, + `keyword:${this.value}`, + `tag:${this.value}`, + ]; + } } diff --git a/types/Searchable.ts b/types/Searchable.ts index d8af9b8..c2e89a0 100644 --- a/types/Searchable.ts +++ b/types/Searchable.ts @@ -2,4 +2,5 @@ import Package from './Package'; export default interface Searchable { matches(other: Searchable, packages: Package[]): boolean; + getSearchItemText(): string[]; }