Skip to content

feat: add inverted index search - #653

Merged
TheVicky1 merged 1 commit into
TheVicky1:mainfrom
toyes3429:feat/search-inverted-index
Oct 23, 2026
Merged

TheVicky1 merged 1 commit into
TheVicky1:mainfrom
toyes3429:feat/search-inverted-index

Conversation

@toyes3429

Copy link
Copy Markdown
Contributor

🏛️ PACT Pull Request


1. Related Issue

Closes #645

2. Summary of Changes

  • Added an inverted index search implementation in src/lib/search/inverted-index.ts.
  • Added unit tests in tests/inverted-index.test.ts.
  • Implemented term matching, prefix search, and configurable AND/OR query operators.
  • Added relevance scoring, result limits, minimum-score filtering, and configurable stop words.
  • Added support for updating, removing, and clearing indexed documents.

3. Motivation & Context

This contribution introduces an inverted-index-based search utility to support efficient term-based document retrieval and relevance ranking.

It provides reusable search functionality with configurable matching behavior and result filtering.


4. Implementation Details

  • Indexes selected string fields from documents.
  • Normalizes tokens and supports case-insensitive matching.
  • Calculates term-frequency-based relevance scores.
  • Supports AND and OR operators, prefix matching, and stop-word filtering.
  • Maintains index consistency when documents are replaced, removed, or cleared.
  • Validates search options and document IDs.
  • Adds tests covering search behavior, ranking, document lifecycle, and invalid inputs.

5. Testing & Local Validation

  • npm run lint — ESLint passed with 0 errors
  • npx tsc --noEmit — TypeScript strict check passed with 0 errors
  • npm test — Full authoritative test matrix passed
  • npm test -- inverted-index — Targeted inverted-index test suite passed (18 tests)
  • node scratch/secret-scan.mjs — Zero secrets or sensitive credentials detected
  • npm run build — Production build succeeded without errors

Verification performed: The targeted inverted-index suite passed all 18 tests. Full-project validation remains to be confirmed.


6. UI & Visual Changes

  • No UI changes

7. Database & Security Impact

  • No database or security-sensitive changes

8. Documentation Impact

  • Documentation updates not required for this change.

9. Contributor Quality Checklist

  • 🌱 Micro-Contribution Fast-Path — Not applicable; this change introduces a search utility and its test suite.
  • My PR has a focused scope.
  • I have read and followed PACT's [Contributing Guide](https://github.com/TheVicky1/Pact_OS/blob/main/CONTRIBUTING.md).
  • I confirm that zero secrets, API keys, private tokens, or .env.local files are included in this PR.
  • My branch was created from the latest upstream/main.
  • My commits follow the Conventional Commits format.
  • I have linked the target issue in Section 1.
  • I have reviewed my own git diff to ensure no stray files or debugging artifacts were committed.

10. Reviewer Notes

The targeted test suite covers the primary search operations, relevance ranking, query operators, document lifecycle, and invalid inputs.

Please review the implementation and its test coverage for correctness and consistency with the project's existing search architecture.

@toyes3429
toyes3429 requested a review from TheVicky1 as a code owner October 21, 2026 19:59
@vercel

vercel Bot commented Oct 21, 2026

Copy link
Copy Markdown

@toyes3429 is attempting to deploy a commit to the Vicky's projects Team on Vercel.

A member of the Team first needs to authorize it.

@TheVicky1
TheVicky1 merged commit 956ada1 into TheVicky1:main Oct 23, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Search] Add Inverted Index Token Matrix with Term Frequency (TF) Scoring in src/lib/search/inverted-index.ts

2 participants