lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From 김성찬(Seongchan Kim) <kiscko...@gmail.com>
Subject Query auto completion by using TSTAutocomplete
Date Mon, 25 Feb 2013 14:53:03 GMT
Hi all,

 

I am implementing query auto completion by using TSTAutocomplete in lucene
3.6.0.

 

In my understanding, prefixCompletion returns a set of suggestion for
completion. API document says it requires three parameters:

Method:

public ArrayList<TernaryTreeNode> prefixCompletion(TernaryTreeNode root,
CharSequence s, int x)

Parameters:

root - a reference to root node of TST.

s - prefix query to be auto-completed.

x - index of current character to be searched while traversing through the
prefix in TST.

Returns:

suggest list of auto-completed keys for the given prefix query.

But I don’t know what should I give for “root.” Is it from my Index? 

               tst.prefixCompletion(root, str, 10);

 

whole codes are following:

 

import java.io.File;

import java.io.IOException;

import java.util.ArrayList;

import java.util.List;

 

import org.apache.lucene.index.IndexReader;

import org.apache.lucene.search.spell.LuceneDictionary;

import org.apache.lucene.search.suggest.Lookup;

import org.apache.lucene.search.suggest.tst.TSTAutocomplete;

import org.apache.lucene.search.suggest.tst.TSTLookup;

import org.apache.lucene.search.suggest.tst.TernaryTreeNode;

import org.apache.lucene.store.FSDirectory;

 

public class Autocomplete {

 

        public static void main(String[] args) throws IOException {

 

               TSTAutocomplete tst = new TSTAutocomplete();

               String str = "recommen";

 

               Lookup autoCompleter = new TSTLookup();

               FSDirectory dir = FSDirectory.open(new File(

                              "d:/workspace/cshare/index/"));

               LuceneDictionary dict = new
LuceneDictionary(IndexReader.open(dir),

                              "title_suggest");

               autoCompleter.build(dict);

 

                ArrayList list = tst.prefixCompletion(root, str, 10);

               System.out.println(list);

        }

 

}

 

Thank you for your help in advance.

Seongchan.


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message