title: Generate Term-Document matrix using Lucene 4.4
body: <p>I'm trying to create Term-Document matrix for a small corpus to further experiment with LSI. However, I couldn't find a way to do it with Lucene 4.4.</p>
  <p>I know how to get TermVector for each document as following:</p>
  <pre class="lang-java prettyprint-override"><code>//create boolean query to search for a specific document (not shown)
  TopDocs hits = searcher.search(query, 1);    
  Terms termVector = reader.getTermVector(hits.scoreDocs[0].doc, &quot;contents&quot;);
  System.out.println(termVector.size());  //just testing
  </code></pre>
  <p>I thought I can just union all the termVector together as columns in a matrix to get the matrix. However, termVector for different documents have different size. And we don't know how to pad 0 into the termVector. So, certainly, this method does not work.</p>
  <ol>
  <li><p>Hence, I wonder if someone can show me how to create Term-Document vector with Lucene 4.4 please? (If possible, please show sample code).</p>
  </li>
  <li><p>If Lucene does not support this function, what is the other way you recommend to do it?</p>
  <p>Many thanks,</p>
  </li>
  </ol>