Really same artist/album + stats
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user