Get last added album improved

- Take number of month
- Extract method to treat bucket
This commit is contained in:
2017-10-07 11:50:57 +02:00
parent 94e59930ee
commit 331458edbd
2 changed files with 25 additions and 16 deletions

View File

@@ -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) + '...';
}
}); });
} }

View File

@@ -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
} }
} }
}, },