MCPcopy
hub / github.com/PatchMon/PatchMon / GlobalSearch

Method GlobalSearch

server-source-code/internal/store/search.go:29–148  ·  view source on GitHub ↗

GlobalSearch searches across hosts, packages, repositories, host groups, users, and docker entities.

(ctx context.Context, query string, limit int)

Source from the content-addressed store, hash-verified

27
28// GlobalSearch searches across hosts, packages, repositories, host groups, users, and docker entities.
29func (s *SearchStore) GlobalSearch(ctx context.Context, query string, limit int) ([]SearchResult, error) {
30 d := s.db.DB(ctx)
31 if limit <= 0 {
32 limit = 30
33 }
34 pattern := fmt.Sprintf("%%%s%%", query)
35
36 rows, err := d.Raw(ctx, `
37 WITH host_results AS (
38 SELECT id, COALESCE(friendly_name, hostname, '') AS name,
39 'host'::text AS type,
40 COALESCE(os_type || ' ' || os_version, '') AS description
41 FROM hosts
42 WHERE friendly_name ILIKE $1
43 OR hostname ILIKE $1
44 OR ip ILIKE $1
45 OR notes ILIKE $1
46 ORDER BY last_update DESC NULLS LAST
47 LIMIT 5
48 ),
49 package_results AS (
50 SELECT id, name, 'package'::text AS type,
51 COALESCE(description, category, '') AS description
52 FROM packages
53 WHERE name ILIKE $1
54 ORDER BY name ASC
55 LIMIT 5
56 ),
57 repository_results AS (
58 SELECT id, name, 'repository'::text AS type,
59 COALESCE(url, '') AS description
60 FROM repositories
61 WHERE name ILIKE $1
62 OR url ILIKE $1
63 OR description ILIKE $1
64 ORDER BY name ASC
65 LIMIT 5
66 ),
67 host_group_results AS (
68 SELECT id, name, 'host_group'::text AS type,
69 COALESCE(description, '') AS description
70 FROM host_groups
71 WHERE name ILIKE $1
72 OR description ILIKE $1
73 ORDER BY name ASC
74 LIMIT 5
75 ),
76 user_results AS (
77 SELECT id, username AS name,
78 'user'::text AS type,
79 COALESCE(email, '') || CASE WHEN first_name IS NOT NULL OR last_name IS NOT NULL
80 THEN ' - ' || COALESCE(first_name, '') || ' ' || COALESCE(last_name, '')
81 ELSE '' END AS description
82 FROM users
83 WHERE username ILIKE $1
84 OR email ILIKE $1
85 OR first_name ILIKE $1
86 OR last_name ILIKE $1

Callers

nothing calls this directly

Calls 4

RawMethod · 0.80
DBMethod · 0.65
CloseMethod · 0.45
ScanMethod · 0.45

Tested by

no test coverage detected