Skip to content

[Feature]: Add keyword search to flashcards #2292

Description

@Suprita736

Feature/Project Proposal

Add keyword search functionality to the Spaced Repetition flashcard page.

The search should allow users to quickly find flashcards by entering keywords that match either the question or answer. The search should integrate with the existing due-status and category filters so users can narrow down large flashcard collections efficiently.

Problem Statement

Currently, the Spaced Repetition page only provides filters such as due status and category. There is no way to search for a specific flashcard using text.

As an SRS deck grows, manually browsing through a large number of flashcards becomes time-consuming. Users may know a keyword from a question or answer but have no efficient way to locate the relevant card.

Proposed Solution

Add an optional keyword search parameter to the flashcard API and a search input to the existing filter bar.

Backend:

  • Add an optional q query parameter to getUserFlashcards.
  • Search across both the question and answer fields using a case-insensitive $or query.
  • Reuse the existing escapeRegex pattern from questionController.js to safely escape user input.
  • Limit the search term to approximately 200 characters, following the existing implementation pattern.
  • Ensure the search works together with the existing due and category filters.

Frontend:

  • Add a keyword search input to the existing filter bar in SpacedRepetitionPage.jsx.
  • Send the search term as the q query parameter.
  • Update the displayed flashcards based on the search results.

Alternatives Considered

  1. Client-side filtering:
    Filtering the already-loaded flashcards on the frontend was considered, but this would not scale well for large SRS decks and could require loading unnecessary flashcards.

  2. Searching only the question field:
    Searching only questions would be simpler, but users may remember a keyword that appears only in the answer. Searching both question and answer provides a more useful experience.

  3. Adding a separate search page:
    A separate search interface would add unnecessary navigation. Integrating search into the existing filter bar keeps the workflow simple and consistent.

Benefits

This feature would:

  • Make large SRS decks significantly easier to navigate.
  • Allow users to quickly locate specific questions or concepts.
  • Reduce the need to manually browse through flashcards.
  • Allow keyword search to be combined with existing due and category filters.
  • Provide a better experience as users' flashcard collections grow.
  • Keep search handling safe by escaping regex input and limiting the search term length.

Priority

Medium

Additional Context

Relevant files:

  • backend/controllers/flashcardController.jsgetUserFlashcards
  • backend/routes/flashcardRoutes.js
  • frontend/src/pages/SpacedRepetition/SpacedRepetitionPage.jsx
  • questionController.js — existing escapeRegex implementation

The implementation should follow the existing search/regex-safety pattern in questionController.js rather than introducing a separate regex escaping implementation if the helper can be reused.

The search should remain optional so existing API consumers and current filtering behavior continue to work when q is not provided.

Checklist

  • I have searched existing issues and discussions before creating this request.
  • I am willing to work on this feature if it is approved.

Metadata

Metadata

Assignees

Labels

claimedThis issue has been claimed by a contributorenhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions