Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement search options to enable more performant queries #2752

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

FabriceCastel
Copy link

@FabriceCastel FabriceCastel commented Jan 9, 2025

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 comparison
    • false (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 lowercased
    • false: search terms and target columns retain their original casing

This change also introduces search_requires_string_cast? on Field classes to avoid casting search columns with CAST(... 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 sets
  • search_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 the LOWER(...) 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)

@FabriceCastel FabriceCastel marked this pull request as ready for review January 9, 2025 18:41
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.

1 participant