Opened 16 years ago
Last modified 15 years ago
#11220 closed
__similar in filter — at Initial Version
Reported by: | Filip Gruszczyński | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | 1.0 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I would like to propose a new filtering method for char fields, that could be used instead of exact or iexact. similar would return models, which field is similar to the given string. Example use case looks like this: user wants to search for some term, so we try to find objects, that satisfy his query.
objects = Klass.objects.filter(name__iexact=user_term) if objects.count() > 0: return render_to_response('found.html', {'objects': 'objects'}) else: names = Klass.objects.filter(name__similar=user_term).values('name') return render_to_response('did_you_mean.html', {'names': names})
If he inputs name, that can't be found, we try to find to some suggestions, like Google does. I don't really know, if databases support this kind of operations. Could this be done? If it can be done and someone could point me, where I should start, I could try to create a patch.