Created
          September 30, 2009 14:22 
        
      - 
      
- 
        Save JeffreyZhao/198131 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | private static RAMDirectory IndexBenchmark(String target, int topN) throws Exception { | |
| System.gc(); | |
| if (topN < 0) topN = Integer.MAX_VALUE; | |
| RAMDirectory ramDir = new RAMDirectory(); | |
| IndexWriter ramWriter = new IndexWriter(ramDir, new StandardAnalyzer()); | |
| FileInputStream fstream = new FileInputStream("Content.txt"); | |
| BufferedReader reader = new BufferedReader(new InputStreamReader(fstream)); | |
| StringBuffer sb = null; | |
| String filePath = null; | |
| int number = 0; | |
| Stopwatch watch = new Stopwatch(); | |
| watch.start(); | |
| while (true) | |
| { | |
| String line = reader.readLine(); | |
| if (line == null) break; | |
| if (sb == null) | |
| { | |
| filePath = line; | |
| sb = new StringBuffer(); | |
| } | |
| else if (line.equals(separator)) | |
| { | |
| // Document doc = new Document(); | |
| // doc.add(new Field("File", filePath, Field.Store.YES, Field.Index.NO)); | |
| // doc.add(new Field("Content", sb.toString(), Field.Store.NO, Field.Index.ANALYZED)); | |
| // ramWriter.addDocument(doc); | |
| if (number++ > topN) break; | |
| if (number % 1000 == 0) | |
| { | |
| System.out.println(number + " " + watch.getElapsedMilliseconds()); | |
| } | |
| filePath = null; | |
| sb = null; | |
| } | |
| else | |
| { | |
| sb.append(line); | |
| } | |
| } | |
| watch.stop(); | |
| System.out.println("Finished " + watch.getElapsedMilliseconds()); | |
| ramWriter.close(); | |
| return ramDir; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment