Example usage for org.apache.lucene.spatial.prefix PrefixTreeStrategy createIndexableFields

List of usage examples for org.apache.lucene.spatial.prefix PrefixTreeStrategy createIndexableFields

Introduction

In this page you can find the example usage for org.apache.lucene.spatial.prefix PrefixTreeStrategy createIndexableFields.

Prototype

@Override
    public Field[] createIndexableFields(Shape shape) 

Source Link

Usage

From source file:org.esa.beam.occci.LuceneCreateIndexMain.java

License:Open Source License

public static void main(String[] args) throws IOException, ParseException {
    if (args.length != 2) {
        printUsage();/*from   ww w  .  ja v  a2  s.c om*/
    }
    File productListFile = new File(args[0]);
    File indexfile = new File(args[1]);
    if (!productListFile.exists()) {
        System.err.printf("productList file '%s' does not exits%n", args[0]);
        printUsage();
    }
    List<EoProduct> eoProductList = ProductDB.readProducts("s2", productListFile);

    Directory indexDirectory = FSDirectory.open(indexfile.toPath());
    IndexWriterConfig config = new IndexWriterConfig(new SimpleAnalyzer());
    config.setRAMBufferSizeMB(100);

    DateRangePrefixTree dateRangePrefixTree = DateRangePrefixTree.INSTANCE;
    PrefixTreeStrategy strategy = new NumberRangePrefixTreeStrategy(dateRangePrefixTree, "productDateRange");

    final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", ENGLISH);
    dateFormat.setCalendar(GregorianCalendar.getInstance(UTC, Locale.ENGLISH));

    int indexCount = 0;
    try (IndexWriter indexWriter = new IndexWriter(indexDirectory, config)) {
        for (EoProduct eoProduct : eoProductList) {
            Document doc = new Document();
            doc.add(new StringField("name", eoProduct.getName(), Field.Store.YES));
            String start = dateFormat.format(new Date(eoProduct.getStartTime()));
            String end = dateFormat.format(new Date(eoProduct.getEndTime()));
            String range = "[" + start + " TO " + end + "]";

            NumberRangePrefixTree.NRShape nrShape = dateRangePrefixTree.parseShape(range);
            for (IndexableField f : strategy.createIndexableFields(nrShape)) {
                doc.add(f);
            }
            indexWriter.addDocument(doc);

            indexCount++;
            if (indexCount % 10_000 == 0) {
                System.out.println("indexCount = " + indexCount);
            }
        }

    }

}