fix: correct "All" entry count in filter panels#428
Conversation
1e94a69 to
57f9a50
Compare
pirhoo
left a comment
There was a problem hiding this comment.
Thanks for this! Unfortunately it doesn't work as expected (I tested it manually to confirm my analysis of the code) and the count is now wrong not only for the entities filter, but also for the other filters if they have unloaded buckets pages:
You should focus on overriding the count display only on named entities filters (probably by creating a new FilterTypeEntities component). The test and calculation you made works because you are only testing it with component that actually do aggregation over type:Document and because all their bucket pages are loaded. The tricky part of the entities filter is the fact that the aggregation is done on type:NamedEntites.
| const fromElasticSearch = computed(() => filter?.fromElasticSearch ?? false) | ||
| const bucketsTotal = computed(() => { | ||
| if (!pages.length) return null | ||
| return buckets.value.reduce((sum, b) => sum + b.doc_count, 0) |
There was a problem hiding this comment.
crucial: this is not correct, you're are adding the "doc_count" of each bucket which is not the number of documents but the number of named entities ("doc" means ElasticSearch document here) in each bucket. Although even that value was correct, you cannot use it because it means the total increases when user load the next bucket pages. So you might have the correct number in tests because there is only one bucket page and they are the same number of documents than named entities.
Co-authored-by: Pierre Romera Zhang <hello@pirhoo.com>
fix: correct "All" entry count in filter panels
related to ICIJ/datashare#2019
The "All" entry in filter panels (content type, language, recommended by, starred, etc.) was incorrectly showing
searchStore.total- the global document count - instead of a count meaningful to each filter type.Changes:
FilterType.vue: ComputesbucketsTotalas the sum ofdoc_countacross all loaded aggregation buckets and passes it as:counttoFilterTypeAll. Returnsnullbefore any buckets are fetched (keeps count hidden until data arrives).FilterTypeAll.vue: Replaces thecomputedTotal/searchStorecoupling with acountprop (Number, defaultnull). ThehadTotalguard now uses an immediate watcher oncountto prevent flickering on first render. Each filter type controls its own count semantics.FilterTypeRecommendedBy.vue: Overrides the#allslot to passrecommendedStore.total(sum of all recommendation counts across selected indices) as the "All" count. Uses awaitForso count isnulluntil the fetch resolves, preventing a premature0.FilterTypeStarred.vue: Overrides the#allslot to pass the real document total fromgetTotal()as the "All" count. UseswaitForfor flicker-prevention reason. Also fixes a copy-paste bug where the "Not starred" entry hadname="starred". Exposesfetchfor testability.AI disclaimer
Used to write the description more cleanly
use agent to do first draft of unit test (TDD like)