geoadmin/mf-chsdi3 — pull request #1182 by loicgasser (2014-12-23 15:52:18+00:00)
Title: Support special characters for similarity queries

This PR is for: https://github.com/geoadmin/mf-geoadmin3/issues/2009

At some point the where `unicode` will be converted to byte `str` and will fail because for some reason we have non-ASCII unicode strings.

The famous `UnicodeError` ...

Here we
1. Build a query to postrges can understand (Escaping the `\` and telling postrgres to escape it with E)
2. We convert to byte `str` and replace unmapped characters with `?` that we finally replace with `%`

It's a workaround but it works fine.
If anybody has a better solution/understanding of what's going please feel free.

[Current Link in prod]
(http://api3.geo.admin.ch/rest/services/all/MapServer/identify?geometryFormat=geojson&lang=fr&layers=all:ch.swisstopo.geologie-geotope&time=2013&where=nom+ilike+%27%25Bloc+erratique+rhodanien+de+la+L%C3%A9cherette+(Ch%C3%A2teau+d%27Oex,+VD)%25%27)

[Deployed Branch in test]
(http://mf-chsdi3.dev.bgdi.ch/gal_handle_accents/rest/services/all/MapServer/identify?geometryFormat=geojson&lang=fr&layers=all:ch.swisstopo.geologie-geotope&time=2013&where=nom+ilike+%27%25Bloc+erratique+rhodanien+de+la+L%C3%A9cherette+(Ch%C3%A2teau+d%27Oex,+VD)%25%27)