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