Opened 17 years ago

Closed 4 years ago

#6933 closed New feature (fixed)

You cannot search with spaces if search_fields is declared with "^"

Reported by: Martín Conte Mac Donell <Reflejo@…> Owned by: Alix Léger
Component: contrib.admin Version: newforms-admin
Severity: Normal Keywords: nfa-someday yandex-sprint ep2008
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Ramiro Morales)

That is. When search_fields is declared to "starts with" you cannot perform queries with spaces.

File contrib/admin/views/main.py; Line 326:

for bit in self.query.split():
    or_queries = [models.Q(**{construct_search(field_name): bit}) for field_name in self.search_fields]
    other_qs = QuerySet(self.model)
    (...)
    qs = qs & other_qs

So, if for example i'm looking for "Hey dud" query will be:

qs.filter(field__startswith="Hey") & qs.filter(field__startswith("dud"))

Attachments (4)

django-6933-0.diff (909 bytes ) - added by diafour 16 years ago.
django-6933-0.2.diff (957 bytes ) - added by diafour 16 years ago.
django-6933-0.3.diff (892 bytes ) - added by diafour 16 years ago.
django-6933-1.diff (1.9 KB ) - added by diafour 16 years ago.

Download all attachments as: .zip

Change History (23)

comment:1 by Karen Tracey <kmtracey@…>, 16 years ago

Keywords: nfa-someday added

Code is same here on trunk and nfa, this should not block merge.

comment:2 by Ramiro Morales, 16 years ago

Description: modified (diff)

comment:3 by diafour, 16 years ago

Owner: changed from nobody to diafour

by diafour, 16 years ago

Attachment: django-6933-0.diff added

comment:4 by diafour, 16 years ago

Has patch: set
Keywords: yandex-sprint added

django-6933-0.diff patch gives ability to use search strings with spaces.

You can define such strings with '"' (like google):

'hey dud' interprets like qs.filter(fieldstartswith="Hey") & qs.filter(fieldstartswith("dud"))

and '"hey dud"' interprets like qs.filter(fieldstartswith="hey dud")

The algorithm is very basic and don't check a string for paired quotes. So '"hey dud' works like '"hey dud"'.

by diafour, 16 years ago

Attachment: django-6933-0.2.diff added

by diafour, 16 years ago

Attachment: django-6933-0.3.diff added

comment:5 by diafour, 16 years ago

Fix tabs in a patch.

comment:6 by Honza Král, 16 years ago

Needs documentation: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Please take a look at django.utils.text.smart_split for the splitting tool. And document this feature.

comment:7 by diafour, 16 years ago

New patch use smart_split from django.utils.text.

by diafour, 16 years ago

Attachment: django-6933-1.diff added

comment:8 by diafour, 16 years ago

django-6933-1.diff patch updated with addition to docs/model-api.txt

comment:9 by Honza Král, 16 years ago

Keywords: ep2008 added
Needs documentation: unset
Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

thanks diafour. I just think that the doc patch should reffer to docs/admin.txt, but that's probably just a minor glitch

comment:10 by Russell Keith-Magee, 16 years ago

Needs tests: set
Triage Stage: Ready for checkinAccepted

comment:11 by Julien Phalip, 14 years ago

Severity: Normal
Type: Uncategorized

#15203 was closed as a dupe. It reports the same problem but when the field name starts with =. It has a much more current patch too.

comment:12 by Julien Phalip, 14 years ago

Type: UncategorizedBug

comment:13 by Karen Tracey, 13 years ago

Easy pickings: unset
Needs documentation: set
Type: BugNew feature
UI/UX: unset

#17039 reported this again. Also given the current behavior is documented (https://docs.djangoproject.com/en/1.3/ref/contrib/admin/#django.contrib.admin.ModelAdmin.search_fields) I'd call this ticket a new feature, not a bug. Also, I don't see that the doc mentioning the inability to search exactly on phrases with spaces is changed by the newest patch here so I think there is some doc change needed in addition to what is added by the patch.

comment:14 by Lev Lybin, 6 years ago

Django 2.1.7 same behavior.

in reply to:  description comment:15 by Alix Léger, 4 years ago

Last edited 4 years ago by Alix Léger (previous) (diff)

comment:16 by Mariusz Felisiak, 4 years ago

Needs documentation: unset
Needs tests: unset
Owner: changed from diafour to Alix Léger
Status: newassigned

comment:17 by Mariusz Felisiak, 4 years ago

Patch needs improvement: set

comment:18 by Mariusz Felisiak, 4 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:19 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In 26a41350:

Fixed #6933 -- Added support for searching against quoted phrases in ModelAdmin.search_fields.

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