How to do query auto-completion/suggestions in Lucene?

Posted by Mat Mannion on Stack Overflow See other posts from Stack Overflow or by Mat Mannion
Published on 2008-09-23T10:12:10Z Indexed on 2010/05/15 18:14 UTC
Read the original article Hit count: 202

Filed under:
|

I'm looking for a way to do query auto-completion/suggestions in Lucene. I've Googled around a bit and played around a bit, but all of the examples I've seen seem to be setting up filters in Solr. We don't use Solr and aren't planning to move to using Solr in the near future, and Solr is obviously just wrapping around Lucene anyway, so I imagine there must be a way to do it!

I've looked into using EdgeNGramFilter, and I realise that I'd have to run the filter on the index fields and get the tokens out and then compare them against the inputted Query... I'm just struggling to make the connection between the two into a bit of code, so help is much appreciated!

To be clear on what I'm looking for (I realised I wasn't being overly clear, sorry) - I'm looking for a solution where when searching for a term, it'd return a list of suggested queries. When typing 'inter' into the search field, it'll come back with a list of suggested queries, such as 'internet', 'international', etc.

© Stack Overflow or respective owner

Related posts about lucene

Related posts about autocomplete