#11220: __similar in filter ------------------------------------+--------------------------------------- Reporter: gruszczy | Owner: nobody Status: new | Milestone: Component: Uncategorized | Version: 1.0 Resolution: | Keywords: Stage: Unreviewed | Has_patch: 0 Needs_docs: 0 | Needs_tests: 0 Needs_better_patch: 0 | ------------------------------------+--------------------------------------- Changes (by Alex):
* needs_better_patch: => 0 * needs_tests: => 0 * needs_docs: => 0 Old 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. New 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. Comment: Fixed formatting, please use preview. -- Ticket URL: <http://code.djangoproject.com/ticket/11220#comment:1> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---