Really same artist/album + stats

This commit is contained in:
2017-05-05 02:52:43 +02:00
parent 9cdd69bfd0
commit c9a55c8217
3 changed files with 94 additions and 5 deletions

View File

@@ -162,6 +162,27 @@ export class ElsService {
});
}
getArtistAlbums(artistName: string): Observable<string[]> {
return this.http
.post(this.elsUrl + "artist/_search",
JSON.stringify({"fields": "Album","query":{"match_phrase":{"Artist":artistName}},"size": ElsService.DEFAULT_SIZE}),
{headers: this.headers})
.map(res => res.json().hits.hits)
.map((hits: Array<any>) => {
// Theorically, my script prevent to found two documents with this query.
// But Prevention is better than cure as Shakespeare said
if (hits.length < 1) {
console.info('No artist "' + artistName + '" found.');
return undefined;
}
if (hits.length > 1) {
console.error('More than one artist "' + artistName + '" found, return the first.');
console.error('This is not normal!')
}
return hits[0].fields.Album;
});
}
private handleError(error: any): Promise<any> {
console.error('An error occurred', error); // for demo purposes only
return Promise.reject(error.message || error);