import java.io.*;

import org.apache.lucene.analysis.*;
import org.apache.lucene.document.*;
import org.apache.lucene.index.*;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.json.simple.*;


public class PasteIndexer {

    protected JSONArray pastes;

    public void loadPastes(File file)
        throws java.io.FileNotFoundException {
        pastes = (JSONArray) JSONValue.parse(new FileReader(file));
    }

    public Document Document(int pasteNum) {
        JSONObject p = (JSONObject) pastes.get(pasteNum);
        Document doc = new Document();

        doc.add(Field.Text("number", (String) p.get("number")));
        doc.add(Field.Text("user", (String) p.get("user")));
        doc.add(Field.Text("date", (String) p.get("date")));
        doc.add(Field.Text("channel", (String) p.get("channel")));
        doc.add(Field.Text("title", (String) p.get("title")));
        doc.add(Field.Text("contents", (String) p.get("contents")));

        return doc;
    }
                
    public void indexPastes()
        throws InterruptedException, IOException {

        String indexFile = "pasteindex.luc";
        
        IndexWriter writer = null;
        File f;
        boolean create = true;
        // create index if the directory does not exist
        if ((f = new File(indexFile)).exists() && f.isDirectory()) {
            create = false;
        } else {
            create = true;
        }
        
        try {
            writer = new IndexWriter(indexFile, new StandardAnalyzer(), create);
            writer.minMergeDocs = 5000;
            
            System.out.println("Indexing...");
            System.out.println(System.currentTimeMillis());
            for (int i = 0; i < pastes.size(); i++) {
                indexPaste(writer, i);
            }
            System.out.println(System.currentTimeMillis());

            System.out.println("\nOptimizing...");
            System.out.println(System.currentTimeMillis());
            writer.optimize();
            System.out.println(System.currentTimeMillis());
        } finally {
            if (writer != null) 
                writer.close();
        }
    }

    public void indexPaste(IndexWriter writer, int pasteNum)
        throws IOException {
        writer.addDocument(Document(pasteNum));
    }

    public static void main (String args[]) {
        try{
            PasteIndexer indexer = new PasteIndexer();
            System.out.println("Loading...");
            indexer.loadPastes(new File("../pastes.json"));
            System.out.println("Indexing " + indexer.pastes.size() + " pastes.");
            indexer.indexPastes();
        } catch (Exception e) {
            System.err.println("Got exception " + e);
            e.printStackTrace();
        }
    }
}
@@ -594,26 +594,21 @@
 add(
+new 
 Field
-.Text(%22number
+(%22id
 %22, (
@@ -626,24 +626,43 @@
 et(%22number%22)
+, true, true, false
 ));%0A        
@@ -669,26 +669,25 @@
 doc.add(
+new 
 Field
-.Text
 (%22user%22,
@@ -709,16 +709,35 @@
 (%22user%22)
+, true, true, false
 ));%0A    
@@ -748,26 +748,25 @@
 doc.add(
+new 
 Field
-.Text
 (%22date%22,
@@ -788,16 +788,35 @@
 (%22date%22)
+, true, true, false
 ));%0A    
@@ -827,26 +827,25 @@
 doc.add(
+new 
 Field
-.Text
 (%22channe
@@ -873,16 +873,35 @@
 hannel%22)
+, true, true, false
 ));%0A    
@@ -912,26 +912,25 @@
 doc.add(
+new 
 Field
-.Text
 (%22title%22
@@ -954,16 +954,34 @@
 %22title%22)
+, true, true, true
 ));%0A    
@@ -996,18 +996,17 @@
 add(
+new 
 Field
-.Text
 (%22co
@@ -1040,16 +1040,35 @@
 ntents%22)
+, false, true, true
 ));%0A%0A   
@@ -1680,32 +1680,107 @@
 00;%0A            
+writer.maxFieldLength = 1000000;%0A            %0A            long start, end;%0A
 %0A            Sys
@@ -1823,35 +1823,24 @@
         
-System.out.println(
+start = 
 System.c
@@ -1849,33 +1849,32 @@
 rentTimeMillis()
-)
 ;%0A            fo
@@ -1978,35 +1978,22 @@
         
-System.out.println(
+end = 
 System.c
@@ -2010,19 +2010,17 @@
 Millis()
-);%0A
+;
 %0A       
@@ -2048,27 +2048,68 @@
 ln(%22
-%5CnOptimizing..
+Indexing took %22 + ((end - start) / 1000.0) + %22 seconds
 .%22);%0A
+%0A
     
@@ -2127,32 +2127,72 @@
 tem.out.println(
+%22%5CnOptimizing...%22);%0A            start = 
 System.currentTi
@@ -2193,33 +2193,32 @@
 rentTimeMillis()
-)
 ;%0A            wr
@@ -2241,32 +2241,38 @@
 %0A           
+ end =
  System.
 out.println(
@@ -2263,27 +2263,8 @@
 tem.
-out.println(System.
 curr
@@ -2278,16 +2278,108 @@
 Millis()
+;%0A            System.out.println(%22Optimizing took %22 + ((end - start) / 1000.0) + %22 seconds.%22
 );%0A     
@@ -3093,8 +3093,9 @@
 %0A    %7D%0A%7D
+%0A

Print timing information more readably.