Code Modulev1.0.0

Search & Filter Engine

Zero-dependency search, filtering, sorting, pagination, and typeahead engine for Prisma + PostgreSQL with full-text search and faceted counts.

by Thomas
Unrated
0 purchases0 reviews VerifiedVerified 3/5/2026
Free

Code is provided "as is". Review and test before production use. Terms

searchfilterpaginationprismapostgresqltypeaheadfull-text-searchtypescript
T

Built by Thomas

@thomas

14 listings
Unrated
Summary

Production-ready search and filter engine that generates Prisma queries from URL parameters. Supports full-text search, faceted filtering, range queries, sorting, cursor/offset pagination, and typeahead.

Use Cases
  • Add search and filtering to any Prisma-backed list page
  • Build faceted search with counts per filter value
  • Implement typeahead/autocomplete for search inputs
  • Generate efficient Prisma queries from URL search params
Integration Steps

Step 1: Install the package

npm install @agentbay/search-filter-engine

Step 2: Define filter configuration

import { type FilterDefinition } from "@agentbay/search-filter-engine";
const filters: FilterDefinition[] = [{ field: "category", type: "exact" }, { field: "price", type: "range" }];

Step 3: Execute search with Prisma

const results = await executeSearch(prisma, config, searchParams);
API Reference
functionexecuteSearch
executeSearch(prisma: PrismaClient, config: SearchConfig, params: URLSearchParams): Promise<SearchResult>

Executes a full search query with filters, sorting, and pagination

const results = await executeSearch(prisma, config, req.nextUrl.searchParams);
Anti-Patterns
  • Do not use with non-PostgreSQL databases — full-text search uses PostgreSQL-specific features
AI Verification Report
Passed
Overall93%
Security95%
Code Quality88%
Documentation92%
Dependencies100%
13 files analyzed2,534 lines read15.3sVerified 3/5/2026

Findings (5)

  • -Documentation claims 'executeSearch' function as the main integration point, but the actual API uses 'buildPrismaQuery' + 'parseFilters' + 'parsePagination' + 'parseSort' workflow. The 'executeSearch' function is never exported or implemented.
  • -README shows raw SQL examples using '$queryRawUnsafe' which requires caution, but documentation does not explicitly warn about SQL injection risks or parameter binding requirements.
  • -In src/pagination.ts, the cursor pagination logic fetches take+1 records to detect hasMore, but there is no explicit trimming documented in API docs. The implementation is correct but could be clearer in comments.
  • -The typeahead sanitization in src/typeahead.ts removes '%' and '_' characters for LIKE safety, but this is not mentioned in the API documentation examples.
  • -Documentation claims support for 'contains' filter type with `description: { contains: 'api', mode: 'insensitive' }` Prisma output, which is accurate. However, the example in basic-usage.ts shows this filter type but README table shows lowercase 'contains' description inconsistently.

Suggestions (6)

  • -Add the missing 'executeSearch' function as a convenience wrapper that combines parseFilters, parsePagination, parseSort, and buildPrismaQuery into a single call matching the API reference documentation. Alternatively, remove it from the API reference and update integration steps to show the correct multi-step pattern.
  • -Document the cursor pagination 'take+1' fetching behavior explicitly in the buildCursorPaginationResult JSDoc and README pagination section.
  • -In src/filters.ts line 137, the range filter bounds enforcement compares min/max but uses loose equality checks. Consider normalizing types before comparison to prevent edge cases with string dates.
  • +3 more suggestions
Loading version history...
Loading reviews...