Opened 18 years ago

Closed 18 years ago

Last modified 17 years ago

#2559 closed enhancement (fixed)

[patch] Operators for search_fields

Reported by: Andy Dustman <farcepest@…> Owned by: Adrian Holovaty
Component: contrib.admin Version: dev
Severity: normal Keywords:
Cc: farcepest@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently, search_fields in Admin always do an icontains search, i.e. ILIKE %...% search where ... is the search term. This is inefficient and undesirable in many cases because you cannot use an index and the database must search all rows.

The following patch (to be attached) extends this to add the following prefix operators and corresponding searches:

  • ^: istartswith
  • =: iexact
  • @: search (full-text)
  • no prefix: icontains (current behavior)

My tests indicate ^ makes my searches a lot faster. However, if there is at least one search field without a prefix, the database will still have to check every row.

Attachments (4)

django-search_fields-operators.diff (1.3 KB ) - added by Andy Dustman <farcepest@…> 18 years ago.
Implementation
django-search_fields-operators-docs.diff (1.3 KB ) - added by Andy Dustman <farcepest@…> 18 years ago.
Documentation
django-search_fields-operators_pre_magic_removal.diff (1.4 KB ) - added by eric@… 18 years ago.
The same patch back-ported to the pre-magic-removal tag (changeset r2808)
django-search_fields-operators-docs_pre_magic_removal.diff (1.3 KB ) - added by eric@… 18 years ago.
The same patch back-ported to the pre-magic-removal tag (changeset r2808)

Download all attachments as: .zip

Change History (7)

by Andy Dustman <farcepest@…>, 18 years ago

Implementation

comment:1 by Andy Dustman <farcepest@…>, 18 years ago

Summary: Operators for search_fields[patch] Operators for search_fields

by Andy Dustman <farcepest@…>, 18 years ago

Documentation

by eric@…, 18 years ago

The same patch back-ported to the pre-magic-removal tag (changeset r2808)

by eric@…, 18 years ago

The same patch back-ported to the pre-magic-removal tag (changeset r2808)

comment:2 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: newclosed

(In [3601]) Fixed #2559 -- Added cool new operators for Admin.search_fields, plus documentation. Thanks, Andy Dustman.

comment:3 by QingFeng <paradise.qingfeng@…>, 17 years ago

Version: SVN

search_fields one filed multivalue search bug?
http://code.djangoproject.com/ticket/4977

Note: See TracTickets for help on using tickets.
Back to Top