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
mapperframework and implement a transformer that addscase:yesto queries if any pattern is mixed-case. Example transformer for lowercasing field names. Roughly, callMapParameterand for the first instance of anyfieldname called""orcontent(which means it's a search pattern) that has a mixed casedvalue, return anAndnode with child parameters, one containing the search pattern, and an additional one that has the fieldcaseand valueyes(this corresponds tocase: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 generatein the directory to generate theschema.gotypes/structs. - Pick a nice name for the option. Emacs uses
search-upper-case, we could call itsearchUpperCase, 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.