anl.aida.ae.lucene
Class DBTermFunction

java.lang.Object
  extended by anl.aida.ae.lucene.DBTermFunction
All Implemented Interfaces:
TermFunction

public class DBTermFunction
extends java.lang.Object
implements TermFunction

TermFunction implementation that inserts the term data into a database. The db config info is stored in term_count_db.properties.


Field Summary
private  java.sql.Connection connection
           
private  org.apache.lucene.index.Term currentTerm
           
private  java.sql.Date date
           
private static java.lang.String DOC_FIND
           
private  java.util.Map<java.lang.Integer,java.lang.Integer> docCache
           
private  java.util.Map<java.lang.String,java.lang.Integer> fieldCache
           
private  java.sql.PreparedStatement findDoc
           
private  java.sql.PreparedStatement findTerm
           
private static java.lang.String INSERT_DOC
           
private static java.lang.String INSERT_FIELD
           
private static java.lang.String INSERT_TERM
           
private static java.lang.String INSERT_TERM_SCORE
           
private  java.sql.PreparedStatement insertDoc
           
private  java.sql.PreparedStatement insertField
           
private  java.sql.PreparedStatement insertScore
           
private  java.sql.PreparedStatement insertTerm
           
private static java.lang.String TERM_FIND
           
 
Constructor Summary
DBTermFunction(java.util.Date date)
           
 
Method Summary
 void apply(int docId, org.apache.lucene.document.Document doc, int frequency, float score)
          Apply some implementor specific operation to the term and its data.
 void done()
          Commits any changes to the DB.
private  int findDocId(int lucDocId, org.apache.lucene.document.Document doc)
           
private  int findFieldId(java.lang.String field)
           
private  int findTermId(org.apache.lucene.index.Term term, int docId, org.apache.lucene.document.Document doc)
           
 void init(int docCount)
          Initializes the DB connection.
 void newTerm(org.apache.lucene.index.Term term)
          Called when a new Term is encounters during iterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOC_FIND

private static final java.lang.String DOC_FIND
See Also:
Constant Field Values

TERM_FIND

private static final java.lang.String TERM_FIND
See Also:
Constant Field Values

INSERT_FIELD

private static final java.lang.String INSERT_FIELD
See Also:
Constant Field Values

INSERT_DOC

private static final java.lang.String INSERT_DOC
See Also:
Constant Field Values

INSERT_TERM

private static final java.lang.String INSERT_TERM
See Also:
Constant Field Values

INSERT_TERM_SCORE

private static final java.lang.String INSERT_TERM_SCORE
See Also:
Constant Field Values

connection

private java.sql.Connection connection

fieldCache

private java.util.Map<java.lang.String,java.lang.Integer> fieldCache

docCache

private java.util.Map<java.lang.Integer,java.lang.Integer> docCache

findDoc

private java.sql.PreparedStatement findDoc

findTerm

private java.sql.PreparedStatement findTerm

insertField

private java.sql.PreparedStatement insertField

insertDoc

private java.sql.PreparedStatement insertDoc

insertTerm

private java.sql.PreparedStatement insertTerm

insertScore

private java.sql.PreparedStatement insertScore

date

private java.sql.Date date

currentTerm

private org.apache.lucene.index.Term currentTerm
Constructor Detail

DBTermFunction

public DBTermFunction(java.util.Date date)
Method Detail

init

public void init(int docCount)
          throws AIDAException
Initializes the DB connection.

Specified by:
init in interface TermFunction
Parameters:
docCount - the number of documents in the index.
Throws:
AIDAException - if there is an error during initialization.

done

public void done()
          throws AIDAException
Commits any changes to the DB.

Specified by:
done in interface TermFunction
Throws:
AIDAException - if there is an error during the "done" phase.

newTerm

public void newTerm(org.apache.lucene.index.Term term)
Called when a new Term is encounters during iterator.

Specified by:
newTerm in interface TermFunction
Parameters:
term - the new term.

apply

public void apply(int docId,
                  org.apache.lucene.document.Document doc,
                  int frequency,
                  float score)
           throws AIDAException
Apply some implementor specific operation to the term and its data.

Specified by:
apply in interface TermFunction
Parameters:
docId - the numeric id of the document. This is only valid between calls to init and done.
doc - the document the term applies to
frequency - the frequency count of the term in the document
score - the score of this term for the specified document.
Throws:
AIDAException - if there is an error.

findTermId

private int findTermId(org.apache.lucene.index.Term term,
                       int docId,
                       org.apache.lucene.document.Document doc)
                throws java.sql.SQLException,
                       java.text.ParseException
Throws:
java.sql.SQLException
java.text.ParseException

findDocId

private int findDocId(int lucDocId,
                      org.apache.lucene.document.Document doc)
               throws java.sql.SQLException,
                      java.text.ParseException
Throws:
java.sql.SQLException
java.text.ParseException

findFieldId

private int findFieldId(java.lang.String field)
                 throws java.sql.SQLException
Throws:
java.sql.SQLException