Skip to content

fix: support multiple -c collection filters in search/query/vsearch#176

Open
neomatrixyzy wants to merge 1 commit intotobi:mainfrom
neomatrixyzy:fix/multiple-collection-filter
Open

fix: support multiple -c collection filters in search/query/vsearch#176
neomatrixyzy wants to merge 1 commit intotobi:mainfrom
neomatrixyzy:fix/multiple-collection-filter

Conversation

@neomatrixyzy
Copy link

Summary

Fix for #175 — multiple -c / --collection flags are now properly supported across all search modes.

The Bug

parseArgs in qmd.ts used type: "string" without multiple: true for the collection option. When passing -c plans -c sessions, only "sessions" (the last value) was kept. This silently broke multi-collection search workflows.

The Fix

qmd.ts (CLI layer)

  • Added multiple: true to parseArgs collection option
  • Added normalizeCollectionFilter() helper to normalize string | string[]string[] | undefined
  • Updated search(), vectorSearch(), and querySearch() to validate and pass collection arrays

store.ts (search engine layer)

  • searchFTS: collectionId?: numbercollectionNames?: string[], SQL = ?IN (?, ?, ...)
  • searchVec: collectionName?: stringcollectionNames?: string[], SQL = ?IN (?, ?, ...)
  • Updated CJK fallback paths (trigram + LIKE) for multi-collection support
  • Updated Store interface, HybridQueryOptions, VectorSearchOptions
  • Updated all internal callers in hybridQuery and vectorSearchQuery

Testing

# Before fix: only searches last collection
qmd search "Apple TV" -c plans -c sessions -n 5 --files
# → only "sessions" results (or empty)

# After fix: searches both collections
qmd search "Apple TV" -c plans -c sessions -n 5 --files
# → results from both plans AND sessions ✅

# Single -c backward compatible
qmd search "test" -c plans -n 3 --files  # ✅ works as before

# All three modes verified
qmd search  "query" -c a -c b  #
qmd query   "query" -c a -c b  #
qmd vsearch "query" -c a -c b  #

Files Changed

  • src/qmd.ts — parseArgs + command handlers (~20 lines)
  • src/store.ts — search functions + interfaces (~40 lines)

Fixes #175

Previously, passing multiple -c flags (e.g. -c plans -c sessions) only
searched the last collection because parseArgs used type:'string' without
multiple:true. This silently dropped all but the last -c value.

Changes:
- qmd.ts: Add multiple:true to parseArgs collection option, add
  normalizeCollectionFilter() helper, update search/vectorSearch/querySearch
  to handle string[] collection filters
- store.ts: Change searchFTS collectionId?:number to collectionNames?:string[],
  change searchVec collectionName?:string to collectionNames?:string[],
  update SQL from '= ?' to 'IN (?, ?, ...)', update Store interface,
  HybridQueryOptions, VectorSearchOptions, and all internal callers

Fixes tobi#175
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.

Bug: Multiple -c (collection filter) flags silently ignored — only last value used

1 participant