Skip to content

Commit

Permalink
Merge pull request #1899 from CSCfi/CSCTTV-4073v4
Browse files Browse the repository at this point in the history
implement project keywords filter
  • Loading branch information
konolak authored Dec 13, 2024
2 parents cd5bc0b + f0d3b72 commit fe7cd89
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 68 deletions.
51 changes: 42 additions & 9 deletions src/app/portal/services/filters/aggregation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1331,16 +1331,49 @@ export class AggregationService {
},
},
},
keywords: {
terms: {
size: 50,
field:
'keywords.keyword.keyword',
},
}
}
}
break;
},
payLoad.aggs.topic = {
nested: {
path: 'keywords',
},
aggs: {
scheme: {
terms: {
field: 'keywords.scheme.keyword',
exclude: ' ',
size: 10,
order: {
_key: 'asc',
},
},
aggs: {
keywords: {
terms: {
field: 'keywords.keyword.keyword',
exclude: ' ',
size: 250,
},
aggs: {
filtered: {
reverse_nested: {},
aggs: {
filterCount: {
filter: {
bool: {
filter: filterActiveNested('keywords'),
},
},
},
},
},
},
},
},
},
},
}
break;

// Datasets
case 'datasets':
Expand Down
23 changes: 13 additions & 10 deletions src/app/portal/services/filters/filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ export class FilterService {
okmDataCollectionFilter: string[];
coPublicationFilter: string[];
sectorFilter: string[];
topicFilter: string[];
topicFilterFundings: string[];
topicFilterProjects: string[];
organizationFilter: string[];
keywordFilter: string[];
keywordFilterPersons: string[];
positionFilter: string[];
dataSourceFilter: string[];
accessTypeFilter: string[];
Expand Down Expand Up @@ -223,7 +224,7 @@ export class FilterService {
// Global
this.yearFilter = this.filterByYear(filter.year);
this.organizationFilter = this.filterByOrganization(filter.organization);
this.keywordFilter = this.filterByKeyword(filter.keyword);
this.keywordFilterPersons = this.filterByPersonsKeyword(filter.keyword);

this.positionFilter = this.filterByPosition(filter.position);

Expand Down Expand Up @@ -285,11 +286,14 @@ export class FilterService {
filter.scheme,
'keywords.scheme.keyword'
);
this.topicFilter = this.basicFilter(
this.topicFilterFundings = this.basicFilter(
filter.topic,
'keywords.keyword.keyword'
);
this.topicFilterProjects = this.basicFilter(
filter.topic,
'keywords.keyword.keyword'
);

// Datasets
this.dataSourceFilter = this.basicFilter(
filter.dataSource,
Expand Down Expand Up @@ -575,7 +579,7 @@ export class FilterService {
return res;
}

private filterByKeyword(filter: string[]) {
private filterByPersonsKeyword(filter: string[]) {
const res = [];
const currentTab = this.tabChangeService.tab;
switch (currentTab) {
Expand All @@ -591,7 +595,6 @@ export class FilterService {
}
}
}

return res;
}

Expand Down Expand Up @@ -925,7 +928,7 @@ export class FilterService {
...basicFilter('publication', this.okmDataCollectionFilter),
...basicFilter('publication', this.coPublicationFilter),
// Persons
...basicFilter('person', this.keywordFilter),
...basicFilter('person', this.keywordFilterPersons),
...nestedFilter('person', this.organizationFilter, 'activity.affiliations.sector.organization'),
...nestedFilter('person', this.positionFilter, 'activity.affiliations'),
// Fundings
Expand Down Expand Up @@ -972,7 +975,7 @@ export class FilterService {
: []),
...basicFilter('funding', this.funderFilter),
...basicFilter('funding', this.typeOfFundingFilter),
...nestedFilter('funding', this.topicFilter, 'keywords'),
...nestedFilter('funding', this.topicFilterFundings, 'keywords'),
...nestedFilter('funding', this.fieldFilter, 'fieldsOfScience'),
...basicFilter('funding', this.fundingSchemeFilter),
...basicFilter('funding', this.statusFilter),
Expand Down Expand Up @@ -1026,7 +1029,7 @@ export class FilterService {
// Projects
...basicFilter('project', this.yearFilter),
...basicFilter('project', this.organizationFilter),

...nestedFilter('project', this.topicFilterProjects, 'keywords'),

// Global filters
...globalFilter(this.yearFilter),
Expand Down
58 changes: 10 additions & 48 deletions src/app/portal/services/filters/project-filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export class ProjectFilterService {
tooltip: $localize`:@@spFiltersOrganizationTooltip:Haun rajaus hankkeeseen osallistuvien organisaatioiden mukaan`,
},
{
field: 'keywords',
field: 'topic',
label: $localize`:@@spFiltersKeywords:Avainsanat`,
hasSubFields: true,
hasSubFields: false,
open: true,
searchFromParent: true,
limitHeight: false,
tooltip: $localize`:@@spFiltersKeywordsTooltip:Haun rajaus hankkeen tiedoissa olevien avainsanojen perusteella`,
},
];
Expand Down Expand Up @@ -77,8 +77,8 @@ export class ProjectFilterService {
item.label = item.organizationName.buckets[0].key.trim();
item.translation = item.organizationName.buckets[0].key.trim();
return item;
}
);
});
source.topic.buckets = this.mapTopic(source.topic.scheme.buckets);
}
source.shaped = true;
return source;
Expand All @@ -89,6 +89,7 @@ export class ProjectFilterService {
clone.map((item) => {
item.key = item.key.toString();
});
console.log('years', clone);
return clone;
}

Expand Down Expand Up @@ -174,68 +175,29 @@ export class ProjectFilterService {
subItem.doc_count = subItem.doc_count;
});
});

