Created
August 6, 2009 09:18
-
-
Save dmishe/163207 to your computer and use it in GitHub Desktop.
This file contains 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 word_search(request): | |
match = request.GET.get('q') | |
result = [] | |
if match is not None and len(match) >= 2: | |
# We search different variants of spelling | |
variants = Variant.objects.filter( | |
Q(name__istartswith=match) | Q(downcoded__istartswith=match) | |
).values_list("entry__pk").order_by("name") | |
words = PhraseTranslation.objects.filter( | |
Q(pk__in=variants) | \ | |
Q(name__istartswith=match) | Q(downcoded__istartswith=match) | |
).values_list( | |
'id', 'name').order_by('name') | |
for word in words[:200]: | |
result.append({'v': '%d' % word[0], 'l': word[1]}) | |
if not result: | |
result.append({'v': '', 'l': 'No matching results.'}) | |
return json_response(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment