title: Building an inverted index in Java-logic
body: <p>I have a collection of around 1500 documents. I parsed through each document and extract tokens. These tokens are stored in an hashmap(as key) and the total number of times they occur in the collection (i.e. frequency) is stored as the value.</p>
  
  <p>I have to extend this to build an inverted index. That is, the term(key)| number of documents it occurs it-->DocNo|Frequency in that document. For exmple, </p>
  
  <pre><code>    Term       DocFreq    DocNum      TermFreq  
    data           3           1            12  
                              23            31  
                              100           17  
    customer       2          22            43  
                              19            2  
  </code></pre>
  
  <p>Currently, I have the following in Java,</p>
  
  <pre><code>hashmap&lt;string,integer&gt;  
  for(each document)  
  {  
      extract line  
      for(each line)  
      {  
          extract word   
          for(each word)  
          {  
              perform some operations  
              get value for word from hashmap and increment by one  
          }  
      }  
  }  
  </code></pre>
  
  <p>I have to build on this code. I can't really think of a good way to implement an inverted index.
  So far, I thought of making value a 2D array. So the term would be the key and the value(i.e 2D array) would store the docId and termFreq.</p>
  
  <p>Please let me know if my logic is correct.</p>