Update global search for API changes - #9094
Conversation
| else: | ||
| res["description"] = res["snippet"] | ||
| # Strip " | CFPB" suffix | ||
| res["title"] = re.sub(r" \| .*", "", res["title"]) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Seems reasonable to me! Definitely better than the previous way.
The search.gov API that powers cf.gov global site search has changed in a couple of ways recently:
<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
Removals
How to test this PR
Notes and todos
Checklist