use of org.codice.ddf.spatial.geocoding.GeoEntryExtractionException in project ddf by codice.
the class GeoNamesLuceneIndexer method updateIndex.
@Override
public void updateIndex(final String resource, final GeoEntryExtractor geoEntryExtractor, final boolean create, final ProgressCallback progressCallback) throws GeoEntryIndexingException, GeoEntryExtractionException, GeoNamesRemoteDownloadException {
Directory directory;
try {
directory = FSDirectory.open(Paths.get(indexLocation));
} catch (IOException e) {
throw new GeoEntryIndexingException("Couldn't open the directory for the index, " + indexLocation, e);
}
// Try-with-resources to ensure the IndexWriter always gets closed.
try (final IndexWriter indexWriter = createIndexWriter(create, directory)) {
final SpatialPrefixTree grid = new GeohashPrefixTree(SPATIAL_CONTEXT, GeoNamesLuceneConstants.GEOHASH_LEVELS);
final SpatialStrategy strategy = new RecursivePrefixTreeStrategy(grid, GeoNamesLuceneConstants.GEO_FIELD);
final ExtractionCallback extractionCallback = new ExtractionCallback() {
@Override
public void extracted(final GeoEntry newEntry) throws GeoEntryIndexingException {
try {
addDocument(indexWriter, newEntry, strategy);
} catch (IOException e) {
throw new GeoEntryIndexingException("Error writing to the index.", e);
}
}
@Override
public void updateProgress(final int progress) {
if (progressCallback != null) {
progressCallback.updateProgress(progress);
}
}
};
try {
geoEntryExtractor.pushGeoEntriesToExtractionCallback(resource, extractionCallback);
} catch (GeoEntryExtractionException e) {
// Need to roll back here before the IndexWriter is closed at the end of the try
// block.
indexWriter.rollback();
throw e;
}
} catch (IOException e) {
throw new GeoEntryIndexingException("Error writing to the index.", e);
}
}
Aggregations