Example usage for org.apache.lucene.index IndexWriter close

List of usage examples for org.apache.lucene.index IndexWriter close

Introduction

In this page you can find the example usage for org.apache.lucene.index IndexWriter close.

Prototype

@Override
public void close() throws IOException 

Source Link

Document

Closes all open resources and releases the write lock.

Usage

From source file:com.mss.mirage.recruitment.ConsultantAction.java

License:Open Source License

public static int index(File indexDir, File dataDir) throws IOException {

    // Listing 1.1 Indexer: traverses a file system and indexes .txt files
    // Create Lucene index in this directory
    // Index files in this directory

    /*//from w ww  .jav  a 2 s.  co  m
    if (!dataDir.exists() || !dataDir.isDirectory()) {
    throw new IOException(dataDir
    + " does not exist or is not a directory");
    }*/

    IndexWriter writer = new IndexWriter(indexDir, new StandardAnalyzer(), true);
    writer.setUseCompoundFile(false);
    indexDirectory(writer, dataDir);
    int numIndexed = writer.docCount();
    writer.optimize();
    writer.close();
    return numIndexed;
}

From source file:com.mycompany.mavenproject1.Main.java

public static void main(String[] args) throws IOException, ParseException {
    StandardAnalyzer analyzer = new StandardAnalyzer();
    //        Directory index = new RAMDirectory();
    Directory index = new SimpleFSDirectory(Paths.get(
            "C:\\Users\\slete\\Documents\\NetBeansProjects\\mavenproject1\\src\\main\\java\\com\\mycompany\\mavenproject1\\data"));
    IndexWriterConfig config = new IndexWriterConfig(analyzer);
    //config.setOpenMode(OpenMode.CREATE);
    IndexWriter w = new IndexWriter(index, config);
    try (ItemProvider provider = new ItemProvider(
            "C:\\Users\\slete\\Documents\\NetBeansProjects\\mavenproject1\\src\\main\\java\\com\\mycompany\\mavenproject1\\items.xml")) {

        while (provider.hasNext()) {
            Item item = provider.next();
            addItem(w, item);//from w w w  .ja  v a2 s  . c om

        }
    } catch (XMLStreamException | IOException ex) {
        ex.getMessage();
    }
    //        w.commit();
    w.close();

    //        String queryStr = "id:1* NOT id:19*";
    String a = "id:1* NOT id:19*";
    String b = "name:Dekielek AND description:(ty AND obiektywu)";
    String c = "category:Dek*";
    String ds = "id:1232~2";
    String e = "price:[0.0 TO 100.0]";

    Query q = new QueryParser("name", analyzer).parse(ds);

    int hitsPerPage = 10;
    IndexReader reader = DirectoryReader.open(index);
    IndexSearcher searcher = new IndexSearcher(reader);
    TopDocs docs = searcher.search(q, hitsPerPage);
    ScoreDoc[] hits = docs.scoreDocs;

    System.out.println("Found " + hits.length + " hits.");
    for (int i = 0; i < hits.length; ++i) {
        int docId = hits[i].doc;
        Document d = searcher.doc(docId);
        System.out
                .println(d.get("id") + "\t" + d.get("price") + "\t" + d.get("name") + "\t" + d.get("category"));//+"\t" + d.get("description"));
    }
}

From source file:com.mycompany.restlet.search.sample.indexer.java

License:Apache License

