From f0d3b72505c5440158ff7abf898ef780b8f687d5 Mon Sep 17 00:00:00 2001 From: konolak Date: Fri, 13 Dec 2024 13:11:34 +0200 Subject: [PATCH] implement project keywords filter --- .../services/filters/aggregation.service.ts | 51 +++++++++++++--- .../portal/services/filters/filter.service.ts | 23 ++++---- .../filters/project-filter.service.ts | 58 ++++--------------- .../portal/services/static-data.service.ts | 2 +- 4 files changed, 66 insertions(+), 68 deletions(-) diff --git a/src/app/portal/services/filters/aggregation.service.ts b/src/app/portal/services/filters/aggregation.service.ts index 6b5791a32..845d902a8 100644 --- a/src/app/portal/services/filters/aggregation.service.ts +++ b/src/app/portal/services/filters/aggregation.service.ts @@ -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': diff --git a/src/app/portal/services/filters/filter.service.ts b/src/app/portal/services/filters/filter.service.ts index b25dac797..8704d020a 100644 --- a/src/app/portal/services/filters/filter.service.ts +++ b/src/app/portal/services/filters/filter.service.ts @@ -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[]; @@ -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); @@ -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, @@ -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) { @@ -591,7 +595,6 @@ export class FilterService { } } } - return res; } @@ -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 @@ -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), @@ -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), diff --git a/src/app/portal/services/filters/project-filter.service.ts b/src/app/portal/services/filters/project-filter.service.ts index 5364f6389..25e65a72a 100644 --- a/src/app/portal/services/filters/project-filter.service.ts +++ b/src/app/portal/services/filters/project-filter.service.ts @@ -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`, }, ]; @@ -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; @@ -89,6 +89,7 @@ export class ProjectFilterService { clone.map((item) => { item.key = item.key.toString(); }); + console.log('years', clone); return clone; } @@ -174,49 +175,24 @@ 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) { @@ -224,18 +200,4 @@ export class ProjectFilterService { (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); - } - } } diff --git a/src/app/portal/services/static-data.service.ts b/src/app/portal/services/static-data.service.ts index 37c4965c9..f23920083 100644 --- a/src/app/portal/services/static-data.service.ts +++ b/src/app/portal/services/static-data.service.ts @@ -761,7 +761,7 @@ export class StaticDataService { dataset: ['keywords.keyword'], infrastructure: ['keywords.keyword'], organization: [''], - project: [''] + project: ['keywords.keyword'] }, organization: { publication: [''],