Created
October 18, 2017 11:50
-
-
Save OndrejIT/0a972bf870c101aaa29fdd672e9d712a to your computer and use it in GitHub Desktop.
search.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def search(query): | |
try: | |
query.encode("ascii") | |
except UnicodeEncodeError: | |
galleries = Gallery.objects.published().filter( | |
fulltext__full_ts=SearchQuery(query, config="czech") | |
) | |
if not galleries: | |
galleries = Gallery.objects.published().filter(title__icontains=query) | |
else: | |
galleries = Gallery.objects.published().filter( | |
fulltext__full_ascii_ts=SearchQuery(query, config="czech_ascii") | |
) | |
if not galleries: | |
galleries = Gallery.objects.published().filter(title__unaccent__icontains=query) | |
return galleries |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment