Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: add facets parameter to getRecords #421

Merged
merged 1 commit into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions projects/rero/ng-core/src/lib/record/record.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,32 @@ describe('RecordService', () => {
httpMock.verify();
});

it('should return requested aggregations', () => {
const expectedData: Record = {
aggregations: {
authors: {
buckets: [{
doc_count: 2,
key: 'Doe, John'
}]
}
},
hits: {
total: 2
},
links: {}
};

service
.getRecords('documents', '', 1, 10, [{ key: 'author', values: ['John doe'] }], undefined, null, null, ['authors'])
.subscribe((data: Record) => {
expect(data.aggregations.authors.buckets[0].doc_count).toBe(2);
});

const req = httpMock.expectOne(request => request.method === 'GET' && request.url === url + '/');
req.flush(expectedData);
});

it('should get a record detail', () => {
const expectedData: any = {
id: '1',
Expand Down
8 changes: 7 additions & 1 deletion projects/rero/ng-core/src/lib/record/record.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export class RecordService {
* a string or a list of string to filter with multiple values.
* @param headers - HttpHeaders optional http header for the backend call.
* @param sort - parameter for sorting records (eg. 'mostrecent' or '-mostrecent')
* @param facets - list of strings, define which aggregations/facets should be included into the response.
*/
getRecords(
type: string,
Expand All @@ -110,7 +111,8 @@ export class RecordService {
aggregationsFilters: any[] = [],
preFilters: object = {},
headers: any = null,
sort: string = null
sort: string = null,
facets: string[] = []
): Observable<Record | Error> {
// Build query string
let httpParams = new HttpParams().set('q', query);
Expand Down Expand Up @@ -140,6 +142,10 @@ export class RecordService {
}
}

// facets management
// if array `facets` is an empty array, no aggregations data will be included into response.s
httpParams = httpParams.append('facets', facets.join(','));

// http request with headers
return this._http
.get<Record>(this._apiService.getEndpointByType(type, true) + '/', {
Expand Down