Skip to content

Add search option where mixed-case patterns imply case-sensitivity

Created by: rvantonder

By default all regexp searches are case-insensitive (AKA "case-folding", reference). When the toggle is activated, or case:yes is specified, patterns become case-sensitive (case-folding is disabled).

Some editors, like emacs, will make the search case-sensitive if the search string includes upper-case letters (i.e., the string is mixed-case) by default. Many users may find this convenient and preferable.

However, historical search usage of Sourcegraph shows that we should keep the current case-folding by default, and not behave any differently for the mixed-case emacs example above. That said, having the option would be a nice feature to have, via a setting that can be enabled individually by users, orgs, or the entire site.

This issue tracks adding an option that interprets mixed-case search patterns as implying case-sensitivity.

Implementation guidance:

  • Use the new query mapper framework and implement a transformer that adds case:yes to queries if any pattern is mixed-case. Example transformer for lowercasing field names. Roughly, call MapParameter and for the first instance of any field name called "" or content (which means it's a search pattern) that has a mixed cased value, return an And node with child parameters, one containing the search pattern, and an additional one that has the field case and value yes (this corresponds to case:yes, and will make the query case-sensitive).
  • Test the case transformer code works with unit tests at this point, before going further.
  • Add an option that can be accessed by user/org/site settings that enables the feature above, see example PR that adds such a setting. The setting should go in schema/settings.schema.json and then run go generate in the directory to generate the schema.go types/structs.
  • Pick a nice name for the option. Emacs uses search-upper-case, we could call it searchUpperCase, or something else.
  • To see the results in the web frontend, you will need to add the following to your site config:
{"experimentalFeatures": {"andOrQuery": "enabled"}}

as well as the new configuration option.