/** Index all text files under a directory. */
public static void main(String[] args) {
    String usage = "java org.apache.lucene.demo.IndexFiles"
            + " [-index INDEX_PATH] [-docs DOCS_PATH] [-update]\n\n"
            + "This indexes the documents in DOCS_PATH, creating a Lucene index"
            + "in INDEX_PATH that can be searched with SearchFiles";
    String indexPath = "index";
    String docsPath = null;// w  ww . ja v a 2s.c  o  m
    boolean create = true;
    for (int i = 0; i < args.length; i++) {
        if ("-index".equals(args[i])) {
            indexPath = args[i + 1];
            i++;
        } else if ("-docs".equals(args[i])) {
            docsPath = args[i + 1];
            i++;
        } else if ("-update".equals(args[i])) {
            create = false;
        }
    }

    if (docsPath == null) {
        System.err.println("Usage: " + usage);
        System.exit(1);
    }

    final Path docDir = Paths.get(docsPath);
    if (!Files.isReadable(docDir)) {
        System.out.println("Document directory '" + docDir.toAbsolutePath()
                + "' does not exist or is not readable, please check the path");
        System.exit(1);
    }

    Date start = new Date();
    try {
        System.out.println("Indexing to directory '" + indexPath + "'...");

        Directory dir = FSDirectory.open(Paths.get(indexPath));
        Analyzer analyzer = new StandardAnalyzer();
        //         MorphemeAnalyzer ma = new MorphemeAnalyzer();

        IndexWriterConfig iwc = new IndexWriterConfig(analyzer);

        if (create) {
            // Create a new index in the directory, removing any
            // previously indexed documents:
            iwc.setOpenMode(OpenMode.CREATE);
        } else {
            // Add new documents to an existing index:
            iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
        }

        // Optional: for better indexing performance, if you
        // are indexing many documents, increase the RAM
        // buffer.  But if you do this, increase the max heap
        // size to the JVM (eg add -Xmx512m or -Xmx1g):
        //
        // iwc.setRAMBufferSizeMB(256.0);

        IndexWriter writer = new IndexWriter(dir, iwc);
        indexDocs(writer, docDir);

        // NOTE: if you want to maximize search performance,
        // you can optionally call forceMerge here.  This can be
        // a terribly costly operation, so generally it's only
        // worth it when your index is relatively static (ie
        // you're done adding documents to it):
        //
        // writer.forceMerge(1);
        writer.close();

        Date end = new Date();
        System.out.println(end.getTime() - start.getTime() + " total milliseconds");

    } catch (IOException e) {
        System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage());
    }
}

From source file:com.mylucene.basiclucene.IndexFiles.java

License:Apache License

/** Index all text files under a directory. */
public static void main(String[] args) {
    String usage = "java org.apache.lucene.demo.IndexFiles"
            + " [-index INDEX_PATH] [-docs DOCS_PATH] [-update]\n\n"
            + "This indexes the documents in DOCS_PATH, creating a Lucene index"
            + "in INDEX_PATH that can be searched with SearchFiles";
    String indexPath = "index";
    String docsPath = null;/*  w w w. ja  v a  2 s. c  om*/
    boolean create = true;
    for (int i = 0; i < args.length; i++) {
        if ("-index".equals(args[i])) {
            indexPath = args[i + 1];
            i++;
        } else if ("-docs".equals(args[i])) {
            docsPath = args[i + 1];
            i++;
        } else if ("-update".equals(args[i])) {
            create = false;
        }
    }

    if (docsPath == null) {
        System.err.println("Usage: " + usage);
        System.exit(1);
    }

    final File docDir = new File(docsPath);
    if (!docDir.exists() || !docDir.canRead()) {
        System.out.println("Document directory '" + docDir.getAbsolutePath()
                + "' does not exist or is not readable, please check the path");
        System.exit(1);
    }

    Date start = new Date();
    try {
        System.out.println("Indexing to directory '" + indexPath + "'...");

        Directory dir = FSDirectory.open(new File(indexPath));
        Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_44);
        IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_44, analyzer);

        if (create) {
            // Create a new index in the directory, removing any
            // previously indexed documents:
            iwc.setOpenMode(OpenMode.CREATE);
        } else {
            // Add new documents to an existing index:
            iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
        }

        // Optional: for better indexing performance, if you
        // are indexing many documents, increase the RAM
        // buffer.  But if you do this, increase the max heap
        // size to the JVM (eg add -Xmx512m or -Xmx1g):
        //
        // iwc.setRAMBufferSizeMB(256.0);

        IndexWriter writer = new IndexWriter(dir, iwc);
        indexDocs(writer, docDir);

        // NOTE: if you want to maximize search performance,
        // you can optionally call forceMerge here.  This can be
        // a terribly costly operation, so generally it's only
        // worth it when your index is relatively static (ie
        // you're done adding documents to it):
        //
        // writer.forceMerge(1);

        writer.close();

        Date end = new Date();
        System.out.println(end.getTime() - start.getTime() + " total milliseconds");

    } catch (IOException e) {
        System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage());
    }
}

