Skip to content

Update global search for API changes - #9094

Merged
niqjohnson merged 2 commits into
mainfrom
fix/global-search
Jun 8, 2026
Merged

Update global search for API changes#9094
niqjohnson merged 2 commits into
mainfrom
fix/global-search

Conversation

@niqjohnson

Copy link
Copy Markdown
Member

The search.gov API that powers cf.gov global site search has changed in a couple of ways recently:

  1. They've removed custom facets, which we were using to get page language and render better search result descriptions than the default snippet
  2. Something has changed that has re-introduced the " | Consumer Financial Protection Bureau" from page <title>s into search result titles.

This PR removes our handling custom facets and strips the " | CFPB" suffix from search result titles.

See GHE/Design-Development/cfgov/issues/4707 for more details. Also see #8993, #8889, #8865, #8803, #8815, and #8809 for where most of this was added.


Additions

  • Strip out the " | Consumer Financial Protection Bureau" from search result titles

Removals

  • Everything related to custom search.gov facets, which are now no longer indexed or returned in API results

How to test this PR

  1. Do some searches, like http://localhost:8000/search/?q=mortgage and http://localhost:8000/search/?q=bureau
  2. Make sure result titles don't have " | Consumer Financial Protection Bureau" on the end of them as they do in production
  3. Make sure best bets, result descriptions/snippets, result links, result count, and pagination work as they do in production

Notes and todos

  • See the inline note I added to the bit that removes the " | Consumer Financial Protection Bureau" suffix. Is there a better way to do this and still account for all the possibilities?

Checklist

  • PR has an informative and human-readable title
    • PR titles are used to generate the change log in releases; good ones make that easier to scan.
    • Consider prefixing, e.g., "Mega Menu: fix layout bug", or "Docs: Update Docker installation instructions".
  • Changes are limited to a single goal (no scope creep)
  • Code follows the standards laid out in the CFPB development guidelines
  • Future todos are captured in comments and/or tickets

Comment thread cfgov/searchgov/views.py Outdated
else:
res["description"] = res["snippet"]
# Strip " | CFPB" suffix
res["title"] = re.sub(r" \| .*", "", res["title"])

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was trickier than I thought to strip the | Consumer Financial Protection Bureau from the end of search result titles. We used to do it like res["title"] = res["title"][:-39] (see #8993). That mostly worked, but I realized it didn't cover if someone searches for, say, "bureau", which would come back in the API results as | Consumer Financial Protection \ue000Bureau\ue001 and thus leave | in the result title. This regex seems to work fine unless we for some reason happen to have pages with a | somewhere else in their title. We shouldn't have any page titles like that, but if there's a way to improve this regex, I'm all for it. I thought about using a negative lookahead to only capture the last instance, but I wasn't sure if the extra complexity was worth it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me! Definitely better than the previous way.

@wpears wpears left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@niqjohnson
niqjohnson added this pull request to the merge queue Jun 8, 2026
Merged via the queue into main with commit 1f30eeb Jun 8, 2026
11 of 12 checks passed
@niqjohnson
niqjohnson deleted the fix/global-search branch June 8, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants