Skip to content

Global Search Design

Ed Mozley edited this page Dec 6, 2026 · 2 revisions

Global Search: design

Status, 6 December 2026: PR 1 MERGED. PR #537 by @cloudcogsio (index, permissions and the search service, no screen) was merged on 6 December 2026, verdict Merge + fix, with review follow-ups on top (see Review notes below and the review page). Tracking issue #536. Next: PR 2 - both switches, results page, home box, Ctrl-K's See all results row, previews, REST/MCP, help.

Status: AGREED (5 December 2026) - written by @cloudcogsio, who is building it; agreed with Ed in discussion #459. Next: the issue and PR 1 from @cloudcogsio. (Originally: proposed, for agreement before the PRs) Β· Discussion: #459 Β· Code: cloudcogsio:pr/global-search (on 5.14.0) Β· Builds on: the search corpus (#53, #76, Full-Text-Search)

Decisions

# Decision Date Status
D1 Global Search extends the search corpus (search_documents) with new source types, rather than adding a second search 2026-11-27 Agreed (Ed, 2026-12-05)
D2 Permission is judged inside the query, on each record's own table now, never on the indexed copy. Counts and lists share one WHERE 2026-11-27 Agreed (Ed, 2026-12-05)
D3 New, optional scope keys: tenant_ids, record_clause, created_from_utc/created_to_utc, exclude_internal_notes, knowledge_viewer. The existing allowed_modules now also filters source types 2026-11-27 Agreed (Ed, 2026-12-05)
D4 The System β†’ Search rebuild walks the new types in resumable stages after the tickets and records an index version 2026-11-27 Agreed (Ed, 2026-12-05)
D5 Ctrl-K and the results page stay separate: Ctrl-K is a jump list for the active company; the results page is the full search across every company. They meet in one row, See all results 2026-11-27 Agreed (Ed, 2026-12-05)
D6 Off by default, behind one switch in System β†’ Search. While off, nothing changes for analysts, except D9, which is a permission fix and applies whatever the switch says 2026-11-27 Agreed (Ed, 2026-12-05)
D7 The home page box is a separate tick, "Show a search box on the home page", only shown while Global Search is on. Default: off until ticked (Q1) 2026-11-29, default 2026-12-05 Agreed (Ed)
D8 Each result carries a preview badge (FreeITSMPreview.badge()). Projects and documents gain a preview each 2026-11-29 Agreed in #459
D9 Ctrl-K's knowledge results follow knowledge access lists, on every install from PR 1, with its own changelog line 2026-11-29 Agreed in #459
D10 Two PRs: (1) index and permissions. The only visible changes are D9 and the System β†’ Search rebuild running in stages. (2) The search itself: service, switches, results page, home box, palette row, previews, REST/MCP, help 2026-11-29 Agreed in #459
D12 Documents across companies (Q2): v1 finds documents in every company the analyst can access, through their parent record (the parent's permission decides), like every other result - with its own changelog line 2026-12-05 Agreed (Ed)
D13 PR 1 carries the service (Q3): the index, the permissions and the search service with no UI and no endpoint, so the permission rules are tested end to end before any screen is built on them 2026-12-05 Agreed (Ed)
D11 Ask (questions answered from the results) is not in v1. v1 keeps the door open (see Later: Ask) 2026-11-29 Agreed in #459

Review notes - PR 1 (2026-12-06)

Added when PR #537 was merged. Binding on PR 2. Full write-up: Global Search PR 1 - review.

# Note Date
R1 A scope's company list narrows, never widens, and that is enforced in the scope builder. searchScopeForAnalyst() cuts tenant_ids / tenant_id / include_default back to getAccessibleTenantIds() after any overrides, and ticketScopeFilterForCompanies() intersects the same way (as documentVisibilityClause() already did). This matters for PR 2: a company list coming from an API key (REST, MCP) can never reach further than the key's analyst 2026-12-06
R2 A hand-built scope judges no records. A scope without record_clause judges no task, change, problem, contract or project, members-only projects included. Every search on behalf of a person (page, REST, MCP) must build its scope with searchScopeForAnalyst() / searchScopeForAnalystAllCompanies() (a TRAP: in searchScopeToSql()) 2026-12-06
R3 The final rebuild stage also prunes rows of Knowledge articles that no longer exist (they made System β†’ Search's counts wrong; never shown) 2026-12-06

Why

"Where did we see this before?" Someone remembers that something mentioned the VPN certificate, an invoice number or a supplier, but not whether it was a ticket, task, change or problem, not its number, and often not its company. Ctrl-K is built to jump to a record you can name: it searches the active company, matches most modules by title, and doesn't search tasks. The corpus already does the hard part for tickets and knowledge (ranking, phrases, exclusions, permission inside the query), so Global Search stretches it across the other modules.

What v1 does

  • One full-text search over tickets (subject, messages, notes, attachment text), tasks, changes, problems, contracts, projects, knowledge and documents.
  • A results page, search/?q=…, grouped by module with counts, top three per group, See all for a ranked, paged list. A preview badge on every result.
  • Keywords in:, after:, before:, company: alongside "phrases" and -exclusions. The chips on the results page edit the same text.
  • Every company the analyst can access; company: narrows it.
  • An optional search box on the home page (D7), and a See all results row in Ctrl-K.
  • GET /api/v1/search and an MCP tool, global_search.

1. What is indexed

Existing source types are untouched. Five new ones, one corpus row per record: the title, and the record's text fields joined into a plain-text body.

Source type Title Body
task title description
change title description, reason_for_change, risk_evaluation, test_plan, rollback_plan, post_implementation_review, pir_lessons_learned, pir_follow_up
problem title description, root_cause, workaround
contract title description
project name summary, goal, business_case, estimated_benefit, approval_notes, health_note

One registry, searchRecordTypes() in includes/search/records.php, names each type's table, columns, module, results group and entityLink() type. The indexer, rebuild, permission clause and results page all read it, so they can't drift apart. Adding a type later means one entry plus its hooks.

No new tables, no schema change. All five tables read a NULL company as the Default company, as tickets do. Contracts without tenant_id (before Database Verification) are treated as Default.

2. Keeping the index current

  • searchIndexRecordSafe($conn, $type, $id) after each service's commit, searchUnindexRecordSafe() on delete. Both log and never throw, so a failed index never fails a save. Projects are refreshed once, in ProjectsService::afterChange().
  • The writes that bypass the services call it too: workflow task creation, repeat occurrences and their subtasks, the starters task text refresh, tasks following their ticket's company move (ticketsFollowCompanyMove()), tasks moved with a change, and template clean-up.
  • Indexing runs whether Global Search is on or off. It's invisible, and turning the search on then needs one rebuild, not a catch-up. The cost: from the upgrade on, every install writes one more corpus row per task, change, problem, contract and project.
  • A missed hook leaves a row stale, never leaky, because visibility is judged on the live table (section 3). The rebuild repairs stale rows and prunes rows whose record is gone.

3. Permissions, inside the query

Following the two rules at the top of includes/search/search.php: permission is part of the query, and scope is data, not SQL. The scope gains these keys, all rendered by searchScopeToSql():

Key What it does
tenant_ids (new) Every company the caller may see, instead of the one active company. An empty array matches nothing. include_default keeps today's Default-company meaning.
allowed_modules (existing) Already limited documents. Now also limits source types through a type β†’ module map. A type the map doesn't know is excluded (fails closed). searchScopeForAnalyst() already sets this key, so every corpus search now drops types outside the analyst's modules. For today's callers that changes nothing: the inbox reads only ticket rows, and Ctrl-K already hid articles from analysts without Knowledge.
record_clause (new) Built by searchRecordVisibilityClause() in searchScopeForAnalyst(), so every corpus search gets it. Judges each record on its own table now: company (a moved record stops being found before anything re-indexes it), members-only projects via projectVisibleSql(), knowledge via knowledgeVisibilitySql() (lifecycle unarchived, the analyst list's rule), and the created-date range. A part that can't be built excludes its type. The knowledge part is what makes D9 apply to Ctrl-K.
created_from_utc / created_to_utc (new) The date range (section 4).
exclude_internal_notes (new) Leaves internal ticket notes out. Used by API keys without ticket_notes.read.
knowledge_viewer (new) The knowledge reader for an explicit company list (KnowledgeViewer::forApiKey()). Used by the every-company and API scopes.

Now that the corpus holds other record types, Ctrl-K's content block asks only for ticket rows and articles (source_types), so tasks and changes can't take its few places.

Ticket rules are unchanged (departments, deleted tickets, internal notes). Documents keep upstream's documentSearchVisibilityClause() unchanged, so in v1 documents are found through their parent records in the active company only (see open question Q2). (Superseded by D12, built in PR #537: documents are found through their parents in every company the analyst can reach - Permissions and search Β§4a.)

Counts and lists come from one shared WHERE (searchCorpusWhere()), so "7 found" always sits above seven rows. The permission tests use positive controls (the same fixture is found by someone who may see it), so a test can't pass just because nothing matched. They cover companies, modules, members-only projects, shared, archived and draft articles, deleted documents and internal notes. PR 1 adds one for an article restricted by an access list, in Global Search and in Ctrl-K (D9).

4. Query language

searchExtractKeywords() (includes/search/keywords.php) takes the keywords out before searchParseQuery() sees the text. It's a pure function with its own tests.

Keyword Meaning
in:tasks One results group. Repeatable (OR). Unknown names are ignored with a notice.
after:2026-01-01, before:… Created on or after / on or before, in whole days in the reader's time zone (UTC over the API).
company:Acme / company:"Acme Ltd" Every company of that name the reader may see. A company that doesn't exist and one the reader can't reach give the same empty answer, so a search never confirms that a company exists.

Quoted keywords stay text ("in:tasks" searches the words). Dates are the parent record's created date, joined from its own table, never source_datetime. A ticket counts by when it was opened, so one ticket is never split across a range. Existing rows need no re-index.

5. Grouping, counts and paging

  • searchCorpusQuery(…, ['group_by' => 'record']) ranks records of any type. A ticket's rows collapse into the ticket, and documents stay documents. The default (ticket) grouping is unchanged for the inbox and Ctrl-K.
  • searchCorpusModuleCounts() counts records per results group over the same WHERE.
  • A grouped search runs one counts query, then one ranked query per group for its top three. Groups are ordered by their best hit.
  • One group (in: a single module, or See all): a ranked list, 20 at a time, with More. next_offset comes from what the index ranked, so pages don't overlap or skip.
  • Result fields (title, reference, company, created date, link) are read from the record's own table, not the index. Snippets come from searchSnippet() as plain text, with terms wrapped in <mark> after escaping.

6. Rebuild and index version

The System β†’ Search rebuild becomes searchRebuildSlice($conn, $stage, $sinceId) over the stages tickets β†’ task β†’ change β†’ problem β†’ contract β†’ project β†’ final. Each slice is resumable, and tickets run first exactly as today. The final stage records search_index_version = 2. scripts/search_backfill.php does the same in one run, and only a full run writes the version.

While the version is below 2, the switch tells the admin a rebuild is still needed, and the results page tells admins the index isn't complete. Analysts see no difference.

7. Switches (System β†’ Search)

Setting Default Controls
global_search_enabled: "Global Search" off Everything: results page and its help, Ctrl-K's See all row, the palette on the home page, GET /api/v1/search (404 while off, and not listed by GET /), the MCP tool.
global_search_home_box: "Show a search box on the home page" (D7) off Only the box under the welcome text. The tick can't be changed while Global Search is off, and does nothing then.

Both are system_settings rows, read with "unset = off", so an upgrade changes nothing until an admin opts in. Ctrl-K works on the home page whenever Global Search is on, with or without the box.

8. The results page

  • search/?q=…. The URL holds only q, so searches can be bookmarked and shared, and Back works.

  • Chips for module, date and company write the same keywords into the box. The home box and the results box open a small picker when you type a keyword: modules for in:, companies for company:, a date for after:/before:.

  • Each result: title linking through entityLink(), reference, company (multi-company installs only), created date, snippet, and a preview badge (D8).

  • Previews: the page loads assets/js/record-preview.js and calls FreeITSMPreview.badge(type, id) on every row. Ticket, task, change, problem, contract and knowledge use the existing previews (corpus kb_article β†’ preview knowledge_article). Two new ones in includes/record_preview.php, written the file's way (one function, reached through recordPreview()):

    • recordPreviewProject(): name, status, health, owner, dates, company. Access: recordPreview()'s module gate, then analystCanAccessProject() (members-only, then company), as the task preview uses analystCanAccessTask().
    • recordPreviewDocument(): name, type, size, what it's attached to, uploaded by and when. Access: the document isn't deleted, and at least one record it is attached to passes documentCanViewParent(). That's the download endpoint's rule, and it covers every company the analyst can reach, as the other previews do.

    The preview endpoint judges access itself, so a badge never shows more than opening the record would. Both previews also work on any other page that wants them.

  • Empty, not-ready and dropped-term states are explained in words ("'to' is too short to search").

  • In-app help at search/help.php.

9. Ctrl-K

Unchanged behaviour: active company, jump on Enter, the same sources. Two changes:

  • Knowledge results follow knowledge access lists (knowledgeVisibilitySql()) (D9). This comes from record_clause (section 3), so it ships in PR 1 and applies on every install, whether Global Search is on or off. An analyst outside an article's list no longer sees it in Ctrl-K, which is stricter than today. Proposed changelog line: "Ctrl-K no longer lists knowledge articles that are restricted to other analysts or teams."
  • While Global Search is on (PR 2), a last row See all results for "…" opens the results page. renderCommandPalette() is lifted out of renderWaffleMenuJS() so the home page can load the palette. See all results is a list row, not a button.

Why separate (D5): Ctrl-K answers "take me to X" and must stay instant. LT-001 + Enter still jumps to the asset. The results page answers "where does this appear". Name-matched types not in the corpus (assets, CMDB, people, suppliers, domains) stay in Ctrl-K only.

10. REST and MCP

  • GET /api/v1/search?q=…&limit=&offset=. The grouped shape is {groups: [{group, total, results}]}, with each group's top three. With exactly one in: group it returns results, total, limit, offset, next_offset instead. limit and offset apply only then. It's documented in the OpenAPI spec.
  • The page (through its own endpoint, api/search/query.php), the REST API and MCP all call one service, GlobalSearchService::search($conn, $scope, $q, $opts) (includes/services/search.php). The service never reads the session. Its caller builds the scope: searchScopeForAnalystAllCompanies() for the page, searchScopeForApiKey() for REST and MCP.
  • No new permission. Through REST, a group is searched only if the key can read its resource (tickets, changes, …) and the key's analyst has the module. Internal notes need ticket_notes.read, and documents need documents.read. Companies are the key's effective company scope, and anything unexpected means none (fails closed).
  • MCP (global_search): an MCP key carries mcp.read rather than resource permissions, so it searches what the key's analyst may see, in the key's companies, like the other MCP tools. The tool is listed only while Global Search is on and the analyst has at least one module to search.

11. Tests

CLI scripts on a real DB with ZZ fixtures, behind the CLI guard: global-search-{indexing,permissions,query,keywords,rebuild,service,ui}.php, api-global-search.php, shared fixtures in tests/support/global-search-fixtures.php, and a browser page for the JS helpers. The second PR adds the home box tick (off/on), the preview badges, and the project and document previews (seen and refused). The existing search tests and the OpenAPI self-check still pass.

12. Delivery

  1. Issue linking this page.
  2. PR 1, index, permissions and the service (D13; #537, merged 2026-12-06): records.php, the index hooks, the scope keys and group_by => 'record' in search.php, Ctrl-K's source_types restriction, the staged rebuild and index version, the documents companies rule (D12), the keywords and GlobalSearchService with no UI and no endpoint, plus the indexing, permissions (with the access-list test), query, keywords, rebuild and service tests. Visible changes: D9 (its changelog line) and the rebuild's stages. Nothing but the service and its tests reads the new rows until PR 2.
  3. PR 2, Global Search, opened once PR 1 is merged: both switches, results page, home box, Ctrl-K's See all results row, previews, REST/MCP, help, lang/en, plus the remaining tests (global-search-ui.php, api-global-search.php).

(Corrected 2026-12-06: this section first listed the keywords and the service under PR 2. D13 moved them into PR 1, and PR #537 followed D13.)

Not in v1

Comments and history on tasks, changes and problems. The self-service portal. Stemming and typo tolerance (MySQL has neither; the trailing wildcard covers plurals). Saved searches. A search box in every page header.

Later: Ask

An optional Ask on the results page: "what do we know about the VPN certificate problem?", answered from the results the analyst can already see, with a link to each record it used. Not in v1 (D11). How v1 leaves room for it:

  • The AI only ever sees search results. Ask would call GlobalSearchService::search() with the analyst's own scope, the same call as the page, so it can't be given a record the analyst couldn't open. No second permission path to keep in step.
  • Citations come free. Every result already carries type, id, company and link, so the answer can cite records by link, and the page can check that every citation was in the results it sent.
  • Text, not just snippets. v1 returns snippets. Ask would need a bounded amount of each top record's text. That's a service option (e.g. with_text) reading the record's own table, the same way results read their fields now. v1 doesn't need to change for it.
  • Confidential tickets. Ask follows the existing rule for AI features that read many tickets: ticketAiExclusionSql() (Tickets β†’ Settings) leaves confidential tickets out. So do records whose text comes from one: its messages, notes and attachments, its tasks, and documents attached only to it. Anything left out is listed as "not included", never silently dropped.
  • Internal notes and staff-only articles. The analyst can see them, but sending them takes them off the install. Ask's settings say whether they go, off by default.
  • Record text is data. Everything sent is quoted as material to answer from, never as instructions to the model.
  • Its own switch. Off by default, under System β†’ AI, using that provider, and not offered while Global Search is off. Not on the API at first.
  • Logged like the other AI calls (who asked, which records were sent).

Open questions - answered 5 December 2026 (D7, D12, D13)

  • (Answered: off until ticked - D7.) Q1. Home box default. Proposed off until ticked (D7), like the main switch. Would you rather it came on with Global Search, as the original build did?
  • (Answered: yes, every company, through the parent record - D12.) Q2. Documents across companies. Results find documents through their parent records in the active company (upstream's documentSearchVisibilityClause(), left unchanged on purpose), while the new document preview follows the parent across every company, as the other previews do. Should v1 also find documents across every company? It's a small change to the document clause, and I'd rather you decided it than slip it in.
  • (Answered: PR 1 carries the service, no UI or endpoint - D13.) Q3. PR 1 without its reader. Is it fine for PR 1 to index rows that nothing reads until PR 2, or would you rather PR 1 also carried the service (no UI, no endpoint) so it can be tested end to end on its own?

FreeITSM

Getting Started

Modules

Multi-tenancy (planned)

Responses to feedback

Blue sky thinking

Bugs resolved

Pull requests

Links

Clone this wiki locally