From source file:com.nearinfinity.blur.mapreduce.BlurReducer.java

License:Apache License

protected void cleanupFromRebuild(Context context) throws IOException, InterruptedException {
    _writer.commit();//w  ww.  ja v a 2 s.  co m
    _writer.close();

    IndexReader reader = IndexReader.open(_directory);

    TableDescriptor descriptor = _blurTask.getTableDescriptor();

    Path directoryPath = _blurTask.getDirectoryPath(context);
    remove(directoryPath);

    NoLockFactory lockFactory = NoLockFactory.getNoLockFactory();

    Directory destDirectory = getDestDirectory(descriptor, directoryPath);
    destDirectory.setLockFactory(lockFactory);

    boolean optimize = _blurTask.getOptimize();

    if (optimize) {
        context.setStatus("Starting Copy-Optimize Phase");
        IndexWriterConfig conf = new IndexWriterConfig(LUCENE_VERSION, _analyzer);
        TieredMergePolicy policy = (TieredMergePolicy) conf.getMergePolicy();
        policy.setUseCompoundFile(false);
        long s = System.currentTimeMillis();
        IndexWriter writer = new IndexWriter(getBiggerBuffers(destDirectory), conf);
        writer.addIndexes(reader);
        writer.close();
        long e = System.currentTimeMillis();
        context.setStatus("Copying phase took [" + (e - s) + " ms]");
        LOG.info("Copying phase took [" + (e - s) + " ms]");
    } else {
        context.setStatus("Starting Copy-Optimize Phase");
        long s = System.currentTimeMillis();
        List<String> files = getFilesOrderedBySize(_directory);
        long totalBytesToCopy = getTotalBytes(_directory);
        long totalBytesCopied = 0;
        long startTime = System.currentTimeMillis();
        for (String file : files) {
            totalBytesCopied += copy(_directory, destDirectory, file, file, context, totalBytesCopied,
                    totalBytesToCopy, startTime);
        }
        long e = System.currentTimeMillis();
        context.setStatus("Copying phase took [" + (e - s) + " ms]");
        LOG.info("Copying phase took [" + (e - s) + " ms]");
    }
}

From source file:com.nearinfinity.blur.search.TestingPagingCollector.java

License:Apache License

private static IndexReader getReaderFlatScore(int length) throws Exception {
    RAMDirectory directory = new RAMDirectory();
    IndexWriter indexWriter = new IndexWriter(directory,
            new IndexWriterConfig(LUCENE_VERSION, new KeywordAnalyzer()));
    for (int i = 0; i < length; i++) {
        Document document = new Document();
        document.add(new Field("f1", "value", Store.NO, Index.ANALYZED_NO_NORMS));
        indexWriter.addDocument(document);
    }//from w ww .jav a 2s  .c  o  m
    indexWriter.close();
    return IndexReader.open(directory);
}

From source file:com.nearinfinity.blur.utils.TermDocIterableTest.java

License:Apache License

private IndexReader createIndexReader() throws IOException {
    FSDirectory directory = FSDirectory.open(new File("./tmp/termdociterable"));
    if (!IndexReader.indexExists(directory)) {
        rm(new File("./tmp/termdociterable"));
        IndexWriter writer = new IndexWriter(directory,
                new IndexWriterConfig(LUCENE_VERSION, new StandardAnalyzer(LUCENE_VERSION)));
        for (int i = 0; i < BLOCKS; i++) {
            addDocumentBlock(i, COUNT_PER_BLOCK, writer);
        }//w w w. j a v a 2  s  .  c o  m
        writer.close();
    }
    return IndexReader.open(directory);
}

