package de.hsmannheim.iws2014.indexing;

import org.apache.lucene.document.*;
import org.apache.lucene.index.IndexWriter;

import java.io.IOException;
import java.util.List;

/**
 * This class does all the hard work. Indexing developers.
 */
public class Indexer {

    private final IndexWriter index;

    public Indexer(IndexWriter index) {
        this.index = index;
    }

    public void index(List<Developer> developers) {
        try {
            try {
                for (Developer developer : developers) {
                    Document doc = new Document();
                    doc.add(stringField("firstname", developer.firstname));
                    doc.add(stringField("surname", developer.surname));
                    doc.add(stringField("residence", developer.residence));
                    doc.add(textField("personalAbstract", developer.personalAbstract));
                    index.addDocument(doc);
                }
            } finally {
                index.close();
            }
        } catch (IOException e) {
            new IndexerException("Cannot add dcoument to index.", e);
        }
    }

    private static StringField stringField(String name, String value) {
        return new StringField(name, value, Field.Store.YES);
    }

    private static TextField textField(String name, String value) {
        return new TextField(name, value, Field.Store.NO);
    }

    static class IndexerException extends RuntimeException {
        public IndexerException(String message, Throwable e) {
            super(message, e);
        }
    }
}
@@ -259,16 +259,251 @@
 exer %7B%0A%0A
+    public static final String FIRSTNAME = %22firstname%22;%0A    public static final String SURNAME = %22surname%22;%0A    public static final String RESIDENCE = %22residence%22;%0A    public static final String PERSONAL_ABSTRACT = %22personalAbstract%22;%0A
     priv
@@ -531,16 +531,16 @@
  index;%0A
-
 %0A    pub
@@ -839,27 +839,25 @@
 ngField(
-%22firstname%22
+FIRSTNAME
 , develo
@@ -913,25 +913,23 @@
 ngField(
-%22surname%22
+SURNAME
 , develo
@@ -983,27 +983,25 @@
 ngField(
-%22residence%22
+RESIDENCE
 , develo
@@ -1055,34 +1055,33 @@
 xtField(
-%22personalAbstract%22
+PERSONAL_ABSTRACT
 , develo

Make index fields public constants