//return coWeightSum / (Math.sqrt(weightSumSquare1) * Math.sqrt(weightSumSquare2));
}
private static Map<String,Double> getTfIdfVector(IndexReader ir, int doc, String field) throws Exception {
Map<String,Double> tfIdf = new HashMap<String,Double>();
TermFreqVector tv = ir.getTermFreqVector(doc, field);
double termTotal = 0.0;
if(tv == null) return tfIdf;
String [] terms = tv.getTerms();
int [] counts = tv.getTermFrequencies();
double docTotal = ir.numDocs();
for(int i=0;i<tv.size();i++) {
termTotal += counts[i];
}
for(int i=0;i<tv.size();i++) {
String term = terms[i].intern();
double tf = counts[i] / termTotal;
double idf = Math.log(docTotal / ir.docFreq(new Term(field, term)));
tfIdf.put(term, tf * idf);
//tfIdf.put(term, tf);