Implement search options to enable more performant queries #2752
+73
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Address issue: #2745
Change
Add the following config options to better control how administrate generates search queries targeting a given field:
search_exact
true
: the search will be performed using an equality comparisonfalse (default)
: the search will be performed using a substring search as... LIKE '%your-search-term%'
search_lower
true (default)
: search terms and target columns are lowercasedfalse
: search terms and target columns retain their original casingThis change also introduces
search_requires_string_cast?
onField
classes to avoid casting search columns withCAST(... AS CHAR(256))
when the casting is redundant (ie. for string-like columns).The defaults for all of the above have been set so as to retain existing behaviour by default.
Usage/Rationale
search_exact
allows users to support exact searches (for eg. an email address, a phone number, a postal code), in cases where substring matching isn't applicable and/or incurs too heavy a performance penalty on the db side when dealing with fairly large data setssearch_lower
controls whether or not we lowercase the term and column being compared; this both adds support for case-sensitive searching as well as allows folks to disable theLOWER(...)
clause in the generated query to avoid having to support it with extraneous db indices (eg. when searching for a phone number or zip code)