With a specific ELS Services to query element in a specific folder TODO: Parameterize folder
148 lines
4.2 KiB
TypeScript
148 lines
4.2 KiB
TypeScript
import { HttpClient } from '@angular/common/http';
|
|
import { Injectable } from '@angular/core';
|
|
import { Observable } from 'rxjs';
|
|
import { map, catchError } from 'rxjs/operators';
|
|
import { ElsService } from './els.service';
|
|
import { Album } from './model/album';
|
|
import { Bucket } from './model/bucket';
|
|
import { Song } from './model/song';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class ElsSortService extends ElsService {
|
|
|
|
constructor(protected http: HttpClient) {
|
|
super(http);
|
|
}
|
|
|
|
getTime(): Promise<number> {
|
|
return this.http
|
|
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
|
|
JSON.stringify({
|
|
query: {
|
|
bool: {
|
|
must_not: [
|
|
{
|
|
term: {
|
|
"Location.tree": "/F:/Musique"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
},
|
|
aggs: {
|
|
sum_time: {
|
|
sum: { field: 'Total Time'}
|
|
}
|
|
},
|
|
'size': 0
|
|
}), {headers: this.headers})
|
|
.toPromise()
|
|
.then(res => res.aggregations.sum_time.value as number)
|
|
.catch(error => this.handleError(error, 'getTime()'));
|
|
}
|
|
|
|
getSize(): Promise<number> {
|
|
return this.http
|
|
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
|
|
JSON.stringify({
|
|
query: {
|
|
bool: {
|
|
must_not: [
|
|
{
|
|
term: {
|
|
"Location.tree": "/F:/Musique"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
},
|
|
aggs: {
|
|
sum_time: {
|
|
sum: { field: 'Size' }
|
|
}
|
|
},
|
|
'size': 0
|
|
}), {headers: this.headers})
|
|
.toPromise()
|
|
.then(res => res.aggregations.sum_time.value as number)
|
|
.catch(error => this.handleError(error, 'getSize()'));
|
|
}
|
|
|
|
getCountSong(): Promise<number> {
|
|
return this.http
|
|
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_COUNT,
|
|
JSON.stringify({
|
|
query: {
|
|
bool: {
|
|
must_not: [
|
|
{
|
|
term: {
|
|
"Location.tree": "/F:/Musique"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
}), {headers: this.headers})
|
|
.toPromise()
|
|
.then(res => res.count as number)
|
|
.catch(error => this.handleError(error, 'getCountSong()'));
|
|
}
|
|
|
|
getCountNeverListenSong(): Promise<number> {
|
|
return this.http
|
|
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_COUNT,
|
|
JSON.stringify({
|
|
'query': {
|
|
'bool': {
|
|
'must_not': [
|
|
{
|
|
'exists': { 'field': 'Play Count'}
|
|
}, {
|
|
term: {
|
|
"Location.tree": "/F:/Musique"
|
|
} }
|
|
]
|
|
}
|
|
}
|
|
}), {headers: this.headers})
|
|
.toPromise()
|
|
.then(res => res.count as number)
|
|
.catch(error => this.handleError(error, 'getCountNeverListenSong()'));
|
|
}
|
|
|
|
getAlbums(): Observable<Bucket[]> {
|
|
return this.http
|
|
.post(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
|
|
JSON.stringify({
|
|
query: {
|
|
bool: {
|
|
must_not: [
|
|
{
|
|
term: {
|
|
"Location.tree": "/F:/Musique"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
},
|
|
'size': 0,
|
|
'aggs': {
|
|
'albums' : {
|
|
'terms': {
|
|
'field' : 'Album.raw',
|
|
'order': { '_term': 'asc' },
|
|
'size': 50
|
|
}
|
|
}
|
|
}
|
|
}), {headers: this.headers})
|
|
.pipe(
|
|
map(res => this.responseAggregationToBucket(res, "albums")),
|
|
catchError(error => this.handleError(error, 'getAlbums'))
|
|
);
|
|
}
|
|
}
|