Django search / filter in views.py using icontains
and gte
, simplified:
def BootstrapFilterView(request):
qs = Table.objects.all()
food_contains_query = request.GET.get('food')
country_contains_query = request.GET.get('country')
price_min_query = request.GET.get('pmin')
qs = qs.filter(food__icontains= food_contains_query)
qs = qs.filter(country__icontains= country_contains_query)
qs = qs.filter(price__gte=price_min_query)
gte
works fine but upon testing icontains
is unsuitably inefficient. Indexing doesn't help for icontains
and I think iexact
might work, but users can't be expected to provide exact matches. I'm bewildered by more advanced options for a task well beyond my understanding and am reluctant to attempt potentially obsolete approaches.
Using Postgres 11.6 with millions of rows, and need multiple optional search criteria. There are thousands of unique food
and all are children of one of dozens of country
.
Django Postgres has full text search but all search criteria are nouns so don't need lexeme conversion but spelling correction (eg. "burito" → "burrito") and synonym matching (eg. "hamburger" → "cheeseburger") are desirable. Is Postgres full text suitable and can this be used with other search criteria of gte
and similar numeric operations?
What's a modern and practical way to improve performance?