Calibre-web: The search does not work correctly for the Russian language

Created on 13 Oct 2017  路  8Comments  路  Source: janeczku/calibre-web

Hello! Thanks for your work!
I noticed search bug for the Russian language.
When I'm looking for a book with a name in Russian with an entry, for example, "way", then I don't find the book "Way". Similarly, for the author, the search for "emily" doesn't find "Emily".
The search is case sensitive.

bug

All 8 comments

Theoretically the fix must be trivial -- in SQLAlchemy the case-insensitive searches are implemented by .ilike() method. So in web.py/search_feed all .like() method calls must be replaced with .ilike() calls. I will check at home and if it works create a PR.

Well, not that trivial. There is one more than one search method and ilike somehow does not work. Will try to dig in...

Well, bad news. It is a limitation of SQLite (functions lower() and upper() do not really work for non-ASCII characters). There is a way to enable that -- include a special extension, called "ICU" into the sqlite access layer. Calibre-web uses standard python sqlite3, and sqlite3 by default does not include ICU, so case insesnitive search for all other than ASCII won't be possible without a more deep rework. In Calibre itself it works, because Calibre uses metadata.db just as a file storage, reads all the structures in memory and operates there (see here).
So, to make a long story short -- it cannot be easily fixed.
What one can do, is look at APSW as a substitution for sqlite3, because APSW has ICU already... but I'm not sure I would have time for that... Maybe, the author? :)

Thank you!
This is really bad news.

There seems to be an inexpensive way to do it. Works for me, let me test it, possibly tomorrow I will create a PR with a fix. The trick is to create a custom SQLite function with the name lower() so that the execution engine used it when running the case-insensitive LIKE clause. For that the SQLAlchemy session binding must be changed from Engine to Connection...

Created a PR.

Thank you!

PR is merged

Was this page helpful?
0 / 5 - 0 ratings

Related issues

floviolleau picture floviolleau  路  5Comments

armandoss picture armandoss  路  7Comments

christophwolff picture christophwolff  路  6Comments

olskar picture olskar  路  5Comments

sirprancelot picture sirprancelot  路  4Comments