MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / Search

Method Search

internal/metadata/store.go:196–233  ·  view source on GitHub ↗

Search queries the metadata_items table with LIKE matching. Results are deduplicated by name (case-insensitive): when the same name exists in several repos, only the canonical source is returned (see canonicalOrder). Install status is unaffected because InstalledAppsFor detects installs by on-disk d

(ctx context.Context, q SearchQuery)

Source from the content-addressed store, hash-verified

194// Install status is unaffected because InstalledAppsFor detects installs by
195// on-disk directory name, independent of repo.
196func (s *Store) Search(ctx context.Context, q SearchQuery) ([]Item, error) {
197 if err := s.Init(ctx); err != nil {
198 return nil, err
199 }
200 db, err := s.open()
201 if err != nil {
202 return nil, err
203 }
204 defer db.Close()
205
206 limit := q.Limit
207 if limit <= 0 {
208 limit = 100
209 }
210 pattern := "%" + q.Query + "%"
211
212 args := []any{pattern, pattern, pattern, pattern, pattern}
213 if q.Kind != "" {
214 args = append([]any{q.Kind}, args...)
215 }
216 args = append(args, limit, q.Offset)
217
218 rows, err := db.QueryContext(ctx, `
219 WITH ranked AS (
220 SELECT `+itemColumns+`,
221 ROW_NUMBER() OVER (PARTITION BY lower(name) ORDER BY `+canonicalOrder+`) AS rn
222 FROM metadata_items
223 WHERE `+matchPredicate(q.Kind)+`
224 )
225 SELECT `+itemColumns+` FROM ranked WHERE rn = 1
226 ORDER BY name LIMIT ? OFFSET ?`,
227 args...)
228 if err != nil {
229 return nil, fmt.Errorf("metadata: search: %w", err)
230 }
231 defer rows.Close()
232 return scanItems(rows)
233}
234
235// Count returns the number of deduplicated names matching the query (ignoring
236// limit/offset), so the total matches what Search can display.

Calls 5

InitMethod · 0.95
openMethod · 0.95
matchPredicateFunction · 0.85
scanItemsFunction · 0.85
QueryContextMethod · 0.80