Line data Source code
1 : // Ceiling of the authored 0-1000 range (workflow_templates docs/SPEC.md).
2 2355 : const SEARCH_RANK_SATURATION = 1000
3 :
4 : // Spans the retired 1-10 scale's demote band; no legacy value flips to promote.
5 2355 : const SEARCH_RANK_DEAD_ZONE = 5
6 :
7 : /**
8 : * Curator intent as a signed strength in [-1, 1]. Unset, non-numeric, and any
9 : * rank within the dead zone are the same neutral baseline — most of the catalog
10 : * ships an explicit `"searchRank": 0` meaning "not curated", so 0 must not
11 : * demote. Promotion starts once the rank exceeds the dead zone and demotion
12 : * once it falls below the negative of it, each saturating at the cap.
13 : */
14 6 : export function searchRankBoost(searchRank: number | undefined): number {
15 6 : if (!searchRank || Math.abs(searchRank) <= SEARCH_RANK_DEAD_ZONE) return 0
16 0 : const magnitude = Math.min(
17 : 1,
18 : Math.log1p(Math.abs(searchRank)) / Math.log1p(SEARCH_RANK_SATURATION)
19 : )
20 0 : return Math.sign(searchRank) * magnitude
21 : }
|