Get last added album improved
- Take number of month - Extract method to treat bucket
This commit is contained in:
@@ -61,22 +61,31 @@ export class DashboardComponent implements OnInit {
|
||||
this.elsService.getGenres('asc').subscribe(data => this.bottomGenres = data);
|
||||
// this.elsService.getGenreCount().subscribe(data => console.log(data));
|
||||
|
||||
this.elsService.getLastAddedAlbums().subscribe(buckets => {
|
||||
this.elsService.getLastAddedAlbums(6).subscribe(buckets => {
|
||||
this.lastAddedAlbums = buckets;
|
||||
buckets.forEach(bucket => {
|
||||
this.elsService.getArtistFromAlbumName(bucket.key).subscribe(data => {
|
||||
if (data.length > 1) {
|
||||
data.forEach(album => {
|
||||
if (album['Track Count'] === bucket.doc_count) {
|
||||
console.log(album.Artist.toString());
|
||||
buckets.forEach(bucket => this.getArtistName(bucket));
|
||||
});
|
||||
}
|
||||
|
||||
private getArtistName(albumBucket: Bucket) {
|
||||
// For each bucket.key (album name), search artist.
|
||||
// Use track count to compare
|
||||
this.elsService.getArtistFromAlbumName(albumBucket.key).subscribe(albums => {
|
||||
if (albums.length > 1) {
|
||||
// More than one result for an album name
|
||||
// Search good artist by track count
|
||||
albums.forEach(album => {
|
||||
if (album['Track Count'] === albumBucket.doc_count) {
|
||||
this.albumArtists[album.Name] = album.Artist.toString();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.albumArtists[data[0].Name] = data[0].Artist.toString();
|
||||
// Just one artistresult for album name
|
||||
this.albumArtists[albums[0].Name] = albums[0].Artist.toString();
|
||||
}
|
||||
if (this.albumArtists[albums[0].Name].length > 50) {
|
||||
this.albumArtists[albums[0].Name] = this.albumArtists[albums[0].Name].substring(0, 50) + '...';
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -270,14 +270,14 @@ export class ElsService {
|
||||
.map(res => res.json().aggregations.genres.value);
|
||||
}
|
||||
|
||||
getLastAddedAlbums(): Observable<Bucket[]> {
|
||||
getLastAddedAlbums(month: number): Observable<Bucket[]> {
|
||||
return this.http
|
||||
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
'query': {
|
||||
'range' : {
|
||||
'Date Added' : {
|
||||
'gte' : 'now-6M/d',
|
||||
'gte' : 'now-' + month + 'M/d',
|
||||
'lte' : 'now/d'
|
||||
}
|
||||
}
|
||||
@@ -286,7 +286,7 @@ export class ElsService {
|
||||
'album' : {
|
||||
'terms' : {
|
||||
'field' : 'Album.original',
|
||||
'size': 5
|
||||
'size': 10
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user