Opened 12 years ago

Closed 10 years ago

Last modified 10 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: UI/UX:

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@…> 12 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@…> 10 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@…> 10 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@…> 10 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@… 10 years ago.
Added (yet-untested) oracle support.
regex-field-lookups.2.patch (10.7 KB) - added by Tom Tobin <korpios@…> 10 years ago.
With working oracle support, yay!

Download all attachments as: .zip

Change History (16)

Changed 12 years ago by Tom Tobin <korpios@…>

patch against r2487 of trunk to implement regular expression field lookups

comment:1 Changed 12 years ago by Adrian Holovaty

priority: normallow
Severity: normalminor

comment:2 Changed 11 years ago by Chris Beaven

Triage Stage: UnreviewedDesign decision needed

comment:3 Changed 11 years ago by Tom Tobin <korpios@…>

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

Changed 10 years ago by Tom Tobin <korpios@…>

Attachment: regex-field-lookups.diff added

Patch aganst r5486 of trunk to implement regex field lookups

comment:4 Changed 10 years ago by Tom Tobin <korpios@…>

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

Changed 10 years ago by Tom Tobin <korpios@…>

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

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

comment:5 Changed 10 years ago by Tom Tobin <korpios@…>

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

Changed 10 years ago by Tom Tobin <korpios@…>

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

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

comment:6 Changed 10 years ago by Tom Tobin <korpios@…>

Fixed the patch to apply cleanly after [5519].

Changed 10 years ago by Tom Tobin <korpios@…

Attachment: regex-field-lookups.patch added

Added (yet-untested) oracle support.

comment:7 Changed 10 years ago by ian.g.kelly@…

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.

Changed 10 years ago by Tom Tobin <korpios@…>

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

With working oracle support, yay!

comment:8 Changed 10 years ago by Tom Tobin <korpios@…>

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

comment:9 Changed 10 years ago by Jacob

Resolution: fixed
Status: newclosed

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

comment:10 Changed 10 years ago by korpios

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