title: Information Retrieval: How to calculate tf-idf for multiple search terms?
body: <p>I have a corpus of the following 4 documents:</p>
  
  <blockquote>
    <p>&lt;1> This is the first document.<br>
    &lt;2> And this is the second document.<br>
    &lt;3> The third document is longer than the first and second one.<br>
    &lt;4> This is the last document.</p>
  </blockquote>
  
  <p>And use the search queue "first OR last", how am I supposed to calculate the tf-idf?</p>
  
  <p>Currently I'm using this:</p>
  
  <p><code>tf(x, D) = raw frequency of term x in document D / raw frequency of most occurring term in D</code></p>
  
  <p><code>idf(x) = log(1 + total number of documents / number of documents containing x)</code></p>
  
  <p>So for queue I get<br>
  <code>&lt;1&gt; = (1 / 1) * log(1 + 4/3)</code><br>
  <code>&lt;3&gt; = (1 / 2) * log(1 + 4/3)</code><br>
  <code>&lt;4&gt; = (1 / 1) * log(1 + 4/3)</code>  </p>
  
  <p>Is this correct? How do you do this properly? Do I calculate the value for all search terms separately and then add? multiply?</p>