Skip to content

Literal search by default

Warren Gifford requested to merge fa/literal-search-new into master

Created by: attfarhan

This PR implements RFC 31: Literal search by default.

The changes made in this PR are as follows:

GraphQL API

This PR updates the search GraphQL API field to accept two new, optional parameters: version and patternType.

version defaults to V1 if not passed, so existing scripts, src-cli, and other clients that aren't upgraded will continue to work.

patternType is an optional parameter passed, which will override version when determining which pattern type to use. There is a new enum called SearchPatternType which specs the valid values, which are currently regexp and literal.

Go backend

The search GraphQL API resolver was updated to accept the version and patternType parameters. The resolver now checks whether a query should be interpreted as literal or regular expression. It does this via checking versions (V1 = regexp, V2 = literal). Then, it checks whether the patternType parameter has a value, and uses this to override the configuration it determined via the version parameter. Finally, it calls the new HandlePatternType() function, which checks for the patternType: field in the query, and if so, will override both the version and patternType parameters.

HandlePatternType() will then convert the query from regex to literal if necessary.

Webapp

The webapp now has a new query parameter patternType=, which determines the pattern type to be used for a query on search routes. This is the source of truth for what will be passed as the patternType parameter to the search GraphQL endpoint, for search requests coming from the webapp. All searches on the webapp will have a patternType= query parameter.

The search input now has a regexp toggle, which, when clicked, will toggle the patternType= query parameter in the URL.

There is also a new setting, search.defaultPatternType, which can configure the default pattern type for an instance or user.

Because the patternType query parameter is now required for all search routes, the buildSearchURLQuery function has been updated to take an additional patternType parameter. This forces all components to specify the patternType before navigating to the search results page.

The buildSearchURLQuery function will check if the patternType: field exists in the raw query, and if so, will use that value in the patternType= URL query parameter, overriding the patternType argument passed into the function. This means that queries with the patternType: field in them will have the filter removed from the query, and the value will be reflected in the URL query parameter.

For URLs that do not have a patternType= query parameter, the SearchResults page component will detect that, and redirect to a URL appending patternType=regexp. This ensures that old links continue to work. This also updates the regexp toggle to accurately show the active state.

There is also a new pop-up toast LiteralSearchToast that appears for a user visiting the instance for the first time. The pop-up tells the user that there is a new regexp toggle, and that searches are now non-regexp by default, and links to the docs page. Once dismissed, it will not appear again for the user.

Browser extension

The browser extension's omnibar search is updated to pass literal as the patternType parameter to to buildSearchURLQuery. Omnibar search users can override this by including patternType:regexp in their query.

Saved searches

A migration was added to append patternType:regexp to all existing saved searches on startup. This is to avoid saved searches breaking due to any ambiguity about the patternType, which could arise if the instance/user defaults are changed.

The createSavedSearch and updateSavedSearch endpoints will throw an error, displayed in the saved search form, if a user tries to create a saved search without a patternType parameter.

Testing:

  • I added e2e tests for the regexp toggle.
  • There are unit tests for the Go backend.
  • Existing search tests were updated, with either "patternType:regexp" or "V1" passed to maintain the old testing behavior.

I would encourage reviewers to pull down this branch and stress test any of these changes since it is a wide surface area.

Merge request reports

Loading