feat(search): add relevance-based ranking for campaign and donation s…#160
Merged
BarryArinze merged 2 commits intoJul 23, 2026
Merged
Conversation
…earch - Add weighted relevance scoring via parameterized $queryRaw when sortBy is 'relevance' - Score computed from exact/prefix/contains match tiers across searched fields - Deterministic ordering: score DESC, id ASC tiebreaker - Existing orderBy/pagination path untouched for non-relevance sorts - Add test-environment redis mock so searchCampaigns tests run without a live Redis - Add 8 tests covering path selection, ordering after hydration, pagination params, and regression
DingiDinigi
force-pushed
the
feat/search-relevance-ranking
branch
from
July 23, 2026 00:08
11bba54 to
2f03555
Compare
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #148
Summary
Adds relevance-based ranking for campaign and donation search, while keeping existing pagination, filtering, and non-relevance sort options fully untouched.
Changes
search.service.ts: WhensortBy: 'relevance'is requested,searchCampaigns/searchDonationsroute to newsearchCampaignsByRelevance/searchDonationsByRelevancemethods. These compute a per-field weighted relevance score via a parameterized$queryRawCTE (exact match > prefix match > contains match tiers, weighted per field), order byscore DESC, id ASCfor deterministic results, and paginate withLIMIT/OFFSETin the same query. Ranked ids are then hydrated via a normalfindMany(sameincludeshape as today) and re-sorted in JS to preserve rank order, sinceWHERE id IN (...)doesn't guarantee row order.orderBypath.containspath either).searchCampaigns's existing response cache covers the relevance path automatically (same cache-key strategy, no changes needed there).Testing
count/orderBypath), score-descending/id-tiebreak ordering survives hydration reordering, pagination params (LIMIT/OFFSET) are correctly computed and passed, and non-relevance sorts are unaffected (regression).searchCampaignstests previously hung indefinitely (10s timeout) because the test file didn't mock the Redis-backed cache utility, causingioredisto retry a real connection forever in this sandbox. Added a mock so the cache always misses in tests — this was necessary to actually exercisesearchCampaigns(relevance or otherwise) in this environment, not scope creep.npx tsc --noEmit: zero new type errors.