(front) Improve ToSort using album index
This commit is contained in:
@@ -115,7 +115,7 @@ export class ElsSortService extends ElsService {
|
||||
|
||||
getNbAlbums(): Promise<number> {
|
||||
return this.http
|
||||
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||
.post<any>(this.elsUrl + ElsService.ALBUM_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
'query': {
|
||||
'bool': {
|
||||
@@ -142,9 +142,9 @@ export class ElsSortService extends ElsService {
|
||||
.catch(error => this.handleError(error, 'getNbAlbums()'));
|
||||
}
|
||||
|
||||
getAlbums(): Observable<Bucket[]> {
|
||||
getAlbums(): Observable<Album[]> {
|
||||
return this.http
|
||||
.post(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||
.post(this.elsUrl + ElsService.ALBUM_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
query: {
|
||||
bool: {
|
||||
@@ -157,19 +157,13 @@ export class ElsSortService extends ElsService {
|
||||
]
|
||||
}
|
||||
},
|
||||
'size': 0,
|
||||
'aggs': {
|
||||
'albums' : {
|
||||
'terms': {
|
||||
'field' : 'Album.raw',
|
||||
'order': { '_key': 'asc' },
|
||||
'size': 50
|
||||
}
|
||||
}
|
||||
}
|
||||
'size': 550,
|
||||
"sort": [
|
||||
{ "Play Count": "desc"}
|
||||
]
|
||||
}), {headers: this.headers})
|
||||
.pipe(
|
||||
map(res => this.responseAggregationToBucket(res, "albums")),
|
||||
map(res => this.responseToAlbums(res)),
|
||||
catchError(error => this.handleError(error, 'getAlbums'))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -91,22 +91,22 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let album of toSortAlbum">
|
||||
<tr *ngFor="let album of albums">
|
||||
<td>
|
||||
<a [routerLink]="['/album', album.key]">{{album.key}}</a>
|
||||
<a [routerLink]="['/album', album.Name]">{{album.Name}}</a>
|
||||
</td>
|
||||
|
||||
<td>{{albums[album.key]['Track Count']}}</td>
|
||||
<td>{{album['Track Count']}}</td>
|
||||
|
||||
<ng-template [ngIf]="albums[album.key]['Album Artist']" [ngIfElse]="artistSection">
|
||||
<ng-template [ngIf]="album['Album Artist']" [ngIfElse]="artistSection">
|
||||
<td>
|
||||
<a [routerLink]="['/artist', albums[album.key]['Album Artist']]">{{albums[album.key]['Album Artist']}}</a>
|
||||
<a [routerLink]="['/artist', album['Album Artist']]">{{album['Album Artist']}}</a>
|
||||
</td>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #artistSection>
|
||||
<td>
|
||||
<a [routerLink]="['/artist', albums[album.key].Artist[0]]">{{albums[album.key].Artist}}</a>
|
||||
<a [routerLink]="['/artist', album.Artist[0]]">{{album.Artist}}</a>
|
||||
</td>
|
||||
</ng-template>
|
||||
|
||||
@@ -117,12 +117,12 @@
|
||||
</ng-template>
|
||||
|
||||
<td>
|
||||
{{albums[album.key]['Play Count']}} ({{albums[album.key]['Play Count']/albums[album.key]['Track Count'] | number:'1.0-0'}}/songs)
|
||||
{{album['Play Count']}} ({{album['Play Count']/album['Track Count'] | number:'1.0-0'}}/songs)
|
||||
</td>
|
||||
|
||||
<td class="star" [title]="(albums[album.key]['Album Rating Computed']?'Computed Rating: ':'Rating: ') + albums[album.key]['Album Rating']">
|
||||
<span *ngFor="let item of numberToArray(albums[album.key]['Album Rating'], 20)">
|
||||
<span class="glyphicon" [ngClass]="albums[album.key]['Album Rating Computed']?'glyphicon-star-empty':'glyphicon-star'"></span>
|
||||
<td class="star" [title]="(album['Album Rating Computed']?'Computed Rating: ':'Rating: ') + album['Album Rating']">
|
||||
<span *ngFor="let item of numberToArray(album['Album Rating'], 20)">
|
||||
<span class="glyphicon" [ngClass]="album['Album Rating Computed']?'glyphicon-star-empty':'glyphicon-star'"></span>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ElsSortService } from '../els-sort.service';
|
||||
import { Album } from '../model/album';
|
||||
import { Bucket } from '../model/bucket';
|
||||
import { Song } from '../model/song';
|
||||
|
||||
import { Utils } from '../utils';
|
||||
|
||||
@@ -34,58 +32,7 @@ export class ToSortComponent implements OnInit {
|
||||
this.elsService.getCountNeverListenSong().then(result => this.neverListenSong = result);
|
||||
this.elsService.getNbAlbums().then(result => this.nbAlbums = result);
|
||||
|
||||
// **** GET ALBUMS ****//
|
||||
const tmpToSortAlbums: Bucket[] = [];
|
||||
this.elsService.getAlbums().subscribe(buckets => {
|
||||
buckets.forEach(bucket => {
|
||||
if (tmpToSortAlbums.length === 0) {
|
||||
tmpToSortAlbums.push(bucket);
|
||||
} else {
|
||||
let found = false;
|
||||
tmpToSortAlbums.forEach(element => {
|
||||
if (element.key === bucket.key) {
|
||||
element.doc_count += bucket.doc_count;
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
if (!found) {
|
||||
tmpToSortAlbums.push(bucket);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.toSortAlbum = tmpToSortAlbums;
|
||||
this.toSortAlbum.forEach(bucket => this.getAlbum(bucket));
|
||||
// console.log(this.toSortAlbum)
|
||||
// console.log(this.albums)
|
||||
});
|
||||
}
|
||||
|
||||
private getAlbum(albumBucket: Bucket) {
|
||||
// For each bucket.key (album name), get Album document
|
||||
// Use track count to compare
|
||||
this.elsService.getArtistFromAlbumName(albumBucket.key).subscribe(albums => {
|
||||
// Identification of the good album
|
||||
let goodAlbum;
|
||||
if (albums.length > 1) {
|
||||
// More than one result for an album name: search good by track count
|
||||
albums.forEach(album => {
|
||||
if (album['Track Count'] === albumBucket.doc_count) {
|
||||
goodAlbum = album;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Just one result for album name
|
||||
goodAlbum = albums[0];
|
||||
}
|
||||
|
||||
// TODO Crap security if no good album found
|
||||
if (goodAlbum == undefined) {
|
||||
goodAlbum = albums[0]
|
||||
}
|
||||
|
||||
this.albums[albumBucket.key] = goodAlbum;
|
||||
});
|
||||
this.elsService.getAlbums().subscribe(data => this.albums = data)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user