# Multi-posting minimum-match queries

Version **0.2.0** adds `eliasfano.threshold_matches(inputs, minimum_matches)` and
`threshold_distinct`; version 0.1.0 does not include them. An identifier
qualifies if it occurs in at least N input lists. `threshold_matches` returns
sorted distinct `ThresholdHit { value, matches }` records; the second API builds
a normal EliasFano result usable with existing queries and binary encoding.

Each list contributes one vote per value even with duplicate runs. Repeated list
arguments are separate predicates, not evidence of independent sources. N=1
gives union semantics, N=input count gives intersection, and intermediate N
supports minimum-should-match search, faceted filters and tag combinations.
This is a static index primitive, not a search engine or probabilistic quorum.

A min-heap holds one cursor per nonempty input. Equal values are grouped and
each cursor skips its own duplicate run. No full decoded copies of inputs or
max-ID-sized bitmap are created. For T consumed positions and K lists, the
heap part costs O(T log K); random access/select costs of EliasFano also remain.
Query working space is O(K+hits), in addition to input indexes; compressed-result
construction adds normal builder/encoding costs. All-empty or too few nonempty
lists return an empty result after request validation.

Default maximums are 64 lists and 1048576 hits; max_lists may not exceed 1024.
Threshold must be 1..input count; negative budgets are invalid. The first hit
beyond max_results raises a resource error instead of silently truncating.
No result limit bounds total input traversal: hosts must also bound their own
input indexes. Maximum UInt64 identifiers require no increment/sentinel trick.

Run `moon run examples/threshold --target wasm-gc`: three predicates, minimum
two matches, duplicate suppression, exact hit counts, compressed AND result,
binary roundtrip and budget refusal. Differential tests check heaps of 1..8
inputs against dense membership counting.

MoonBit 0.10.16 migration explicitly declares derived Eq/Debug extensions and
core debug imports, qualifies blackbox API references, and removes the old
warning suppressions. Mutable containers in readonly indexes/builders are now
private; use existing exported methods. On affected Windows use
`tools/windows/moon.ps1`; it calls official tools with normalized DOS argv paths.
