Posted By:
Anonymous
Posted On:
Monday, April 5, 2004 02:35 PM
For indexing purposes, you can index from a database.
You grab each value that you want to index..eg
if sql is "select name, surname, id from person"
And if u have an object that will connect to the DB and return you each value given the key (fieldName like a Hashtable) then...
IndexWriter writer = IndexWriter(indexDir,analyzer,true);
Document d = new Document();
d.add(Field.Text("name",(String)resultRow.get("NAME")));
d.add(Field.UnIndexed("surname",(String)resultRow.get("SURNAME")));
d.addA(Field.Text("id",(String)resultRow.get("ID")));
writer.addDocument(d);
As you see the trick is just in grabbing each row (you can construct an object similar to resultRow)
Then build Field objects and add those Field objects into your Document object then add the document object into the writer.
The implementation that i wrote for my project incorporates using RAMDirectory object it makes it much more faster to index
It takes approx 7 secs to index 6000 records!