From source file:com.nero.model.IndexFiles.java

License:Apache License

/** Index all text files under a directory. */
public static void main(String[] args) {
    String usage = "java org.apache.lucene.demo.IndexFiles"
            + " [-index INDEX_PATH] [-docs DOCS_PATH] [-update]\n\n"
            + "This indexes the documents in DOCS_PATH, creating a Lucene index"
            + "in INDEX_PATH that can be searched with SearchFiles";
    String indexPath = "index";
    String docsPath = "docspath";
    boolean create = true;
    //    for(int i=0;i<args.length;i++) {
    //      if ("-index".equals(args[i])) {
    //        indexPath = args[i+1];
    //        i++;
    //      } else if ("-docs".equals(args[i])) {
    //        docsPath = args[i+1];
    //        i++;
    //      } else if ("-update".equals(args[i])) {
    //        create = false;
    //      }//  ww w.  j ava  2  s. c om
    //    }

    if (docsPath == null) {
        System.err.println("Usage: " + usage);
        System.exit(1);
    }

    final File docDir = new File(docsPath);
    if (!docDir.exists() || !docDir.canRead()) {
        System.out.println("Document directory '" + docDir.getAbsolutePath()
                + "' does not exist or is not readable, please check the path");
        System.exit(1);
    }

    Date start = new Date();
    try {
        System.out.println("Indexing to directory '" + indexPath + "'...");

        Directory dir = FSDirectory.open(new File(indexPath));
        Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_31);
        IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_31, analyzer);

        if (create) {
            // Create a new index in the directory, removing any
            // previously indexed documents:
            iwc.setOpenMode(OpenMode.CREATE);
        } else {
            // Add new documents to an existing index:
            iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
        }

        // Optional: for better indexing performance, if you
        // are indexing many documents, increase the RAM
        // buffer.  But if you do this, increase the max heap
        // size to the JVM (eg add -Xmx512m or -Xmx1g):
        //
        // iwc.setRAMBufferSizeMB(256.0);

        IndexWriter writer = new IndexWriter(dir, iwc);
        indexDocs(writer, docDir);

        // NOTE: if you want to maximize search performance,
        // you can optionally call forceMerge here.  This can be
        // a terribly costly operation, so generally it's only
        // worth it when your index is relatively static (ie
        // you're done adding documents to it):
        //
        // writer.forceMerge(1);

        writer.close();

        Date end = new Date();
        System.out.println(end.getTime() - start.getTime() + " total milliseconds");

    } catch (IOException e) {
        System.out.println(" caught a " + e.getClass() + "\n with message: " + e.getMessage());
    }
}

From source file:com.netcrest.pado.index.provider.lucene.LuceneBuilderRAMDirectory.java

License:Open Source License

