Repository navigation
Global Search: one search across every module, built on the search corpus #459
Replies: 1 comment 2 replies
|
@cloudcogsio this is an amazing piece of work, thank you. "Where did we see this before?" is exactly the question a desk asks every day, and the screenshots show it answering it. I especially like that it's built on the search index the way So yes, please do open the issue and the PR. Splitting it the way you suggest, the index and permission work first and the UI second, suits me well. Before the PR, could you write it up as a design page? It's about 55 files, and I'd rather we agree the details in one place than across review comments. The things worth settling are the ones you raised (scope keys, the rebuild stages, palette and results page kept separate), plus the points below. Write it as Markdown, here or as a file in the PR, and I'll put it on the wiki and add each decision with its date as we go. A few points from me:
Thanks again. This is a big step up for anyone working across several companies. |
Uh oh!
There was an error while loading. Please reload this page.
Hi Ed,
I'd like to show something we built on our fork and ask whether it's worth a PR.
Why we built it
The question we kept hearing on our service desk was "where did we see this before?" Someone remembers that something mentioned the VPN certificate, or an invoice number, or a supplier's name, but not whether it was a ticket, a task, a change or a problem, not its number, and often not which company it was for. We look after several companies, so it's usually in a company other than the one you're working in.
Today the answer means trying module by module, and switching company for each. Ctrl-K is great for jumping to something you can name, but it searches the active company only, matches changes, problems, contracts and projects by title, and doesn't search tasks at all. Your search corpus already does the hard part for tickets and knowledge (ranking, phrases, exclusions, permission inside the query), so it seemed the right foundation to stretch across the other modules rather than build a second search.
Here's the same word in both. In the Default company, Ctrl-K finds three things for "vpn":
Its new last row, See all results for "vpn", opens the results page, which finds twelve: the ticket that reported it, the problem behind it, the change that fixes it, the tasks, the support contract and the how-to, across three companies:
What it does
search/?q=…, grouped by module with counts. Each group shows its best three, with See all for a ranked, paged list. Chips filter by module, date and company, and the URL holds onlyq, so a search can be bookmarked or shared and Back works.in:tasks(repeatable),after:2026-01-01,before:…,company:"Acme Ltd", alongside the existing"phrases"and-exclusions. The chips and the keywords are the same thing: clicking a chip edits the text in the box.company:narrows it.knowledgeVisibilitySql()), so an analyst outside an article's list no longer sees it there. That's stricter than today, and probably worth a changelog line.GET /api/v1/search, and as an MCP tool (global_search).How it fits the corpus design
I tried to follow the rules at the top of
includes/search/search.phprather than add a second search:New source types in
search_documents:task,change,problem,contract,project, one row per record. No new tables, no schema change. One type-driven indexer (includes/search/records.php) is called from each module's service after commit. It's also called from the handful of writes that bypass the services: workflow task creation, repeat occurrences, the starters task refresh, tasks following their ticket's company move, and the template clean-up. A failed index is logged and never fails the save.Permission inside the query. The scope gains three parts, all rendered by
searchScopeToSql():projectVisibleSql(), and knowledge viaknowledgeVisibilitySql().Counts and lists come from one shared WHERE, so "7 found" always sits above seven rows.
searchCorpusQuery()generalised, not duplicated. It gainsgroup_by => 'record'and a module-count companion. The default ticket grouping is unchanged, so the inbox and the palette get exactly what they get today.Dates are the parent record's created date. A ticket counts by when it was opened, not when a reply arrived, so one ticket is never split across a range. No re-index of existing rows.
The rebuild in System → Search walks the new types in resumable stages after the tickets. It records an index version, so the switch can tell an admin that a rebuild is still needed.
API keys get no new permission. A type is searched only if the key can read it (
changes.read, …), internal notes needticket_notes.read, and results stay in the key's companies.What it touches
About 55 files, 24 of them new:
includes/search/{records,keywords,global}.php,includes/services/search.php,search/,api/search/query.php,api/v1/resources/search.php, two JS files and one CSS file. Changes to existing code are small hooks in the five services and the bypass paths, the scope and query changes insearch.php, the staged rebuild,renderCommandPalette()lifted out ofrenderWaffleMenuJS()so the home page can load it, and the one palette row.Tests: eight new CLI test files with ZZ fixtures on a real DB (indexing, permissions with positive controls, grouping/counts/dates, keywords, the service, the rebuild, the REST/MCP endpoint, the UI over HTTP), plus a browser page for the JS helpers. The existing search tests and the OpenAPI self-check pass.
Left out on purpose (v1): comments and history on tasks, changes and problems; the self-service portal; stemming and typo tolerance (MySQL doesn't do them; the trailing wildcard still covers plurals); saved searches. Documents keep their existing rule, found through their parent records in the active company, because I didn't want to change how documents are judged in this change.
The code is on
cloudcogsio:pr/global-search(diff against main), 16 commits on 5.13.0.Would this be useful upstream? If so I'm happy to open an issue and a PR, split however suits you: the corpus and permission work first and the UI second, for example. If you'd rather it worked differently anywhere, especially the scope keys, the stages, or keeping the palette and the results page separate, I'd value your view before going further.
All reactions