return merged;
}

mapTopic(data) {
let mappedData = [];
data.forEach((item) => {
if (item.key !== 'YSA' && item.key !== 'YSO') {
item.subData = item.keywords.buckets.filter(
mappedData = item.keywords.buckets.filter(
(x) => x.filtered.filterCount.doc_count > 0
);

item.subData.map(
mappedData.map(
(x) => (
(x.label = x.key), (x.doc_count = x.filtered.filterCount.doc_count)
)
);

switch (item.key) {
case 'Avainsana': {
item.key = $localize`:@@keywords:Avainsanat`;
item.tooltip = $localize`:@@fkeywordsTooltip:Haun rajaus rahoitusmyönnön tiedoissa olevien avainsanojen perusteella.`;
break;
}
case 'Teema-ala': {
item.key = $localize`:@@FAField:Teemat`;
item.tooltip = $localize`:@@fthemesTooltip:Osa rahoittajista järjestää haut teemojen mukaisesti. Teemat ovat tyypillisesti rahoittajakohtaisia, jolloin hakutuloksessa näkyy vain yhden rahoittajan myöntämiä rahoituksia.`;
break;
}
case 'topic': {
item.key = $localize`:@@identifiedTopic:Tunnistettu aihe`;
item.tooltip = $localize`:@@identifiedTopicsTooltip:Koneoppimisen avulla myönnettyjen rahoitusten tiedoista tutkimustietovarannossa muodostettu aiheluokittelu. Rahoitusmyöntö liittyy aiheeseen, jota se todennäköisimmin käsittelee. Osassa rahoitusmyönnöistä ei ole riittävästi tietoa aiheen päättelyyn.`;
break;
}
case 'Tutkimusala': {
item.key = $localize`:@@FAResearchFields:Suomen Akatemian tutkimusalat`;
item.tooltip = $localize`:@@fresearchFieldTooltip:Suomen Akatemia luokittelee rahoitusmyöntönsä myös oman tutkimusalaluokittelunsa mukaisesti. Valinta kohdistuu vain Akatemian myöntämään rahoitukseen.`;
break;
}
}
}
});

return data;
return mappedData;
}

onGoing(data) {
return data.map(
(item) => (item.key = { key: 'onGoing', doc_count: item.doc_count })
);
}

mapDecisionMaker(data) {
data.map((item) => {
item.label = decisionMakerLabels[item.key] || item.key;
});

return data;
}

getSingleAmount(data) {
if (data.length > 0) {
return data.filter((x) => x.key === 1);
}
}
}
2 changes: 1 addition & 1 deletion src/app/portal/services/static-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ export class StaticDataService {
dataset: ['keywords.keyword'],
infrastructure: ['keywords.keyword'],
organization: [''],
project: ['']
project: ['keywords.keyword']
},
organization: {
publication: [''],
Expand Down

0 comments on commit fe7cd89

Please sign in to comment.