Description
Current search only covers campaigns and donations. Extend the search feature to support beneficiaries with advanced filtering, pagination, sorting, faceted search, and optimized query performance.
Background
Beneficiary discovery is currently limited, making it harder for donors, admins, and partners to find people in need by location, profile attributes, or risk/verification status. A richer beneficiary search experience will improve matching, transparency, and platform usability.
Scope
- Add beneficiary search support alongside existing campaign/donation search
- Filter beneficiaries by:
- location: country, city
- needs category
- verification status
- risk score
- age range
- family size
- Add pagination and sorting to beneficiary search results
- Add faceted search metadata for common dimensions
- Optimize search queries with indexes and query tuning
- Ensure API contract is backward-compatible for campaigns/donations
Goals
- Enable search users to discover beneficiaries by both demographic and programmatic attributes
- Provide responsive search with pagination and sorting
- Provide UI-friendly facet metadata for filter counts
- Prevent slow scans by adding appropriate database indexes and query optimizations
Functional requirements
Beneficiary filters
Support search filters for beneficiaries:
location.country
location.city
needsCategory
verificationStatus (e.g. VERIFIED, PENDING, REJECTED)
riskScore range
age range
familySize range
Pagination
- Add
page and limit support
- Return pagination metadata:
total
page
pageSize
totalPages
Sorting
Support sorting by:
- relevance / score
- createdAt
- updatedAt
- riskScore
- age
- familySize
Faceted search
Return facet counts for beneficiary search results, including:
- country
- city
- needs categories
- verification status
- risk score buckets
- age ranges
- family size buckets
Faceted responses should support UI filter panels and drill-down.
Query optimization
- Add indexes on beneficiary search fields:
country, city
needsCategory
verificationStatus
riskScore
age
familySize
- Use query plans or full-text indexes where appropriate
- Avoid N+1 queries and repeated joins
- Ensure faceted aggregation queries are efficient
- Add test coverage to verify performance-sensitive queries
API contract
Extend search endpoints or add beneficiary-specific search routes:
GET /search/beneficiaries or GET /beneficiaries/search
- Query params:
q
country
city
needsCategory
verificationStatus
riskScoreMin
riskScoreMax
ageMin
ageMax
familySizeMin
familySizeMax
page
limit
sortBy
sortOrder
- Response shape:
results: Beneficiary[]
pagination: { total, page, pageSize, totalPages }
facets: { countries, cities, needsCategories, verificationStatuses, riskScoreRanges, ageRanges, familySizeRanges }
Acceptance criteria
Implementation notes
- Add or extend
search.service.ts, search.controller.ts, and route definitions
- Update Prisma schema / DB model indexes if needed
- Add search-specific DTO/validation for beneficiary filter params
- Add unit and integration tests for beneficiary search
- Document new beneficiary search parameters in API.md
Description
Current search only covers campaigns and donations. Extend the search feature to support beneficiaries with advanced filtering, pagination, sorting, faceted search, and optimized query performance.
Background
Beneficiary discovery is currently limited, making it harder for donors, admins, and partners to find people in need by location, profile attributes, or risk/verification status. A richer beneficiary search experience will improve matching, transparency, and platform usability.
Scope
Goals
Functional requirements
Beneficiary filters
Support search filters for beneficiaries:
location.countrylocation.cityneedsCategoryverificationStatus(e.g.VERIFIED,PENDING,REJECTED)riskScorerangeagerangefamilySizerangePagination
pageandlimitsupporttotalpagepageSizetotalPagesSorting
Support sorting by:
Faceted search
Return facet counts for beneficiary search results, including:
Faceted responses should support UI filter panels and drill-down.
Query optimization
country,cityneedsCategoryverificationStatusriskScoreagefamilySizeAPI contract
Extend search endpoints or add beneficiary-specific search routes:
GET /search/beneficiariesorGET /beneficiaries/searchqcountrycityneedsCategoryverificationStatusriskScoreMinriskScoreMaxageMinageMaxfamilySizeMinfamilySizeMaxpagelimitsortBysortOrderresults: Beneficiary[]pagination: { total, page, pageSize, totalPages }facets: { countries, cities, needsCategories, verificationStatuses, riskScoreRanges, ageRanges, familySizeRanges }Acceptance criteria
Implementation notes
search.service.ts,search.controller.ts, and route definitions