Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cmd/msgvault/cmd/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
searchLimit int
searchOffset int
searchJSON bool
searchAccount string
)

var searchCmd = &cobra.Command{
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down