Code

Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#1465 closed enhancement (fixed)

[patch] regular expression field lookups

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

Download all attachments as: .zip

Change History (16)

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

patch against r2487 of trunk to implement regular expression field lookups

comment:1 Changed 8 years ago by adrian

  • priority changed from normal to low
  • Severity changed from normal to minor

comment:2 Changed 7 years ago by SmileyChris

  • Triage Stage changed from Unreviewed to Design decision needed

comment:3 Changed 7 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 7 years ago by Tom Tobin <korpios@…>

Patch aganst r5486 of trunk to implement regex field lookups

comment:4 Changed 7 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 7 years ago by Tom Tobin <korpios@…>

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

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

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

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

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

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

Fixed the patch to apply cleanly after [5519].

Changed 7 years ago by Tom Tobin <korpios@…

Added (yet-untested) oracle support.

comment:7 Changed 7 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 7 years ago by Tom Tobin <korpios@…>

With working oracle support, yay!

comment:8 Changed 7 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 7 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:10 Changed 7 years ago by korpios

  • Reporter changed from Tom Tobin <korpios@…> to Tom Tobin <korpios@…>

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.