Django

Code

Ticket #1465 (closed: fixed)

Opened 2 years ago

Last modified 1 year ago

[patch] regular expression field lookups

Reported by: Tom Tobin <korpios@korpios.com> Assigned to: adrian
Milestone: Component: Core framework
Version: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

The attached patch implements regular expression field lookups against r2487 of trunk.

The lookups are performed via "fieldname__regex" or "fieldname__iregex" for case-sensitive and -insensitive matching, respectively.

Only PostgreSQL implements case-sensitive matching; for all other databases, case-insensitive matching is performed regardless of which type is specified.

Only PostgreSQL (assuming system defaults) and sqlite implement PCRE-ish "advanced" regular expressions; the other databases only support POSIX "extended" regular expressions.

MSSQL/Transact-SQL does not implement regular expressions (as far as I can tell from the documentation available at MSDN); attempting to use regex or iregex field lookups with this backend will raise a NotImplementedError.

Regular expression searches can be performed through the admin interface by prepending and appending a slash ("/") character to the search term (e.g., /like this/). This is backwards-incompatible, but with a low chance of collision with existing usage (i.e., it's unlikely that a user is going to input a search phrase both beginning and ending with a slash; I considered adding a toggle for this behavior in settings.py, but decided against it for the time being).

Attachments

trunk-regex_field_lookup.diff (5.0 kB) - added by Tom Tobin <korpios@gmail.com> on 03/04/06 15:08:35.
patch against r2487 of trunk to implement regular expression field lookups
regex-field-lookups.diff (7.1 kB) - added by Tom Tobin <korpios@korpios.com> on 06/17/07 22:29:50.
Patch aganst r5486 of trunk to implement regex field lookups
regex-field-lookups.2.diff (10.9 kB) - added by Tom Tobin <korpios@korpios.com> on 06/18/07 21:42:17.
Patch aganst r5490 of trunk to implement regex field lookups, w/docs, w/tests
regex-field-lookups.3.diff (10.2 kB) - added by Tom Tobin <korpios@korpios.com> on 06/23/07 19:32:30.
Patch aganst r5519 of trunk (post-oracle-merge) to implement regex field lookups
regex-field-lookups.patch (10.5 kB) - added by Tom Tobin <korpios@korpios.com on 06/26/07 11:43:49.
Added (yet-untested) oracle support.
regex-field-lookups.2.patch (10.7 kB) - added by Tom Tobin <korpios@korpios.com> on 06/26/07 12:57:04.
With working oracle support, yay!

Change History

03/04/06 15:08:35 changed by Tom Tobin <korpios@gmail.com>

  • attachment trunk-regex_field_lookup.diff added.

patch against r2487 of trunk to implement regular expression field lookups

04/14/06 14:57:00 changed by adrian

  • priority changed from normal to low.
  • severity changed from normal to minor.

01/23/07 22:17:44 changed by SmileyChris

  • stage changed from Unreviewed to Design decision needed.

01/24/07 12:11:21 changed by Tom Tobin <korpios@gmail.com>

IIRC, the core developers liked the idea but disliked the admin regex searches. I'll create an updated patch against current trunk if I know what behavior to implement. :)

06/17/07 22:29:50 changed by Tom Tobin <korpios@korpios.com>

  • attachment regex-field-lookups.diff added.

Patch aganst r5486 of trunk to implement regex field lookups

06/17/07 22:32:36 changed by Tom Tobin <korpios@korpios.com>

I've brought the patch for this ticket's implementation up to date; documentation is now included, as well as full support for both case sensitive and insensitive matching on the supported platforms (MySQL, PostgreSQL, and sqlite).

06/18/07 21:42:17 changed by Tom Tobin <korpios@korpios.com>

  • attachment regex-field-lookups.2.diff added.

Patch aganst r5490 of trunk to implement regex field lookups, w/docs, w/tests

06/18/07 21:43:03 changed by Tom Tobin <korpios@korpios.com>

The latest incarnation of the patch now has tests, as well.

06/23/07 19:32:30 changed by Tom Tobin <korpios@korpios.com>

  • attachment regex-field-lookups.3.diff added.

Patch aganst r5519 of trunk (post-oracle-merge) to implement regex field lookups

06/23/07 19:33:29 changed by Tom Tobin <korpios@korpios.com>

Fixed the patch to apply cleanly after [5519].

06/26/07 11:43:49 changed by Tom Tobin <korpios@korpios.com

  • attachment regex-field-lookups.patch added.

Added (yet-untested) oracle support.

06/26/07 12:37:24 changed by ian.g.kelly@gmail.com

Initially I got this error:

      File "/home/ikelly/projects/django.trunk/django/db/models/query.py", line 802, in get_where_clause
        if settings.DATABASE_ENGINE == 'oracle':
    NameError: global name 'settings' is not defined

After adding the appropriate import statement, the test cases passed and I didn't find any bugs.

06/26/07 12:57:04 changed by Tom Tobin <korpios@korpios.com>

  • attachment regex-field-lookups.2.patch added.

With working oracle support, yay!

06/26/07 12:59:54 changed by Tom Tobin <korpios@korpios.com>

I think we're all set with the latest version of the patch. Requesting final review and (hopefully) commit. ^_^

06/27/07 13:58:10 changed by jacob

  • status changed from new to closed.
  • resolution set to fixed.

(In [5555]) Fixed #1465: added support for regex lookups. Thanks, Tom Tobin.

07/12/07 12:56:52 changed by korpios

  • reporter changed from Tom Tobin <korpios@gmail.com> to Tom Tobin <korpios@korpios.com>.

Add/Change #1465 ([patch] regular expression field lookups)




Change Properties
Action