Open ayleph opened 8 years ago
Can't reproduce this in 2018. Consider closing the issue Running MediaGoblin 0.9.0 with Python 2.7.12 on Ubuntu Server 16.04
Somehow it stopped working now -_- I now get the exception as well using same search queries as a week ago Will investigate further
somehow the query I send doesn't really match the received one.
it gets received as б
баЙ
I am completely lost now, as it fails to decode some of my non-unicode inputs, while other non-unicode strings work just fine
searching for те
doesn't work, while searching for тест
does
I kinda fixed it with a nasty patch
I patched $MEDIAGOBLIN_ROOT/mediagoblin/tools/pagination.py
My diff:
97a98,121
> def encode_obj(self, in_obj):
> def encode_list(in_list):
> out_list = []
> for el in in_list:
> out_list.append(self.encode_obj(el))
> return out_list
>
> def encode_dict(in_dict):
> out_dict = {}
> for k, v in in_dict.iteritems():
> out_dict[k] = self.encode_obj(v)
> return out_dict
>
> if isinstance(in_obj, unicode):
> return in_obj.encode('utf-8')
> elif isinstance(in_obj, list):
> return encode_list(in_obj)
> elif isinstance(in_obj, tuple):
> return tuple(encode_list(in_obj))
> elif isinstance(in_obj, dict):
> return encode_dict(in_obj)
>
> return in_obj
>
108c132
< base_url, urllib.parse.urlencode(new_get_params))
---
> base_url, urllib.parse.urlencode(self.encode_obj(new_get_params)))
Thank you so much @vanyasem it worked for me.
Just to mention it, if you need the query working with or without accents I had to add this on $MEDIAGOBLIN_ROOT/mediagoblin/plugins/basicsearch/views.py
but before that you need to install the unaccent extension on Postgres, here's the link
from sqlalchemy.sql.functions import ReturnTypeFromArgs
class unaccent(ReturnTypeFromArgs):
pass
...
else:
for term in terms:
# Search entries without accents
media_entry_statements.append(unaccent(MediaEntry.title).ilike(term))
media_entry_statements.append(unaccent(MediaEntry.description).ilike(term))
media_tag_statements.append(unaccent(MediaTag.name).ilike(term))
# Search entries with accents
media_entry_statements.append(MediaEntry.title.ilike(term))
media_entry_statements.append(MediaEntry.description.ilike(term))
media_tag_statements.append(MediaTag.name.ilike(term))
matches = MediaEntry.query.filter(
...