title: Generating search term suggestions with Whoosh?
body: <p>I've got a set of documents in a Whoosh index, and I want to provide a search term suggestion feature. So If you type "pop", some suggestions that could come up might be:</p>
  
  <ul>
  <li>popcorn</li>
  <li>popular</li>
  <li>pope</li>
  <li>Poplar Film</li>
  <li>pop culture</li>
  </ul>
  
  <p>I've got the terms that should be coming up as suggestions going into an NGRAMWORDS field in my index, but when I do a query on that field I get autocompleted results rather than the expanded suggestions - so I get documents tagged with "pop culture", but no way to show that term to the user. 
  (For comparison, I'd do this in ElasticSearch using a completion mapping on that field and then use the _suggest endpoint to get the suggestions.)</p>
  
  <p>I can only find examples for autocomplete or spelling correction in the documentation or elsewhere on on the web. Is there any way I can get search term suggestions from my index with Whoosh?</p>
  
  <p><strong>Edit:</strong>
  <code>expand_prefix</code> was a much-needed pointer in the right direction. I've ended up using a <code>KEYWORD(commas=True, lowercase=True)</code> for my suggest field, and code like this to get suggestions in most-common-first order (<code>expand_prefix</code> and <code>iter_prefix</code> will yield them in alphabetical order):</p>
  
  <pre><code>def get_suggestions(term):
      with ix.reader() as r:
          suggestions = [(s[0], s[1].doc_frequency()) for s in r.iter_prefix('suggest', term)]
      return sorted(suggestions, key=itemgetter(1), reverse=True)
  </code></pre>