@SuppressWarnings({ "unchecked", "rawtypes", "resource" })
public void buildTemporalKeys(boolean createNewDirectory) {
    Cache cache = CacheFactory.getAnyInstance();
    Region<String, RAMDirectory> region = cache
            .getRegion(IndexMatrixUtil.getProperty(Constants.PROP_REGION_LUCENE));
    TemporalType[] temporalTypes = GemfireTemporalManager.getAllTemporalTypes();

    for (TemporalType type : temporalTypes) {
        IndexWriter writer = null;
        Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_47);
        IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_47, analyzer);
        iwc.setOpenMode(OpenMode.CREATE);
        LuceneField luceneBuilder = new LuceneField();

        LuceneSearch ls = LuceneSearch.getLuceneSearch(type.getFullPath());
        StandardQueryParser parser = ls.createParser();
        TemporalManager tm = TemporalManager.getTemporalManager(type.getFullPath());
        try {//from  w  w w .j a va  2 s .  co  m
            List<?> identityKeyList = tm.getIdentityKeyList();
            if (identityKeyList.size() == 0) {
                continue;
            }

            RAMDirectory directory;
            if (createNewDirectory) {
                directory = new RAMDirectory();
            } else {
                directory = region.get(type.getFullPath());
                if (directory == null) {
                    directory = new RAMDirectory();
                }
            }
            writer = new IndexWriter(directory, iwc);

            // determine the identity key type, public fields and getters
            Field fields[] = null;
            Method getters[] = null;
            Class keyType = null;
            for (Object key : identityKeyList) {
                if (ReflectionHelper.isPrimitiveWrapper(key.getClass())) {
                    fields = null;
                    getters = null;
                    keyType = key.getClass();
                } else {
                    fields = ReflectionHelper.getPublicFields(key.getClass());
                    getters = ReflectionHelper.getPublicGetters(key.getClass());
                }
                break;
            }

            if (keyType != null) {

                configNumericType(parser, "IdentityKey", keyType);

                // primitive
                List<Document> docList = new ArrayList();
                if (keyType == String.class) {
                    for (Object key : identityKeyList) {
                        // TODO: do lucene here
                        Document doc = luceneBuilder.createDocument();
                        doc.add(luceneBuilder.createField("IdentityKey", key.toString()));
                        docList.add(doc);
                    }
                } else if (keyType == Integer.class) {
                    for (Object key : identityKeyList) {
                        // TODO: do lucene here
                        Document doc = luceneBuilder.createDocument();
                        doc.add(luceneBuilder.createField("IdentityKey", (Integer) key));
                        docList.add(doc);
                    }
                } else if (keyType == Long.class) {
                    for (Object key : identityKeyList) {
                        // TODO: do lucene here
                        Document doc = luceneBuilder.createDocument();
                        doc.add(luceneBuilder.createField("IdentityKey", (Long) key));
                        docList.add(doc);
                    }
                } else if (keyType == Float.class) {
                    for (Object key : identityKeyList) {
                        // TODO: do lucene here
                        Document doc = luceneBuilder.createDocument();
                        doc.add(luceneBuilder.createField("IdentityKey", (Float) key));
                        docList.add(doc);
                    }
                } else if (keyType == Double.class) {
                    for (Object key : identityKeyList) {
                        // TODO: do lucene here
                        Document doc = luceneBuilder.createDocument();
                        doc.add(luceneBuilder.createField("IdentityKey", (Double) key));
                        docList.add(doc);
                    }
                }
                try {
                    writer.addDocuments(docList);
                } catch (Exception ex) {
                    Logger.warning(ex);
                }
            } else {
                try {
                    // fields
                    if (fields != null && fields.length > 0) {

                        // configure numeric types
                        for (Field field : fields) {
                            configNumericType(parser, field.getName(), field.getType());
                        }

                        List<Document> docList = new ArrayList();
                        for (Object key : identityKeyList) {
                            Document doc = luceneBuilder.createDocument();
                            for (Field field : fields) {
                                Object obj = field.get(key);
                                Class fieldType = field.getType();
                                if (fieldType == String.class) {
                                    doc.add(luceneBuilder.createField(field.getName(), obj.toString()));
                                } else if (fieldType == Integer.class || fieldType == int.class) {
                                    doc.add(luceneBuilder.createField(field.getName(), (Integer) obj));
                                } else if (fieldType == Long.class || fieldType == long.class) {
                                    doc.add(luceneBuilder.createField(field.getName(), (Long) obj));
                                } else if (fieldType == Float.class || fieldType == float.class) {
                                    doc.add(luceneBuilder.createField(field.getName(), (Float) obj));
                                } else if (fieldType == Double.class || fieldType == double.class) {
                                    doc.add(luceneBuilder.createField(field.getName(), (Double) obj));
                                } else if (fieldType == Date.class) {
                                    doc.add(luceneBuilder.createField(field.getName(), ((Date) obj).getTime()));
                                }
                            }
                            docList.add(doc);
                        }
                        try {
                            writer.addDocuments(docList);
                        } catch (Exception ex) {
                            Logger.warning(ex);
                        }
                    }

                    // getters - methods
                    if (getters != null && getters.length > 0) {
                        List<Document> docList = new ArrayList();
                        for (Object key : identityKeyList) {
                            Document doc = luceneBuilder.createDocument();
                            for (Method method : getters) {
                                // TODO: build lucene here
                                Object obj = method.invoke(key);
                                Class<?> fieldType = method.getReturnType();
                                if (fieldType == String.class) {
                                    doc.add(luceneBuilder.createField(getPropertyName(method), obj.toString()));
                                } else if (fieldType == Integer.class || fieldType == int.class) {
                                    doc.add(luceneBuilder.createField(getPropertyName(method), (Integer) obj));
                                } else if (fieldType == Long.class || fieldType == long.class) {
                                    doc.add(luceneBuilder.createField(getPropertyName(method), (Long) obj));
                                } else if (fieldType == Float.class || fieldType == float.class) {
                                    doc.add(luceneBuilder.createField(getPropertyName(method), (Float) obj));
                                } else if (fieldType == Double.class || fieldType == double.class) {
                                    doc.add(luceneBuilder.createField(getPropertyName(method), (Double) obj));
                                } else if (fieldType == Date.class) {
                                    doc.add(luceneBuilder.createField(getPropertyName(method),
                                            ((Date) obj).getTime()));
                                }
                            }
                            docList.add(doc);
                        }
                        try {
                            writer.addDocuments(docList);
                        } catch (Exception ex) {
                            Logger.warning(ex);
                        }
                    }

                } catch (Exception ex) {
                    Logger.warning(ex);
                }
            }

            writer.commit();
            writer.close();

            // TODO: support file system
            // place the RamDirectory in lucene
            region.put(type.getFullPath(), directory);

        } catch (Exception ex) {
            Logger.error("Index builder aborted.", ex);
            return;
        }
    }
}

