changeset 2531:7ec50a76110a

Adds suggestions-as-you-type feature for the search function
author sharky93 <rishabhr123@gmail.com>
date Mon, 22 Jul 2013 03:33:30 +0530
parents bfb653c10406
children 74d2eafffa29
files MoinMoin/apps/frontend/views.py MoinMoin/storage/middleware/indexing.py MoinMoin/templates/ajaxsearch.html
diffstat 3 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Mon Jul 22 03:29:40 2013 +0530
+++ b/MoinMoin/apps/frontend/views.py	Mon Jul 22 03:33:30 2013 +0530
@@ -305,9 +305,16 @@
             content_suggestions = [word for word, score in results.key_terms(CONTENT, docs=20, numterms=10)]
             flaskg.clock.stop('search suggestions')
             flaskg.clock.start('search render')
+            
+            lastword = query.split(' ')[-1]
+            word_suggestions = []
+            if len(lastword) > 2:
+                corrector = searcher.corrector(CONTENT)
+                word_suggestions = corrector.suggest(lastword, limit=3)
             if ajax:
                 html = render_template('ajaxsearch.html',
                                    results=results,
+                                   word_suggestions=u', '.join(word_suggestions),
                                    name_suggestions=u', '.join(name_suggestions),
                                    content_suggestions=u', '.join(content_suggestions),
                 )
--- a/MoinMoin/storage/middleware/indexing.py	Mon Jul 22 03:29:40 2013 +0530
+++ b/MoinMoin/storage/middleware/indexing.py	Mon Jul 22 03:33:30 2013 +0530
@@ -299,7 +299,7 @@
             # DATAID from metadata
             DATAID: ID(stored=True),
             # data (content), converted to text/plain and tokenized
-            CONTENT: TEXT(stored=True),
+            CONTENT: TEXT(stored=True, spelling=True),
         }
 
         latest_revs_fields = {
--- a/MoinMoin/templates/ajaxsearch.html	Mon Jul 22 03:29:40 2013 +0530
+++ b/MoinMoin/templates/ajaxsearch.html	Mon Jul 22 03:33:30 2013 +0530
@@ -12,6 +12,9 @@
     {% endif %}
 
     {% if results is defined %}
+        {% if word_suggestions %}
+            <p>{{ _("input suggestions: %(termlist)s", termlist=word_suggestions) }}</p>
+        {% endif %}
         {% if name_suggestions or content_suggestions %}
             <p>{{ _("name term suggestions: %(termlist)s", termlist=name_suggestions) }}</p>
             <p>{{ _("content term suggestions: %(termlist)s", termlist=content_suggestions) }}</p>