Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7k
Align SearchFilter behaviour to django.contrib.admin search#9017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
auvipy commentedJun 23, 2023
looks like a nice improvment |
Uh oh!
There was an error while loading.Please reload this page.
auvipy commentedJun 23, 2023
can we avoid at least one breaking change
|
sevdog commentedJun 23, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This could be interesting, however it should be defined the order of split logics due to how '"hello, world" can I,help you'Withonly ['hello, world','can','I,help','you'] Maybe a good compromise would be:
With this logic the first search whould become ['hello, world','can','I' ,'help','you'] There is anedge case: what to do if there are one or more commas before or after a quoted sentence? ',"hello, world", what to,,do,?'I belive that in this case it would be nice tostrip commas from tokens extracted by The generator to handle this iteration whould be something like: defsearch_smart_split(search_terms):forterminsmart_split(search_terms):term=term.strip(',')ifterm.startswith(('"',"'"))andterm[0]==term[-1]:yieldunescape_string_literal(term)else:yieldfrom (sub_termforsub_terminterm.split(',')ifsub_term) This should parse the latter term into: ['hello, world','what','to','do','?'] |
sevdog commentedJun 23, 2023
Testing the previous approach I encountered an other case which I did not considered before. What to do when there is a quoted phrase followed by other characters: '"hello, world",found'The ['"hello',' world"','found'] The whitespace is easy and intuitive to remove (IMO), but I am not sure if in this case also the quotes should be removed (thus using |
auvipy commentedJun 24, 2023
are we going to preserve the old way or going to have option for both new and old ways? |
sevdog commentedJun 28, 2023
It depends on which mechanism are we willing to provide to select this behaviour. I can think these:
|
auvipy commentedJul 13, 2023
from the tests it seems that both type of search is supported in this PR, right? I would like to consider this improvement for 3.15 release |
sevdog commentedJul 13, 2023
Yes, |
| returnvalue | ||
| defdistinct(queryset,base): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
can we change this in a separate PR? or it is part of the change in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
It could be splitted, however this method was introduced inb4b2dc1 only for the search class and putted intocompact package in the hope of being re-used.
IMO this should be kept togheter with the rest of the PR since this change goes in the same direction of "align the behaviour with django".
I just noticed that the code I used (which was introduced indjango/django@1871182) has just been removed from the main branch indjango/django@d569c1d. So the whole thing may just be changed to use.distinct() like django is going to do.
PS: I really do not understand why 8 years ago there was the need to have a different implementation of distinct only for Oracle engine and why this was implemented here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
PS: I really do not understand why 8 years ago there was the need to have a different implementation of distinct only for Oracle engine and why this was implemented here.
at that time django oracle back end was not properly maintained. but now it is
docs/api-guide/filtering.md Outdated
| search_fields = ['data__breed', 'data__owner__other_pets__0__name'] | ||
| By default, searches will use case-insensitive partial matches. The search parameter may contain multiple search terms, which should be whitespaceand/or commaseparated. If multiple search terms are used then objects will be returned in the list only if all the provided terms are matched. | ||
| By default, searches will use case-insensitive partial matches. The search parameter may contain multiple search terms, which should be whitespace separated. If multiple search terms are used then objects will be returned in the list only if all the provided terms are matched. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
do we need further enhancement of the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I will add some examples about search term and how it will get parsed.
Uh oh!
There was an error while loading.Please reload this page.
auvipy commentedJul 25, 2023
do you intend to add anything else here or improve anything else? |
sevdog commentedJul 25, 2023
As of now I belive that this should be fine. I tried to figure out what could have been added to the docs, but I felt that it was just copy-pasting fron django admin docs without adding any value. |
)* Use subquery to remove duplicates in SearchFilter* Align SearchFilter behaviour to django.contrib.admin* Add compatibility with older django/python versions* Allow search to split also by comma after smart split* Use generator to build search conditions to reduce iterations* Improve search documentation* Update docs/api-guide/filtering.md---------Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
lovelydinosaur commentedMar 22, 2024
Really nice bit of functionality, thanks... have followed up with#9338. |
Description
Make
SearchFilterbehave more likedjango.contrib.adminsearch (which is already stated in docs).search_fields"the text","the \"text\"")See#8205