mysql - Django ORM query field weight? -
i'm doing following query:
people.objects.filter( q(name__icontains='carolina'), q(state__icontains='carolina'), q(address__icontains='carolina'), )[:9]
i want first results of query people named "carolina" (and matches other fields, name first). problem don't think way determine field "weight" or "priority".
any idea? thanks!
you'll need 3 queries work:
names_match = people.objects.filter(name__icontains='carolina')[:9] states_match = people.objects.filter(state__icontains='carolina')[:9] addresses_match = people.objects.filter(address__icontains='carolina')[:9] all_objects = list(names_match) + list(states_match) + list(addresses_match) all_objects = all_objects[:9]
there 2 problems approach, worked round:
- it unnecessary queries (what if
names_match
contained enough items already). - it allows duplicates (what if in north carolina called carolina?)
Comments
Post a Comment