Repository navigation
fix(visibility): count names that start or end outside ASCII letters - #890
Merged
Merged
Conversation
Mentions were matched with `\b${name}\b`. JavaScript's `\b` only knows
ASCII word characters, so a brand or competitor whose name starts or ends
with an accented letter, a non-Latin script or punctuation ("Émile",
"C++", "Acme, Inc.") was never counted. Every answer naming it was stored
with zero mentions and no position.
- nameRegex() replaces `\b` with Unicode letter/number lookarounds, used
by both countOccurrences and firstOccurrenceIndex. A boundary is only
required on a side where the name ends in a word character.
- Scripts written without spaces (Chinese, Japanese, Thai...) and Korean,
whose particles attach to the noun, get no boundary: the name is always
flanked by other letters there.
- backfill-mention-counts.js re-runs parseResponse over stored answers for
brands whose own or competitor names are affected, and rewrites the
mention counts, visibility scores and positions. Stored sentiment is
kept. Rows whose values do not change are skipped.
Closes #871
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Brand and competitor mentions were matched with
\b${name}\b. JavaScript's\bonly treats ASCII[A-Za-z0-9_]as word characters, so a name that starts or ends with anything else was never counted. Affected names include accented or dotted letters ("Ümit", "İpek"), non-Latin scripts, and trailing punctuation ("C++", "Acme, Inc."). Every answer naming such a brand was stored with zero mentions and no mention position, so its visibility read close to zero.In production this affects 9 of 183 brands and 47 of 1,231 competitors. For the most affected active brand, the name appears in about 9,200 of 25,000 stored answers, but only about 800 were counted as mentions.
Change
nameRegex()inresponse-parser.jsreplaces\bwith Unicode letter/number lookarounds (uflag). BothcountOccurrencesandfirstOccurrenceIndexuse it. A boundary is only required on a side where the name ends in a word character, so names ending in punctuation match.scripts/backfill-mention-counts.jsre-runsparseResponseover stored answers. It rewritesmention_count,visibility_score,mention_position,mentioned_entity_countand the matching fields of existingcompetitor_mentionsentries.--brand <id>narrows it,--dry-runwrites nothing.neutralthey were stored with; re-analysing them is a separate decision.backfill-insights-daily.jscommand for each changed brand.Dry run against production (read only)
Related issue
Closes #871
Type of change
How to test
yarn testfromserver/. The newnames outside ASCII word characters (#871)cases cover accented and dotted names, trailing punctuation, CJK and Korean names, names inside longer words (no match), and mention positions.node src/scripts/backfill-mention-counts.js --brand <id> --dry-runagainst a brand with an affected name.Rollout
node src/scripts/backfill-mention-counts.js.INSIGHTS_BACKFILL_BRAND=<id> node src/scripts/backfill-insights-daily.jscommands to refresh the rollups.Checklist
yarn lint,yarn format:checkandyarn test(897 passed) pass fromserver/🤖 Generated with Claude Code