Merge helpers for Meilisearch facetDistribution JSON maps when building disjunctive facet counts.
A single search returns facetDistribution counts on the same document set as hits,
after q and every active filter (including facet refinements). Buckets therefore reflect
conjunctive narrowing — not "OR-group unrefined" distributions from that response alone.
Multi-search is how Meilisearch documents disjunctive facet counts (the engine’s multi-search batching or separate HTTP calls): run a main query,
then auxiliary queries that drop each disjunctive group's refinements for that group's
distribution (often limit: 0), then merge the returned maps. This module only performs
that merge on wire-level maps; it does not call HTTP or assemble auxiliary payloads.
Summary
Types
Outer facet_attribute => inner_distribution map (facetDistribution JSON shape).
Inner value => count map as decoded from Meilisearch JSON (counts are integers).
Functions
Returns a deep copy of main where each outer key to_string(k) from overrides is
replaced (or inserted if missing) by a normalized copy of the inner map overrides[k].
Types
@type facet_distribution_json() :: %{ optional(String.t()) => facet_inner_distribution() }
Outer facet_attribute => inner_distribution map (facetDistribution JSON shape).
@type facet_inner_distribution() :: %{optional(String.t()) => non_neg_integer()}
Inner value => count map as decoded from Meilisearch JSON (counts are integers).
Functions
@spec merge_distributions(facet_distribution_json(), %{ optional(atom() | String.t()) => map() }) :: facet_distribution_json()
Returns a deep copy of main where each outer key to_string(k) from overrides is
replaced (or inserted if missing) by a normalized copy of the inner map overrides[k].
Parameters are wire-level maps (string keys on main), not %Scrypath.SearchResult.Facets{}.
Override keys may be atoms or strings; inner maps use string keys and integer counts as in JSON.