From 6fbb1a0aff992b52fe168c1143c50eb9a66f78ed Mon Sep 17 00:00:00 2001 From: DavidGG Date: Mon, 2 Mar 2026 17:21:25 +0100 Subject: [PATCH] feat: add --account flag to search command Allows scoping search results to a single account when multiple accounts are synced into the same archive. Resolves the account identifier to a source_id via GetSourceByIdentifier and sets q.AccountID directly on the parsed search.Query, which buildSearchQueryParts already handles. No interface changes needed. --- cmd/msgvault/cmd/search.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmd/msgvault/cmd/search.go b/cmd/msgvault/cmd/search.go index c84fc68f..a2e44217 100644 --- a/cmd/msgvault/cmd/search.go +++ b/cmd/msgvault/cmd/search.go @@ -18,6 +18,7 @@ var ( searchLimit int searchOffset int searchJSON bool + searchAccount string ) var searchCmd = &cobra.Command{ @@ -117,6 +118,18 @@ func runLocalSearch(cmd *cobra.Command, queryStr string) error { if err := s.InitSchema(); err != nil { return fmt.Errorf("init schema: %w", err) } + + if searchAccount != "" { + src, err := s.GetSourceByIdentifier(searchAccount) + if err != nil { + return fmt.Errorf("look up account: %w", err) + } + if src == nil { + return fmt.Errorf("account %q not found", searchAccount) + } + q.AccountID = &src.ID + } + if err := ensureFTSIndex(s); err != nil { return err } @@ -234,6 +247,7 @@ func init() { searchCmd.Flags().IntVarP(&searchLimit, "limit", "n", 50, "Maximum number of results") searchCmd.Flags().IntVar(&searchOffset, "offset", 0, "Skip first N results") searchCmd.Flags().BoolVar(&searchJSON, "json", false, "Output as JSON") + searchCmd.Flags().StringVar(&searchAccount, "account", "", "Limit results to a specific account (email address)") } // ensureFTSIndex checks if the FTS search index needs to be built and