From cb495fcc94dd641a619cae3c80d741a48a33742d Mon Sep 17 00:00:00 2001 From: Nikolay Akhmetov Date: Tue, 5 Nov 2024 14:26:26 -0500 Subject: [PATCH] NickAkhmetov/CAT-969 Increase homepage counts query specificity (#3593) * CAT-969 Increase homepage counts query specificity * adjust query to still exclude collections without a DOI --- CHANGELOG-cat-969.md | 2 + .../js/components/home/EntityCounts/hooks.ts | 39 ++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 CHANGELOG-cat-969.md diff --git a/CHANGELOG-cat-969.md b/CHANGELOG-cat-969.md new file mode 100644 index 0000000000..08c48e56ef --- /dev/null +++ b/CHANGELOG-cat-969.md @@ -0,0 +1,2 @@ +- Adjust homepage queries to exclude donors/samples without descended datasets. +- Adjust homepage queries to exclude datasets in a non-QA/Published state. diff --git a/context/app/static/js/components/home/EntityCounts/hooks.ts b/context/app/static/js/components/home/EntityCounts/hooks.ts index 32ffd2ec33..46317036a3 100644 --- a/context/app/static/js/components/home/EntityCounts/hooks.ts +++ b/context/app/static/js/components/home/EntityCounts/hooks.ts @@ -5,11 +5,40 @@ const entityCountsQuery: SearchRequest = { size: 0, query: { bool: { - // Only include collections with a DOI in count - should: [ - { bool: { must_not: { term: { 'entity_type.keyword': 'Collection' } } } }, - { bool: { must: [{ exists: { field: 'doi_url' } }, { exists: { field: 'registered_doi' } }] } }, - ], + // Exclude invalid/new datasets from count + // using `must_not` for this allows entities without a mapped status to still be matched + must_not: { + terms: { + 'mapped_status.keyword': ['Invalid', 'Error', 'New', 'Processing', 'Submitted'], + }, + }, + // Nested musts are necessary to form an AND of ORs (i.e. a MUST of SHOULDs) + must: { + bool: { + must: [ + { + // Exclude donors/samples with no associated datasets + bool: { + should: [ + // Either not a donor/sample + { bool: { must_not: { terms: { 'entity_type.keyword': ['Donor', 'Sample'] } } } }, + // or has at least one descended dataset + { bool: { must: { exists: { field: 'descendant_counts.entity_type.Dataset' } } } }, + ], + }, + }, + { + // Only include collections with a DOI in count + bool: { + should: [ + { bool: { must_not: { term: { 'entity_type.keyword': 'Collection' } } } }, + { bool: { must: [{ exists: { field: 'doi_url' } }, { exists: { field: 'registered_doi' } }] } }, + ], + }, + }, + ], + }, + }, }, }, aggs: {