title: building a simple index for corpus
body: <p>so I am working on this small project to build an index for 1400 files corpus then searching for keywords using the index. the index should have the frequency of the keyword and its position "file name". Output should be top ten relevant docs according to frequency of the keyword in each. </p>
  
  <p>for Example: 
  flower text1.txt  3 
  flower text2.txt  2
  .
  .
  this is what I have so far and I'm having difficulty with the tuple as I want to add 3 values to the hashmap </p>
  
  <pre><code>import java.io.*;
  import java.nio.charset.*;
  
  import java.nio.file.*;
  import java.util.*;
  
  public class MyIndex {
  
  
  static Map&lt;String, Tuple&lt;Integer, String&gt;&gt; map = new HashMap();
  
  static String readFile(String path, Charset encoding) throws IOException {
  
      byte[] encoded = Files.readAllBytes(Paths.get(path));
      return new String(encoded, encoding);
  }
  
  
  public static void main (String [] args) throws IOException {
  
      File myDirectory = new File(
              "/Users/.../processedFiles");
  
      File[] fileList = myDirectory.listFiles();
  
      for(int i = 1;i&lt;fileList.length;i++) {
      Scanner scan = new Scanner (new File(fileList[i].getPath()));
  
      while(scan.hasNextLine()) {
          String line = scan.nextLine();
  
          map.put(line, new Tuple (1,fileList[i].getName())); //tuple is frequency of word and file name
      }
  
      }
  
  }
  
  public class Tuple&lt;X, Y&gt; { 
        public final X x; 
        public final Y y; 
        public Tuple(X x, Y y) { 
          this.x = x; 
          this.y = y; 
      } 
  } 
  </code></pre>
  
  <p>}</p>
  
  <p>the error is in put(...) </p>
  
  <p>I didn't add the frequency method yet and this is what I have so far </p>
  
  <pre><code>static void frequency(String [] array) {
  
  Map&lt;String, Integer&gt; map = new HashMap&lt;String, Integer&gt;();
  for (String string : array) {
      int count = 0;
  
      if (!map.containsKey(string)) {
  
      map.put(string, 1);
      }
  
      else {
          count = map.get(string);
          map.put(string, count + 1);
      }
  }
  </code></pre>
  
  <p>is there a better way to do this from scratch as we cannot use lucene etc.. 
  how to put it all together to read and index 1400 files using the Tuple class? 
  I am open to any suggestions 
  thanks </p>