MCPcopy
hub / github.com/21st-dev/1code / search

Method search

src/renderer/features/mentions/search/engine.ts:50–108  ·  view source on GitHub ↗

* Search across all registered providers

(
    trigger: string,
    query: string,
    baseContext: Omit<MentionSearchContext, "query" | "signal" | "limit">,
    options: MentionSearchOptions = {}
  )

Source from the content-addressed store, hash-verified

48 * Search across all registered providers
49 */
50 async search(
51 trigger: string,
52 query: string,
53 baseContext: Omit<MentionSearchContext, "query" | "signal" | "limit">,
54 options: MentionSearchOptions = {}
55 ): Promise<AggregatedSearchResult> {
56 const startTime = performance.now()
57 const opts = { ...DEFAULT_OPTIONS, ...options }
58
59 // Cancel any pending search for this trigger
60 const searchKey = `${trigger}:${baseContext.projectPath ?? "global"}`
61 const existingController = this.pendingSearches.get(searchKey)
62 if (existingController) {
63 existingController.abort()
64 }
65
66 // Create new abort controller
67 const controller = new AbortController()
68 this.pendingSearches.set(searchKey, controller)
69
70 try {
71 // Get applicable providers
72 let providers = mentionRegistry.getByTrigger(trigger)
73
74 // Filter by provider IDs if specified
75 if (opts.providerIds && opts.providerIds.length > 0) {
76 const providerIdSet = new Set(opts.providerIds)
77 providers = providers.filter((p) => providerIdSet.has(p.id))
78 }
79
80 // Filter by availability
81 providers = providers.filter(
82 (p) => p.isAvailable?.({ projectPath: baseContext.projectPath }) ?? true
83 )
84
85 if (providers.length === 0) {
86 return this.createEmptyResult(startTime)
87 }
88
89 // Build search context
90 const context: MentionSearchContext = {
91 ...baseContext,
92 query,
93 signal: controller.signal,
94 limit: 50,
95 }
96
97 // Search all providers
98 const results = opts.parallel
99 ? await this.searchParallel(providers, context, opts)
100 : await this.searchSequential(providers, context, opts)
101
102 // Aggregate results
103 return this.aggregateResults(results, query, startTime)
104 } finally {
105 // Cleanup
106 this.pendingSearches.delete(searchKey)
107 }

Callers

nothing calls this directly

Calls 10

createEmptyResultMethod · 0.95
searchParallelMethod · 0.95
searchSequentialMethod · 0.95
aggregateResultsMethod · 0.95
getByTriggerMethod · 0.80
isAvailableMethod · 0.80
getMethod · 0.45
setMethod · 0.45
hasMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected