Opened 19 years ago

Closed 17 years ago

Last modified 17 years ago

#1465 closed enhancement (fixed)

[patch] regular expression field lookups

Reported by: Tom Tobin <korpios@…> Owned by: Adrian Holovaty
Component: Core (Other) Version:
Severity: minor Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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 (6)

trunk-regex_field_lookup.diff (5.0 KB ) - added by Tom Tobin <korpios@…> 19 years ago.
patch against r2487 of trunk to implement regular expression field lookups
regex-field-lookups.diff (7.1 KB ) - added by Tom Tobin <korpios@…> 17 years ago.
Patch aganst r5486 of trunk to implement regex field lookups
regex-field-lookups.2.diff (10.9 KB ) - added by Tom Tobin <korpios@…> 17 years ago.
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@…> 17 years ago.
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@… 17 years ago.
Added (yet-untested) oracle support.
regex-field-lookups.2.patch (10.7 KB ) - added by Tom Tobin <korpios@…> 17 years ago.
With working oracle support, yay!

Download all attachments as: .zip

Change History (16)

by Tom Tobin <korpios@…>, 19 years ago

patch against r2487 of trunk to implement regular expression field lookups

comment:1 by Adrian Holovaty, 19 years ago

priority: normallow
Severity: normalminor

comment:2 by Chris Beaven, 18 years ago

Triage Stage: UnreviewedDesign decision needed

comment:3 by Tom Tobin <korpios@…>, 18 years ago

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. :)

by Tom Tobin <korpios@…>, 17 years ago

Attachment: regex-field-lookups.diff added

Patch aganst r5486 of trunk to implement regex field lookups

comment:4 by Tom Tobin <korpios@…>, 17 years ago

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).

by Tom Tobin <korpios@…>, 17 years ago

Attachment: regex-field-lookups.2.diff added

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

comment:5 by Tom Tobin <korpios@…>, 17 years ago

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

by Tom Tobin <korpios@…>, 17 years ago

Attachment: regex-field-lookups.3.diff added

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

comment:6 by Tom Tobin <korpios@…>, 17 years ago

Fixed the patch to apply cleanly after [5519].

by Tom Tobin <korpios@…, 17 years ago

Attachment: regex-field-lookups.patch added

Added (yet-untested) oracle support.

comment:7 by ian.g.kelly@…, 17 years ago

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.

by Tom Tobin <korpios@…>, 17 years ago

Attachment: regex-field-lookups.2.patch added

With working oracle support, yay!

comment:8 by Tom Tobin <korpios@…>, 17 years ago

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

comment:9 by Jacob, 17 years ago

Resolution: fixed
Status: newclosed

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

comment:10 by korpios, 17 years ago

Reporter: changed from Tom Tobin <korpios@…> to Tom Tobin <korpios@…>
Note: See TracTickets for help on using tickets.
Back to Top