mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 09:03:02 +00:00
committed by
Rainer Killinger
parent
fe7dd09d7e
commit
5eefa3c2e1
281
test/storage/elasticsearch/aggregations.spec.ts
Normal file
281
test/storage/elasticsearch/aggregations.spec.ts
Normal file
@@ -0,0 +1,281 @@
|
||||
/*
|
||||
* Copyright (C) 2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {SCFacet, SCThingType} from '@openstapps/core';
|
||||
import {expect} from 'chai';
|
||||
import {parseAggregations} from '../../../src/storage/elasticsearch/aggregations';
|
||||
import {AggregationResponse, AggregationSchema} from '../../../src/storage/elasticsearch/common';
|
||||
|
||||
describe('Aggregations', function () {
|
||||
const schema: AggregationSchema = {
|
||||
'@all': {
|
||||
aggs: {
|
||||
type: {
|
||||
terms: {
|
||||
field: 'type.raw',
|
||||
size: 1000
|
||||
}
|
||||
}
|
||||
},
|
||||
filter: {
|
||||
match_all: {}
|
||||
}
|
||||
},
|
||||
'academic event': {
|
||||
aggs: {
|
||||
'academicTerms.acronym': {
|
||||
terms: {
|
||||
field: 'academicTerms.acronym.raw',
|
||||
size: 1000
|
||||
}
|
||||
},
|
||||
'catalogs.categories': {
|
||||
terms: {
|
||||
field: 'catalogs.categories.raw',
|
||||
size: 1000
|
||||
}
|
||||
},
|
||||
categories: {
|
||||
terms: {
|
||||
field: 'categories.raw',
|
||||
size: 1000
|
||||
}
|
||||
},
|
||||
'creativeWorks.keywords': {
|
||||
terms: {
|
||||
field: 'creativeWorks.keywords.raw',
|
||||
size: 1000
|
||||
}
|
||||
},
|
||||
majors: {
|
||||
terms: {
|
||||
field: 'majors.raw',
|
||||
size: 1000
|
||||
}
|
||||
}
|
||||
},
|
||||
filter: {
|
||||
type: {
|
||||
value: 'academic event'
|
||||
}
|
||||
}
|
||||
},
|
||||
catalog: {
|
||||
aggs: {
|
||||
'academicTerm.acronym': {
|
||||
terms: {
|
||||
field: 'academicTerm.acronym.raw',
|
||||
size: 1000
|
||||
}
|
||||
},
|
||||
categories: {
|
||||
terms: {
|
||||
field: 'categories.raw',
|
||||
size: 1000
|
||||
}
|
||||
},
|
||||
'superCatalog.categories': {
|
||||
terms: {
|
||||
field: 'superCatalog.categories.raw',
|
||||
size: 1000
|
||||
}
|
||||
},
|
||||
'superCatalogs.categories': {
|
||||
terms: {
|
||||
field: 'superCatalogs.categories.raw',
|
||||
size: 1000
|
||||
}
|
||||
}
|
||||
},
|
||||
filter: {
|
||||
type: {
|
||||
value: 'catalog'
|
||||
}
|
||||
}
|
||||
},
|
||||
person: {
|
||||
aggs: {
|
||||
'homeLocations.categories': {
|
||||
terms: {
|
||||
field: 'homeLocations.categories.raw',
|
||||
size: 1000
|
||||
}
|
||||
}
|
||||
},
|
||||
filter: {
|
||||
type: {
|
||||
value: 'person'
|
||||
}
|
||||
}
|
||||
},
|
||||
fooType: {
|
||||
terms: {
|
||||
field: 'foo',
|
||||
size: 123,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const aggregations: AggregationResponse = {
|
||||
catalog: {
|
||||
doc_count: 4,
|
||||
'superCatalogs.categories': {
|
||||
buckets: []
|
||||
},
|
||||
'academicTerm.acronym': {
|
||||
buckets: [
|
||||
{
|
||||
key: 'SoSe 2020',
|
||||
doc_count: 2
|
||||
}
|
||||
]
|
||||
},
|
||||
'superCatalog.categories': {
|
||||
buckets: []
|
||||
},
|
||||
categories: {
|
||||
buckets: [
|
||||
{
|
||||
key: 'foo',
|
||||
doc_count: 1,
|
||||
},
|
||||
{
|
||||
key: 'bar',
|
||||
doc_count: 3,
|
||||
},
|
||||
]
|
||||
}
|
||||
},
|
||||
person: {
|
||||
doc_count: 13,
|
||||
'homeLocations.categories': {
|
||||
buckets: []
|
||||
}
|
||||
},
|
||||
'academic event': {
|
||||
doc_count: 0,
|
||||
'academicTerms.acronym': {
|
||||
buckets: []
|
||||
},
|
||||
categories: {
|
||||
buckets: [
|
||||
{
|
||||
key: 'foobar',
|
||||
doc_count: 8,
|
||||
},
|
||||
{
|
||||
key: 'bar',
|
||||
doc_count: 2,
|
||||
},
|
||||
]
|
||||
},
|
||||
'creativeWorks.keywords': {
|
||||
buckets: []
|
||||
}
|
||||
},
|
||||
fooType: {
|
||||
buckets: [
|
||||
{
|
||||
doc_count: 321,
|
||||
key: 'foo'
|
||||
}
|
||||
],
|
||||
},
|
||||
'@all': {
|
||||
doc_count: 17,
|
||||
type: {
|
||||
buckets: [
|
||||
{
|
||||
key: 'person',
|
||||
doc_count: 13
|
||||
},
|
||||
{
|
||||
key: 'catalog',
|
||||
doc_count: 4
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const expectedFacets: SCFacet[] = [
|
||||
{
|
||||
buckets: [
|
||||
{
|
||||
count: 13,
|
||||
'key': 'person'
|
||||
},
|
||||
{
|
||||
count: 4,
|
||||
key: 'catalog'
|
||||
}
|
||||
],
|
||||
field: 'type',
|
||||
},
|
||||
{
|
||||
buckets: [
|
||||
{
|
||||
count: 8,
|
||||
key: 'foobar'
|
||||
},
|
||||
{
|
||||
count: 2,
|
||||
key: 'bar'
|
||||
}
|
||||
],
|
||||
field: 'categories',
|
||||
onlyOnType: SCThingType.AcademicEvent,
|
||||
},
|
||||
{
|
||||
buckets: [
|
||||
{
|
||||
count: 2,
|
||||
key: 'SoSe 2020'
|
||||
}
|
||||
],
|
||||
field: 'academicTerm.acronym',
|
||||
onlyOnType: SCThingType.Catalog
|
||||
},
|
||||
{
|
||||
buckets: [
|
||||
{
|
||||
count: 1,
|
||||
key: 'foo'
|
||||
},
|
||||
{
|
||||
count: 3,
|
||||
key: 'bar'
|
||||
}
|
||||
],
|
||||
field: 'categories',
|
||||
onlyOnType: SCThingType.Catalog,
|
||||
},
|
||||
{
|
||||
buckets: [
|
||||
{
|
||||
count: 321,
|
||||
key: 'foo'
|
||||
}
|
||||
],
|
||||
field: 'fooType'
|
||||
}
|
||||
];
|
||||
|
||||
it('should parse the aggregations providing the appropriate facets', function () {
|
||||
const facets = parseAggregations(schema, aggregations);
|
||||
|
||||
expect(facets).to.be.eql(expectedFacets);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user