2

There are a few non-ascii characters in Turkish language like "İ, ş, ğ, ü, ö, ı" etc. "İ" is a uppercase form of "i" in latin alphabet.

Search terms don't match if there is an "İ" in it. But other letters works perfectly fine. For instance, "İnşaat" (it means construction in TR) doesn't match, but "inşaat" does. And strangely, It only happens in Heroku Django server. Localhost matches both of them.

Django==2.1.4 python==3.6.8

HTML form:

<form class="form-inline ml-3" method="GET" action="{% url 'customer:searchcustomer' %}">
    <div class="input-group input-group-sm">
        <input class="form-control form-control-navbar" type="search" placeholder="Search Customer..." aria-label="Search" name="searchterm" required="">
        <div class="input-group-append">
            <button class="btn btn-navbar" type="submit">
                <i class="fa fa-search"></i>
            </button>
        </div>
    </div>
</form>

views.py

def search_customer(request):
    query = request.GET.get("searchterm")
    if query and len(query)>2 and len(query)<25:
        customer_list = Customer.objects.filter(
            Q(customer_name__icontains=query)|
            Q(customer_address__icontains=query)).order_by("-pk").distinct()

Is it some kind of bug or is there anything that I'm missing?

snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
orhanodabasi
  • 962
  • 7
  • 11
  • Lower casing some Turkish characters doesn't work, so the case-insensitive search is probably the problem. It might help to know which databases, and versions you use locally and in heroku. Also python and django versions – snakecharmerb Aug 20 '20 at 08:26
  • local postgres version: 10.12 heroku postgres version: 10.13 I mentioned python and django versions in the post – orhanodabasi Aug 20 '20 at 08:52
  • Related https://stackoverflow.com/a/24295829/5320906 – snakecharmerb Aug 20 '20 at 11:49

1 Answers1

0

Use unaccent. In docs: https://docs.djangoproject.com/en/4.2/ref/contrib/postgres/lookups/#unaccent

Example:

>>> City.objects.filter(name__unaccent="México")
['<City: Mexico>']

>>> User.objects.filter(first_name__unaccent__startswith="Jerem")
['<User: Jeremy>', '<User: Jérémy>', '<User: Jérémie>', '<User: Jeremie>']