﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
17039	search_fields and multiword searches	Sergiy Kuzmenko	nobody	"Django admin automatically splits query string for search_fields and creates a chained series of filters. For example if ModelAdmin instance contains

{{{
search_fields = ('my_field',)
}}}

and the user searches for ""cool search"", the resulting queryset will look like this:

{{{
qs.filter(my_field__icontains=""cool"").filter(my_field__icontains=""search"")
}}}

translating into SQL

{{{
 ... WHERE my_field LIKE '%cool%' AND my_field LIKE '%search%'
}}}

So far so good. Now if we have anchored or exact search instead:

{{{
search_fields = ('^my_field',)
}}}

Django admin will do exactly the same thing as above and will result in a query like this:

{{{
 ... WHERE my_field LIKE 'cool%' AND my_field LIKE 'search%'
}}}

which is not ever going to find anything because the same field cannot possibly start with two different strings.

For this reason I am proposing to inspect lookup first and don't split query string if exact or anchored lookup is requested. So we would have instead:

{{{
 ... WHERE my_field LIKE 'cool search%'
}}}

The code that need to change is between these two lines:
https://code.djangoproject.com/browser/django/trunk/django/contrib/admin/views/main.py#L362 and
https://code.djangoproject.com/browser/django/trunk/django/contrib/admin/views/main.py#L365
"	Bug	closed	contrib.admin	dev	Normal	duplicate		Sergiy Kuzmenko	Unreviewed	0	0	0	0	1	0
