Skip to content

feat: add opensearch endpoints powered by quicksearch#391

Open
LeoMcA wants to merge 2 commits into
mainfrom
quicksearch-autocomplete
Open

feat: add opensearch endpoints powered by quicksearch#391
LeoMcA wants to merge 2 commits into
mainfrom
quicksearch-autocomplete

Conversation

@LeoMcA

@LeoMcA LeoMcA commented Jun 19, 2026

Copy link
Copy Markdown
Member

Part of mdn/fred#1079

Ports quicksearch in fred into the cloud function, for use from OpenSearch:

  • adds a "suggestions" route to return quicksearch results
  • differs from fred in appending a section of breadcumb to the result to distinguish between pages with the same title where necessary
  • adds a "go" route, to redirect to search, or the actual page if the user has selected a suggestion
  • takes over generating the opensearch.xml from fred, in order to control locales: opted for simplicity here, adding the locale as a query, so the added search engine matches the locale of the page the user adds it from, rather than doing accept-language negotiation at query time
  • adds extensive tests
  • logic ported from fred is clearly commented as so, to make unifying in the future easier
  • adds BASE_URL_MAIN so it's possible to test this locally, with fred and the cloud function running on different ports

@LeoMcA LeoMcA requested a review from globau June 19, 2026 15:01
res
.status(200)
.setHeader("Content-Type", "application/x-suggestions+json; charset=utf-8")
.setHeader("Cache-Control", "public, max-age=3600");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If the search backend fails, this will return HTTP/200 with an empty result that is cached for an hour.

Either return a http error, or don't cache when an error occurs.


return indexResults
.map((i) => index.items[i])
.filter((item) => item !== undefined);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is different from fred, which does:

return indexResults.map((i) => i && (index.items || [])[i]).filter(Boolean);

Which skips the first element. I'm not sure which is correct; it seems non-accidental in fred and has been in prod for a while.

In any event, make sure the funcs in the two repos match, or add a comment explaining the divergence.

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.

3 participants