Class: ClaudeMemory::Commands::SearchCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- ClaudeMemory::Commands::SearchCommand
- Defined in:
- lib/claude_memory/commands/search_command.rb
Overview
Searches indexed content using full-text search
Instance Attribute Summary
Attributes inherited from BaseCommand
Instance Method Summary collapse
Methods inherited from BaseCommand
Constructor Details
This class inherits a constructor from ClaudeMemory::Commands::BaseCommand
Instance Method Details
#call(args) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/claude_memory/commands/search_command.rb', line 7 def call(args) query = args.first unless query stderr.puts "Usage: claude-memory search <query> [--db PATH] [--limit N]" return 1 end opts = (args[1..] || [], {limit: 10, scope: "all"}) do |o| OptionParser.new do |parser| parser.on("--limit N", Integer, "Max results") { |v| o[:limit] = v } parser.on("--scope SCOPE", "Scope: project, global, or all") { |v| o[:scope] = v } end end return 1 if opts.nil? manager = ClaudeMemory::Store::StoreManager.new store = manager.store_for_scope((opts[:scope] == "global") ? "global" : "project") fts = ClaudeMemory::Index::LexicalFTS.new(store) ids = fts.search(query, limit: opts[:limit]) if ids.empty? stdout.puts "No results found." else stdout.puts "Found #{ids.size} result(s):" ids.each do |id| text = store.content_items.where(id: id).get(:raw_text) preview = text&.slice(0, 100)&.gsub(/\s+/, " ") stdout.puts " [#{id}] #{preview}..." end end manager.close 0 end |