From source file:com.netcrest.pado.index.provider.lucene.LuceneBuilderRAMDirectory.java

License:Open Source License

@SuppressWarnings({ "rawtypes", "resource" })
public void buildTemporalData(boolean createNewDirectory) {
    Cache cache = CacheFactory.getAnyInstance();
    Region<String, RAMDirectory> region = cache
            .getRegion(IndexMatrixUtil.getProperty(Constants.PROP_REGION_LUCENE));

    try {//w ww .  j  a v a  2 s. c  om
        TemporalType[] temporalTypes = GemfireTemporalManager.getAllTemporalTypes();
        for (TemporalType type : temporalTypes) {
            IndexWriter writer = null;
            Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_47);
            IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_47, analyzer);
            iwc.setOpenMode(OpenMode.CREATE);
            LuceneField luceneBuilder = new LuceneField();

            LuceneSearch ls = LuceneSearch.getLuceneSearch(type.getFullPath());
            StandardQueryParser parser = ls.createParser();
            TemporalManager tm = TemporalManager.getTemporalManager(type.getFullPath());
            Method[] attributeGetters = null;
            boolean isIdentityKeyPrimitive = false;
            try {
                List identityKeyList = tm.getIdentityKeyList();
                if (identityKeyList.size() == 0) {
                    continue;
                }

                RAMDirectory directory;
                if (createNewDirectory) {
                    directory = new RAMDirectory();
                } else {
                    directory = region.get(type.getFullPath());
                    if (directory == null) {
                        directory = new RAMDirectory();
                    }
                }
                writer = new IndexWriter(directory, iwc);

                // first, find the attribute getter methods
                boolean isKeyMap = false;
                KeyType keyType = null;
                for (Object identityKey : identityKeyList) {
                    TemporalEntry entry = tm.getLastEntry(identityKey);
                    ITemporalData data = entry.getTemporalData();
                    Object value;
                    if (data instanceof GemfireTemporalData) {
                        value = ((GemfireTemporalData) data).getValue();
                    } else {
                        value = data;
                    }
                    isKeyMap = value instanceof KeyMap;
                    if (isKeyMap == false) {
                        attributeGetters = ReflectionHelper.getAttributeGetters(data.getClass());
                    } else {
                        keyType = ((KeyMap) value).getKeyType();

                    }
                    isIdentityKeyPrimitive = ReflectionHelper.isPrimitiveWrapper(identityKey.getClass());
                    break;
                }

                // build the numeric config
                Map<String, NumericConfig> map = parser.getNumericConfigMap();
                if (map == null) {
                    map = new HashMap<String, NumericConfig>();
                    parser.setNumericConfigMap(map);
                }

                if (isKeyMap) {

                    KeyType[] keyTypes = KeyTypeManager.getAllRegisteredVersions(keyType.getClass());
                    for (KeyType kt : keyTypes) {
                        Set<String> nameSet = kt.getNameSet();
                        for (String name : nameSet) {
                            if (map.containsKey(name)) {
                                continue;
                            }
                            KeyType kt2 = kt.getKeyType(name);
                            String fieldName = kt2.getName();
                            Class<?> fieldType = kt2.getType();

                            if (fieldType == Integer.class || fieldType == int.class) {
                                NumericConfig config = new NumericConfig(PRECISION_STEP,
                                        NumberFormat.getNumberInstance(), NumericType.INT);
                                map.put(fieldName, config);
                            } else if (fieldType == Long.class || fieldType == long.class) {
                                NumericConfig config = new NumericConfig(PRECISION_STEP,
                                        NumberFormat.getNumberInstance(), NumericType.LONG);
                                map.put(fieldName, config);
                            } else if (fieldType == Float.class || fieldType == float.class) {
                                NumericConfig config = new NumericConfig(PRECISION_STEP,
                                        NumberFormat.getNumberInstance(), NumericType.FLOAT);
                                map.put(fieldName, config);
                            } else if (fieldType == Double.class || fieldType == double.class) {
                                NumericConfig config = new NumericConfig(PRECISION_STEP,
                                        NumberFormat.getNumberInstance(), NumericType.DOUBLE);
                                map.put(fieldName, config);
                            } else if (fieldType == Date.class) {
                                NumericConfig config = new NumericConfig(PRECISION_STEP, DATE_FORMAT,
                                        NumericType.LONG);
                                map.put(fieldName, config);
                            }
                        }
                    }

                    List<Document> docList = new ArrayList<Document>();

                    for (Object identityKey : identityKeyList) {
                        TemporalEntry entry = tm.getLastEntry(identityKey);
                        ITemporalData data = entry.getTemporalData();
                        KeyMap keyMap;
                        if (data instanceof GemfireTemporalData) {
                            keyMap = (KeyMap) ((GemfireTemporalData) data).getValue();
                        } else {
                            keyMap = (KeyMap) data;
                        }
                        keyType = keyMap.getKeyType();
                        Set<String> nameSet = keyType.getNameSet();

                        Document doc = luceneBuilder.createDocument();
                        if (isIdentityKeyPrimitive) {
                            doc.add(luceneBuilder.createField("IdentityKey", identityKey.toString()));
                        } else {
                            doc.add(luceneBuilder.createIdentityKeyField(identityKey));
                        }
                        for (String name : nameSet) {
                            Object obj = keyMap.get(name);
                            // obj can be null (e.g., version difference or
                            // app defined)
                            if (obj == null) {
                                continue;
                            }
                            KeyType kt = keyType.getKeyType(name);
                            Class fieldType = kt.getType();
                            if (fieldType == String.class) {
                                doc.add(luceneBuilder.createField(name, obj.toString()));
                            } else if (fieldType == Integer.class || fieldType == int.class) {
                                doc.add(luceneBuilder.createField(name, (Integer) obj));
                            } else if (fieldType == Long.class || fieldType == long.class) {
                                doc.add(luceneBuilder.createField(name, (Long) obj));
                            } else if (fieldType == Float.class || fieldType == float.class) {
                                doc.add(luceneBuilder.createField(name, (Float) obj));
                            } else if (fieldType == Double.class || fieldType == double.class) {
                                doc.add(luceneBuilder.createField(name, (Double) obj));
                            } else if (fieldType == Date.class) {
                                doc.add(luceneBuilder.createField(name, ((Date) obj).getTime()));
                            }
                        }
                        docList.add(doc);
                    }
                    try {
                        writer.addDocuments(docList);
                    } catch (Exception ex) {
                        Logger.warning("MapLite error", ex);
                    }

                } else {
                    for (Method method : attributeGetters) {
                        Class fieldType = method.getReturnType();
                        String fieldName = method.getName().substring(3);
                        if (fieldType == Integer.class || fieldType == int.class) {
                            NumericConfig config = new NumericConfig(PRECISION_STEP,
                                    NumberFormat.getNumberInstance(), NumericType.INT);
                            map.put(fieldName, config);
                        } else if (fieldType == Long.class || fieldType == long.class) {
                            NumericConfig config = new NumericConfig(PRECISION_STEP,
                                    NumberFormat.getNumberInstance(), NumericType.LONG);
                            map.put(fieldName, config);
                        } else if (fieldType == Float.class || fieldType == float.class) {
                            NumericConfig config = new NumericConfig(PRECISION_STEP,
                                    NumberFormat.getNumberInstance(), NumericType.FLOAT);
                            map.put(fieldName, config);
                        } else if (fieldType == Double.class || fieldType == double.class) {
                            NumericConfig config = new NumericConfig(PRECISION_STEP,
                                    NumberFormat.getNumberInstance(), NumericType.DOUBLE);
                            map.put(fieldName, config);
                        } else if (fieldType == Date.class) {
                            NumericConfig config = new NumericConfig(PRECISION_STEP, DATE_FORMAT,
                                    NumericType.LONG);
                            map.put(fieldName, config);
                        }
                    }

                    // build lucene for each attribute in the current
                    // (latest)
                    // data
                    if (attributeGetters != null && attributeGetters.length > 0) {
                        List<Document> docList = new ArrayList<Document>();

                        for (Object identityKey : identityKeyList) {
                            TemporalEntry entry = tm.getLastEntry(identityKey);
                            ITemporalData data = entry.getTemporalData();
                            Document doc = luceneBuilder.createDocument();
                            if (isIdentityKeyPrimitive) {
                                doc.add(luceneBuilder.createField("IdentityKey", identityKey.toString()));
                            } else {
                                doc.add(luceneBuilder.createIdentityKeyField(identityKey));
                            }
                            for (Method method : attributeGetters) {
                                Object obj = method.invoke(data);
                                Class fieldType = method.getReturnType();
                                if (fieldType == String.class) {
                                    doc.add(luceneBuilder.createField(getPropertyName(method), obj.toString()));
                                } else if (fieldType == Integer.class || fieldType == int.class) {
                                    doc.add(luceneBuilder.createField(getPropertyName(method), (Integer) obj));
                                } else if (fieldType == Long.class || fieldType == long.class) {
                                    doc.add(luceneBuilder.createField(getPropertyName(method), (Long) obj));
                                } else if (fieldType == Float.class || fieldType == float.class) {
                                    doc.add(luceneBuilder.createField(getPropertyName(method), (Float) obj));
                                } else if (fieldType == Double.class || fieldType == double.class) {
                                    doc.add(luceneBuilder.createField(getPropertyName(method), (Double) obj));
                                } else if (fieldType == Date.class) {
                                    doc.add(luceneBuilder.createField(getPropertyName(method),
                                            ((Date) obj).getTime()));
                                }
                            }
                            docList.add(doc);
                        }
                        try {
                            writer.addDocuments(docList);
                        } catch (Exception ex) {
                            Logger.warning("Non-MapLite error", ex);
                        }
                    }
                }

                writer.commit();
                writer.close();

                // TODO: support file system
                // place the RamDirectory in the lucene
                region.put(type.getFullPath(), directory);

            } catch (Exception ex) {
                Logger.warning(ex);
            }
        }
    } catch (Exception ex) {
        Logger.warning("Index builder aborted.", ex);
    }
}