test fix
[wolnelektury.git] / apps / search / views.py
index 56eef09..ec8275b 100644 (file)
@@ -17,9 +17,10 @@ from lucene import StringReader
 from suggest.forms import PublishingSuggestForm
 from time import sleep
 import re
 from suggest.forms import PublishingSuggestForm
 from time import sleep
 import re
-import enchant
+#import enchant
+import json
 
 
-dictionary = enchant.Dict('pl_PL')
+#dictionary = enchant.Dict('en_US')
 
 
 def match_word_re(word):
 
 
 def match_word_re(word):
@@ -36,13 +37,14 @@ def did_you_mean(query, tokens):
         if len(authors) > 0:
             continue
 
         if len(authors) > 0:
             continue
 
-        if not dictionary.check(t):
-            try:
-                change_to = dictionary.suggest(t)[0].lower()
-                if change_to != t.lower():
-                    change[t] = change_to
-            except IndexError:
-                pass
+        if False:
+            if not dictionary.check(t):
+                try:
+                    change_to = dictionary.suggest(t)[0].lower()
+                    if change_to != t.lower():
+                        change[t] = change_to
+                except IndexError:
+                    pass
 
     if change == {}:
         return None
 
     if change == {}:
         return None
@@ -108,17 +110,23 @@ def hint(request):
             c = c[len('pd_'):]
         return _(c)
 
             c = c[len('pd_'):]
         return _(c)
 
-    return JSONResponse(
-        [{'label': t.name,
-          'category': category_name(t.category),
-          'id': t.id,
-          'url': t.get_absolute_url()}
-          for t in tags] + \
-          [{'label': b.title,
-            'category': _('book'),
-            'id': b.id,
-            'url': b.get_absolute_url()}
-            for b in books])
+    callback = request.GET.get('callback', None)
+    data = [{'label': t.name,
+              'category': category_name(t.category),
+              'id': t.id,
+              'url': t.get_absolute_url()}
+              for t in tags] + \
+              [{'label': b.title,
+                'category': _('book'),
+                'id': b.id,
+                'url': b.get_absolute_url()}
+                for b in books]
+    if callback:
+        return HttpResponse("%s(%s);" % (callback, json.dumps(data)),
+                            content_type="application/json; charset=utf-8")
+    else:
+        return JSONResponse(data)
+            
 
 
 def main(request):
 
 
 def main(request):