feat(search): add disambiguation — largest_pop and ambiguous branches
Multi-row matches within a single govs_type pick the largest-population row (status=largest_pop). Multi-row matches spanning >=2 types return no basket row (status=ambiguous) with all candidates preserved for the sidecar.
This commit is contained in:
+21
-2
@@ -242,8 +242,27 @@ cog_gov_search <- function(name = NULL, state = NULL, type = NULL) {
|
||||
.disambiguate(sub, method = "substring")
|
||||
}
|
||||
|
||||
# Stub for Task 5; raises so any accidental hit during Task 4 is loud.
|
||||
# Disambiguate a multi-row match set. Either picks the largest-pop row
|
||||
# (within single-type) or returns an ambiguous result with no basket row.
|
||||
#' @noRd
|
||||
.disambiguate <- function(matches, method) {
|
||||
cli::cli_abort("internal: .disambiguate() not yet implemented")
|
||||
types <- unique(matches$govs_type)
|
||||
if (length(types) == 1L) {
|
||||
pick <- matches[order(-matches$population_acs, na.last = TRUE), , drop = FALSE][1L, , drop = FALSE]
|
||||
return(list(
|
||||
status = "largest_pop",
|
||||
match_method = method,
|
||||
n_candidates = nrow(matches),
|
||||
row = pick,
|
||||
candidates = matches
|
||||
))
|
||||
}
|
||||
empty <- matches[0, , drop = FALSE]
|
||||
list(
|
||||
status = "ambiguous",
|
||||
match_method = NA_character_,
|
||||
n_candidates = nrow(matches),
|
||||
row = empty,
|
||||
candidates = matches
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user