Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#2559 closed enhancement (fixed)

[patch] Operators for search_fields

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

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

Download all attachments as: .zip

Change History (7)

Changed 9 years ago by Andy Dustman <farcepest@…>

Implementation

comment:1 Changed 9 years ago by Andy Dustman <farcepest@…>

  • Summary changed from Operators for search_fields to [patch] Operators for search_fields

Changed 9 years ago by Andy Dustman <farcepest@…>

Documentation

Changed 9 years ago by eric@…

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

Changed 9 years ago by eric@…

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

comment:2 Changed 9 years ago by adrian

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

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

comment:3 Changed 8 years ago by QingFeng <paradise.qingfeng@…>

  • Version set to 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