0

I am trying to create autosuggestion for some of my blogs i already use lucene as search engine and can any one tell me how can i achieve this . Which analyzer will be usefull to generate this, can any one give some code examples too..

Edit.

i am trying to generate the suggestion terms not to display with UI.

Ramesh
  • 2,295
  • 5
  • 35
  • 64
  • I think you're looking for javascript not java. – awm Dec 09 '11 at 13:00
  • @awm: No, I think Ramesh is looking for the server side part of the solution. Please revert the tag change. – Codo Dec 09 '11 at 14:21
  • 1
    One possible solution can be found in http://stackoverflow.com/questions/120180/how-to-do-query-auto-completion-suggestions-in-lucene. Another one is to just iterate on the term collection. – Codo Dec 09 '11 at 14:23

2 Answers2

0

Try looking at jquery and jquery-ui. ajax, load, autocomplete is the commands you're looking for. If you look on jquery.com you'll find a ton of examples as well as doing a search on google for code samples.

awm
  • 2,723
  • 2
  • 18
  • 26
0

This functionality has been ported from Solr to Lucene just recently. Take a look at the FSTLookup class, introduced in Lucene 3.3.0. For an example on how to use it, see the associated test class.

A small snippet extracted from the test class to show you the basics:

private TermFreq[] evalKeys() {
    final TermFreq[] keys = new TermFreq[] {
        tf("one", 0.5f),
        tf("oneness", 1),
        tf("onerous", 1),
        tf("onesimus", 1),
        tf("two", 1),
        tf("twofold", 1),
        tf("twonk", 1),
        tf("thrive", 1),
        tf("through", 1),
        tf("threat", 1),
        tf("three", 1),
        tf("foundation", 1),
        tf("fourblah", 1),
        tf("fourteen", 1),
        tf("four", 0.5f),
        tf("fourier", 0.5f),
        tf("fourty", 0.5f),
        tf("xo", 1),
      };
    return keys;
}

FSTLookup lookup = new FSTLookup();
lookup.build(new TermFreqArrayIterator(evalKeys()));
LookupResult result = lookup.lookup("one", false, 2);
Zsolt Török
  • 10,289
  • 2
  • 26
  • 26