use of org.codice.ddf.spatial.geocoding.GeoEntry in project ddf by codice.
the class TestGeoNamesCreator method testNoEmptyFields.
@Test
public void testNoEmptyFields() {
final String geoNamesEntryStr = "5289282\tChandler\tChandler\t" + "Candler,Candleris,Chandler,Chandlur\t33.30616\t-111.84125\tP\tPPL\tUS\tUS\tAZ\t" + "013\t012\t011\t236123\t370\t368\tAmerica/Phoenix\t2011-05-14";
final GeoEntry geoEntry = GEONAMES_CREATOR.createGeoEntry(geoNamesEntryStr);
verifyGeoEntry(geoEntry, "Chandler", 33.30616, -111.84125, "PPL", 236123, "Candler,Candleris,Chandler,Chandlur", "US");
}
use of org.codice.ddf.spatial.geocoding.GeoEntry in project ddf by codice.
the class TestGeoNamesCreator method testNotTabDelimited.
@Test(expected = ArrayIndexOutOfBoundsException.class)
public void testNotTabDelimited() {
final String wrongFormat = "5289282,Chandler,Chandler," + "Candler,Candleris,Chandler,Chandlu,33.30616,-111.84125,P,PPL,US,US,AZ," + "013,012,011,236123,370,368,America/Phoenix,2011-05-14";
final GeoEntry geoEntry = GEONAMES_CREATOR.createGeoEntry(wrongFormat);
}
use of org.codice.ddf.spatial.geocoding.GeoEntry in project ddf by codice.
the class TestGeoNamesCreator method testNotEnoughFields.
@Test(expected = ArrayIndexOutOfBoundsException.class)
public void testNotEnoughFields() {
final String wrongFormat = "5288858\tCave Creek\tCave Creek\tAlternate names\t33.83333";
final GeoEntry geoEntry = GEONAMES_CREATOR.createGeoEntry(wrongFormat);
}
use of org.codice.ddf.spatial.geocoding.GeoEntry in project ddf by codice.
the class GeoNamesQueryLuceneIndex method doQuery.
protected List<GeoEntry> doQuery(final String queryString, final int maxResults, final Directory directory) throws GeoEntryQueryException {
if (StringUtils.isBlank(queryString)) {
throw new IllegalArgumentException("The query string cannot be null or empty.");
}
if (maxResults < 1) {
throw new IllegalArgumentException("maxResults must be positive.");
}
if (directory == null) {
return Collections.emptyList();
}
try (final IndexReader indexReader = createIndexReader(directory)) {
final IndexSearcher indexSearcher = createIndexSearcher(indexReader);
final Query query = createQuery(queryString);
final TopDocs topDocs = indexSearcher.search(query, maxResults);
if (topDocs.totalHits > 0) {
final List<GeoEntry> results = new ArrayList<>();
for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
final Document document = indexSearcher.doc(scoreDoc.doc);
// The alternate names aren't being stored (they are only used for queries),
// so we don't retrieve them here.
results.add(new GeoEntry.Builder().name(document.get(GeoNamesLuceneConstants.NAME_FIELD)).latitude(Double.parseDouble(document.get(GeoNamesLuceneConstants.LATITUDE_FIELD))).longitude(Double.parseDouble(document.get(GeoNamesLuceneConstants.LONGITUDE_FIELD))).featureCode(document.get(GeoNamesLuceneConstants.FEATURE_CODE_FIELD)).population(Long.parseLong(document.get(GeoNamesLuceneConstants.POPULATION_FIELD))).countryCode(document.get(GeoNamesLuceneConstants.COUNTRY_CODE_FIELD)).build());
}
return results;
} else {
return Collections.emptyList();
}
} catch (IOException e) {
throw new GeoEntryQueryException("Error reading the index", e);
} catch (ParseException e) {
throw new GeoEntryQueryException("Error parsing query", e);
}
}
use of org.codice.ddf.spatial.geocoding.GeoEntry in project ddf by codice.
the class TestGeoNamesLuceneIndexerExceptions method testExceptionWhenAddingDocumentByExtractor.
@Test
public void testExceptionWhenAddingDocumentByExtractor() throws GeoEntryIndexingException, GeoEntryExtractionException, GeoNamesRemoteDownloadException, IOException {
configureMocks();
geoNamesLuceneIndexer.setIndexLocation(ABSOLUTE_PATH + TEST_PATH + "index");
try {
final GeoEntryExtractor geoEntryExtractor = new GeoEntryExtractor() {
@Override
public List<GeoEntry> getGeoEntries(final String resource, final ProgressCallback progressCallback) {
return null;
}
@Override
public void pushGeoEntriesToExtractionCallback(final String resource, final ExtractionCallback extractionCallback) throws GeoEntryExtractionException {
extractionCallback.updateProgress(0);
try {
extractionCallback.extracted(GEO_ENTRY);
} catch (GeoEntryIndexingException e) {
throw new GeoEntryExtractionException("Unable to add entry.", e);
}
}
@Override
public void setUrl(String url) {
return;
}
};
geoNamesLuceneIndexer.updateIndex("", geoEntryExtractor, true, null);
fail("Should have thrown a GeoEntryExtractionException; extractionCallback.extract() threw " + "a GeoEntryIndexingException because addDocument() threw an " + "IOException.");
} catch (GeoEntryExtractionException e) {
assertThat(e.getCause(), instanceOf(GeoEntryIndexingException.class));
}
}
Aggregations