Skip to content

Support multiple difficulty and pattern filters#4

Merged
conallob merged 2 commits into
mainfrom
claude/multi-filter
May 5, 2026
Merged

Support multiple difficulty and pattern filters#4
conallob merged 2 commits into
mainfrom
claude/multi-filter

Conversation

@conallob
Copy link
Copy Markdown
Owner

@conallob conallob commented May 5, 2026

Summary

This PR extends the filtering system to support selecting multiple difficulties and patterns simultaneously, rather than being limited to a single filter value. The change applies across the CLI, web server, and core filtering logic.

Key Changes

  • Core filtering logic (quiz/quiz.go):

    • FilterProblems() now accepts difficulties and tagSlugs as slices instead of single strings
    • Filters are now OR-based within each category (any matching difficulty OR any matching tag)
    • Improved documentation clarifying filter behavior
  • CLI (cli/cli.go):

    • Added multiFlag type to support both repeated flags (--difficulty easy --difficulty hard) and comma-separated values (--difficulty easy,hard)
    • Updated --difficulty and --tag flags to use the new multiFlag type
    • Updated README with examples of the new multi-select syntax
  • Web UI (server/static/index.html):

    • Replaced single "All" difficulty button with independent toggle buttons for Easy/Medium/Hard
    • Replaced dropdown pattern selector with a scrollable checkbox list for multi-select
    • Added visual hint "(none = all)" to clarify that omitting filters includes all options
    • Updated CSS for checkbox styling and list layout
  • Server API (server/server.go):

    • Updated /api/quiz/start request body to accept difficulties and tags arrays instead of single strings
  • Tests (quiz/quiz_test.go):

    • Updated all existing tests to use the new slice-based API
    • Added new test cases: TestFilterByMultipleDifficulties, TestFilterByMultipleTags, and TestFilterByMultipleDifficultiesAndMultipleTags

Implementation Details

  • Filters use sets (maps) internally for O(1) lookup performance
  • Difficulty comparison remains case-insensitive
  • Passing nil or empty slices skips that filter category (equivalent to "all")
  • Problems must still have a primary pattern to be included (existing behavior preserved)

https://claude.ai/code/session_01CSqri29pumwCCTp4ApU2da

claude added 2 commits May 5, 2026 22:39
FilterProblems now accepts []string slices for both difficulties and
tags. A problem passes if its difficulty matches any of the supplied
values, and if it carries any of the supplied tag slugs. Empty slices
mean "no filter" (all included), same as before.

CLI: --difficulty and --tag now use a custom multiFlag type that
accepts repeated flags or comma-separated values, or any combination:
  --difficulty easy --difficulty hard
  --difficulty easy,hard
  --tag dp --tag backtracking

HTTP server: /api/quiz/start now reads {"difficulties":[...],"tags":[...]}
instead of single-value {"difficulty":"...","tag":"..."}.

Browser UI: difficulty buttons now toggle independently (multi-select)
instead of being mutually exclusive. Pattern selection is a scrollable
checkbox list instead of a single dropdown. In both cases, leaving all
unselected means all are included.

Tests: existing FilterProblems tests updated to pass slices; two new
tests added — TestFilterByMultipleDifficulties and
TestFilterByMultipleTags — plus a combined multi-difficulty+multi-tag
test.

https://claude.ai/code/session_01CSqri29pumwCCTp4ApU2da
The multiFlag type supported both --flag a --flag b and --flag a,b,
which was more complexity than needed. Replace it with standard
flag.String and a splitCSV helper that trims, lowercases, and splits
on commas. Flags are now strictly CSV:

  --difficulty easy,hard
  --tag dynamic-programming,backtracking

Repeated flags are no longer accepted. README examples updated to
match.

https://claude.ai/code/session_01CSqri29pumwCCTp4ApU2da
@conallob conallob merged commit 61716fe into main May 5, 2026
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.

2 participants