Django

Code

Ticket #6933 (new)

Opened 8 months ago

Last modified 5 months ago

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

Reported by: Martín Conte Mac Donell <Reflejo@gmail.com> Assigned to: diafour
Milestone: Component: django.contrib.admin
Version: newforms-admin Keywords: nfa-someday yandex-sprint ep2008
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 0

Description (Last modified by ramiro)

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

django-6933-0.diff (0.9 kB) - added by diafour on 07/12/08 07:40:12.
django-6933-0.2.diff (0.9 kB) - added by diafour on 07/12/08 08:25:23.
django-6933-0.3.diff (0.9 kB) - added by diafour on 07/12/08 08:27:07.
django-6933-1.diff (1.9 kB) - added by diafour on 07/12/08 09:15:45.

Change History

06/09/08 17:04:27 changed by Karen Tracey <kmtracey@gmail.com>

  • keywords set to nfa-someday.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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

06/16/08 16:09:16 changed by ramiro

  • description changed.

07/12/08 04:22:42 changed by diafour

  • owner changed from nobody to diafour.

07/12/08 07:40:12 changed by diafour

  • attachment django-6933-0.diff added.

07/12/08 07:52:49 changed by diafour

  • keywords changed from nfa-someday to nfa-someday yandex-sprint.
  • has_patch set to 1.

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"'.

07/12/08 08:25:23 changed by diafour

  • attachment django-6933-0.2.diff added.

07/12/08 08:27:07 changed by diafour

  • attachment django-6933-0.3.diff added.

07/12/08 08:27:56 changed by diafour

Fix tabs in a patch.

07/12/08 08:31:27 changed by Honza_Kral

  • needs_better_patch set to 1.
  • stage changed from Unreviewed to Accepted.
  • needs_docs set to 1.

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

07/12/08 08:57:47 changed by diafour

New patch use smart_split from django.utils.text.

07/12/08 09:15:45 changed by diafour

  • attachment django-6933-1.diff added.

07/12/08 09:16:50 changed by diafour

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

07/12/08 09:21:32 changed by Honza_Kral

  • keywords changed from nfa-someday yandex-sprint to nfa-someday yandex-sprint ep2008.
  • needs_better_patch deleted.
  • stage changed from Accepted to Ready for checkin.
  • needs_docs deleted.

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

07/18/08 09:31:15 changed by russellm

  • needs_tests set to 1.
  • stage changed from Ready for checkin to Accepted.

Add/Change #6933 (You cannot search with spaces if search_fields is declared with "^")




Change Properties
Action