Commits

sharky93  committed 7ec50a7

Adds suggestions-as-you-type feature for the search function

  • Participants
  • Parent commits bfb653c

Comments (0)

Files changed (3)

File MoinMoin/apps/frontend/views.py

             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),
                 )

File MoinMoin/storage/middleware/indexing.py

             # 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 = {

File MoinMoin/templates/ajaxsearch.html

     {% 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>