Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

fix(tracking): read a fan-out an engine joined with semicolons as each search (#1625)

Cihanc2a5a19a5f9c
diff --git a/server/src/lib/cloro-scraper.js b/server/src/lib/cloro-scraper.js
index 6b6b25f67..9a7f59e46 100644
--- a/server/src/lib/cloro-scraper.js
+++ b/server/src/lib/cloro-scraper.js
@@ -116,6 +116,13 @@ function toCitations(sources) {
}));
}
+/**
+ * Where an entry an engine joined splits into its searches: at a semicolon,
+ * not one that ends an HTML entity ("what's", "&"). The same rule as
+ * the editor's (web/src/lib/content/sources.ts, fanoutQueries).
+ */
+const SEARCH_SEPARATOR = /(?<!&#?\w+);/u;
+
/**
* Normalize the observed query fan-out from a raw Cloro response into a rich,
* engine-labelled array: `[{ query, engine?, source_platform }]` (#332).
@@ -132,26 +139,31 @@ function toCitations(sources) {
* ChatGPT's fan-out went silent on 2026-09-30, nothing told an emptied field
* from one that changed shape, and the strings-only read would have dropped
* the second without a trace. Anything else (or missing) → `[]`. This is
- * OBSERVED data only — we never synthesize sub-queries.
+ * OBSERVED data only — we never synthesize sub-queries. An entry an engine
+ * sent as several searches joined by semicolons ("chatgpt subscription;
+ * gemini subscription") is each of them: a page's heading or FAQ question
+ * written from the fan-out needs one search, not the list.
*/
function normalizeSearchQueries(result, scraperId) {
// Trim on write so the same sub-query never fragments into whitespace
// variants — the #333 aggregation groups by query string. `engine` is only
// kept when it's a non-empty string (never a stray non-string value).
- const toItem = (entry, fallbackEngine) => {
+ const toItems = (entry, fallbackEngine) => {
const query =
typeof entry === 'string' ? entry : typeof entry?.query === 'string' ? entry.query : null;
- if (query === null || query.trim() === '') return null;
+ if (query === null || query.trim() === '') return [];
const engine =
typeof entry?.engine === 'string' && entry.engine.trim() !== ''
? entry.engine.trim()
: fallbackEngine;
- return { query: query.trim(), ...(engine ? { engine } : {}), source_platform: scraperId };
+ return query
+ .split(SEARCH_SEPARATOR)
+ .map((part) => part.trim())
+ .filter(Boolean)
+ .map((part) => ({ query: part, ...(engine ? { engine } : {}), source_platform: scraperId }));
};
const read = (list, fallbackEngine) =>
- Array.isArray(list)
- ? list.map((entry) => toItem(entry, fallbackEngine)).filter((item) => item !== null)
- : [];
+ Array.isArray(list) ? list.flatMap((entry) => toItems(entry, fallbackEngine)) : [];
// Perplexity's field first. An empty one falls through, so it can't hide a
// populated `searchQueries` beside it.
diff --git a/server/src/lib/cloro-scraper.test.js b/server/src/lib/cloro-scraper.test.js
index 8b6498e06..4d77ab833 100644
--- a/server/src/lib/cloro-scraper.test.js
+++ b/server/src/lib/cloro-scraper.test.js
@@ -302,6 +302,51 @@ describe('cloro-scraper – parseScraperResponse', () => {
]);
});
+ it('reads searches an engine joined by semicolons as each search, with its engine', () => {
+ const gemini = parseScraperResponse(
+ {
+ markdown: 't',
+ sources: [],
+ searchQueries: ['ChatGPT subscription;Gemini subscription; Google AIO subscription;'],
+ },
+ 'gemini-web',
+ );
+ expect(gemini.search_queries).toEqual([
+ { query: 'ChatGPT subscription', source_platform: 'gemini-web' },
+ { query: 'Gemini subscription', source_platform: 'gemini-web' },
+ { query: 'Google AIO subscription', source_platform: 'gemini-web' },
+ ]);
+ const perplexity = parseScraperResponse(
+ {
+ markdown: 't',
+ sources: [],
+ search_model_queries: [{ query: 'a; b', engine: 'web' }],
+ },
+ 'perplexity-web',
+ );
+ expect(perplexity.search_queries).toEqual([
+ { query: 'a', engine: 'web', source_platform: 'perplexity-web' },
+ { query: 'b', engine: 'web', source_platform: 'perplexity-web' },
+ ]);
+ });
+
+ it("never splits at an HTML entity's semicolon, and reads 'one;' as 'one', as the editor does", () => {
+ const read = (searchQueries) =>
+ parseScraperResponse(
+ { markdown: 't', sources: [], searchQueries },
+ 'copilot-web',
+ ).search_queries.map((item) => item.query);
+ expect(read(['what&#39;s new in aeo'])).toEqual(['what&#39;s new in aeo']);
+ expect(read(['r&amp;d budget;aeo tools;what&#x27;s aeo'])).toEqual([
+ 'r&amp;d budget',
+ 'aeo tools',
+ 'what&#x27;s aeo',
+ ]);
+ // The same as fanoutQueries('one;') in web/src/lib/content/sources.ts.
+ expect(read(['one;'])).toEqual(['one']);
+ expect(read([' ; '])).toEqual([]);
+ });
+
it('trims surrounding whitespace so a sub-query has one canonical form', () => {
const copilot = parseScraperResponse(
{ markdown: 't', sources: [], searchQueries: [' spaced query '] },
diff --git a/web/src/lib/content/sources.test.ts b/web/src/lib/content/sources.test.ts
index 3f59f5654..89259f352 100644
--- a/web/src/lib/content/sources.test.ts
+++ b/web/src/lib/content/sources.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest';
import {
buildSourceGroups,
+ fanoutQueries,
includedCounts,
normalizeQuery,
pageKey,
@@ -108,6 +109,25 @@ describe('relatedQueries', () => {
});
});
+describe('fanoutQueries', () => {
+ it('splits searches joined by semicolons, and keeps one search as it is', () => {
+ expect(fanoutQueries('a b;c d ; e')).toEqual(['a b', 'c d', 'e']);
+ expect(fanoutQueries('best crm for realtors')).toEqual(['best crm for realtors']);
+ // As the tracker stores it (cloro-scraper.test.js): the search, its semicolon dropped.
+ expect(fanoutQueries('one;')).toEqual(['one']);
+ expect(fanoutQueries(' ; ')).toEqual([]);
+ });
+
+ it('never splits an HTML entity’s semicolon, as the tracker doesn’t', () => {
+ expect(fanoutQueries('what&#39;s new in aeo')).toEqual(['what&#39;s new in aeo']);
+ expect(fanoutQueries('r&amp;d budget;aeo tools;what&#x27;s aeo')).toEqual([
+ 'r&amp;d budget',
+ 'aeo tools',
+ 'what&#x27;s aeo',
+ ]);
+ });
+});
+
describe('buildSourceGroups', () => {
it('lists the prompts, fan-outs, cited pages and related queries, each kind of page named', () => {
const groups = buildSourceGroups(data(), [], draft);
@@ -130,6 +150,90 @@ describe('buildSourceGroups', () => {
expect(prompts.map((p) => p.citesPage)).toEqual([false, true]);
});
+ it('reads a fan-out an engine sent as several searches as each one, and one met twice once', () => {
+ const groups = buildSourceGroups(
+ data({
+ fanouts: [
+ {
+ query: 'ChatGPT subscription;Gemini subscription; Google AIO subscription',
+ platforms: ['gemini-web'],
+ searched: 2,
+ },
+ { query: 'gemini subscription', platforms: ['copilot-web'], searched: 3 },
+ ],
+ }),
+ [],
+ draft,
+ );
+ const fanouts = groups.find((g) => g.kind === 'fanout')!.rows as Extract<
+ DraftSourceRow,
+ { kind: 'fanout' }
+ >[];
+ // The one met twice is the most searched now: first.
+ expect(fanouts.map((f) => [f.name, f.platforms, f.searched])).toEqual([
+ ['Gemini subscription', ['gemini-web', 'copilot-web'], 5],
+ ['ChatGPT subscription', ['gemini-web'], 2],
+ ['Google AIO subscription', ['gemini-web'], 2],
+ ]);
+ });
+
+ it('keeps a joined fan-out’s choice for each search it holds, unless the search has its own', () => {
+ const rows = (choices: Parameters<typeof buildSourceGroups>[1]) =>
+ (
+ buildSourceGroups(
+ data({
+ fanouts: [
+ { query: 'a;b;c', platforms: ['gemini-web'], searched: 4 },
+ { query: 'c', platforms: ['copilot-web'], searched: 1 },
+ { query: 'd;e', platforms: ['gemini-web'], searched: 2 },
+ ],
+ }),
+ choices,
+ draft,
+ ).find((g) => g.kind === 'fanout')!.rows as Extract<DraftSourceRow, { kind: 'fanout' }>[]
+ ).map((f) => [f.name, f.included]);
+ // "a;b;c" was left out: its searches stay out, but "c", also its own row
+ // and left in, stays in; "e" was chosen on its own since.
+ expect(
+ rows([
+ { kind: 'fanout', ref: 'a;b;c', included: false, added: false },
+ { kind: 'fanout', ref: 'd;e', included: false, added: false },
+ { kind: 'fanout', ref: 'e', included: true, added: false },
+ ]),
+ ).toEqual([
+ ['c', true],
+ ['a', false],
+ ['b', false],
+ ['d', false],
+ ['e', true],
+ ]);
+ // Nothing chosen: all in.
+ expect(rows([]).every(([, included]) => included)).toBe(true);
+ });
+
+ it('puts the searches in order of how often they were searched once joined ones are added up', () => {
+ const groups = buildSourceGroups(
+ data({
+ fanouts: [
+ { query: 'x', platforms: ['copilot-web'], searched: 5 },
+ { query: 'y', platforms: ['copilot-web'], searched: 4 },
+ { query: 'a;y', platforms: ['gemini-web'], searched: 3 },
+ ],
+ }),
+ [],
+ draft,
+ );
+ const fanouts = groups.find((g) => g.kind === 'fanout')!.rows as Extract<
+ DraftSourceRow,
+ { kind: 'fanout' }
+ >[];
+ expect(fanouts.map((f) => [f.name, f.searched])).toEqual([
+ ['y', 7],
+ ['x', 5],
+ ['a', 3],
+ ]);
+ });
+
it('keeps a source left out unchecked, and adds the pages and queries added by hand', () => {
const groups = buildSourceGroups(
data(),
diff --git a/web/src/lib/content/sources.ts b/web/src/lib/content/sources.ts
index 333312e5c..12d10dec2 100644
--- a/web/src/lib/content/sources.ts
+++ b/web/src/lib/content/sources.ts
@@ -196,6 +196,26 @@ export function usedIn(
return index >= 0 ? { kind: 'paragraph', index: index + 1 } : null;
}
+/**
+ * Where a fan-out an engine joined splits: at a semicolon, not one that ends
+ * an HTML entity ("what&#39;s", "&amp;"). The same rule as the tracker's
+ * (server/src/lib/cloro-scraper.js, SEARCH_SEPARATOR).
+ */
+const FANOUT_SEPARATOR = /(?<!&#?\w+);/u;
+
+/**
+ * A fan-out as the searches it holds: an engine can send several as one,
+ * joined by semicolons ("chatgpt subscription;gemini subscription"), and a
+ * page's heading or FAQ question needs one search, not the list. Each is
+ * trimmed, and an empty one dropped, as the tracker stores them.
+ */
+export function fanoutQueries(query: string): string[] {
+ return query
+ .split(FANOUT_SEPARATOR)
+ .map((part) => part.trim())
+ .filter(Boolean);
+}
+
/**
* The tab's groups — Prompts · Fan-outs · Cited pages · Search Console — from
* the brand's data and a person's choices: a source left out stays listed,
@@ -229,18 +249,45 @@ export function buildSourceGroups(
citesPage: p.citesPage && !p.inDraft,
}));
- const fanouts: DraftSourceRow[] = data.fanouts.map((f) => {
- const ref = normalizeQuery(f.query);
- return {
+ // An engine's searches sent as one ("a;b;c") are read as each search, and
+ // one met twice as one row: its platforms together, its searches added up.
+ // A search with no choice of its own keeps the one made for the row it was
+ // in (stored under the joined query): left out only when every row it was
+ // in was. The most searched first again, as the brief keeps the first ones.
+ const fanoutRows = new Map<
+ string,
+ { name: string; platforms: Set<string>; searched: number; shown: boolean }
+ >();
+ for (const f of data.fanouts) {
+ const shown = included('fanout', normalizeQuery(f.query));
+ for (const query of fanoutQueries(f.query)) {
+ const ref = normalizeQuery(query);
+ const row = fanoutRows.get(ref);
+ if (row) {
+ for (const platform of f.platforms) row.platforms.add(platform);
+ row.searched += f.searched;
+ row.shown ||= shown;
+ } else {
+ fanoutRows.set(ref, {
+ name: query,
+ platforms: new Set(f.platforms),
+ searched: f.searched,
+ shown,
+ });
+ }
+ }
+ }
+ const fanouts: DraftSourceRow[] = [...fanoutRows]
+ .sort(([, a], [, b]) => b.searched - a.searched)
+ .map(([ref, f]) => ({
kind: 'fanout',
ref,
- name: f.query,
- included: included('fanout', ref),
+ name: f.name,
+ included: choice.get(`fanout:${ref}`)?.included ?? f.shown,
added: false,
- platforms: f.platforms,
+ platforms: [...f.platforms],
searched: f.searched,
- };
- });
+ }));
const pages: DraftSourceRow[] = data.citedPages.map((c) => ({
kind: 'cited_page',