use of org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree in project lucene-solr by apache.
the class PortedSolr3Test method parameters.
@ParametersFactory(argumentFormatting = "strategy=%s")
public static Iterable<Object[]> parameters() {
List<Object[]> ctorArgs = new ArrayList<>();
SpatialContext ctx = SpatialContext.GEO;
SpatialPrefixTree grid;
SpatialStrategy strategy;
grid = new GeohashPrefixTree(ctx, 12);
strategy = new RecursivePrefixTreeStrategy(grid, "recursive_geohash");
ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
grid = new QuadPrefixTree(ctx, 25);
strategy = new RecursivePrefixTreeStrategy(grid, "recursive_quad");
ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
grid = new GeohashPrefixTree(ctx, 12);
strategy = new TermQueryPrefixTreeStrategy(grid, "termquery_geohash");
ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
strategy = PointVectorStrategy.newInstance(ctx, "pointvector");
ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
strategy = PointVectorStrategy.newInstance(ctx, "pointvector_legacy");
ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
return ctorArgs;
}
use of org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree in project lucene-solr by apache.
the class QueryEqualsHashCodeTest method testEqualsHashCode.
@Test
public void testEqualsHashCode() {
switch(//0-3
random().nextInt(4)) {
case 0:
predicate = SpatialOperation.Contains;
break;
case 1:
predicate = SpatialOperation.IsWithin;
break;
default:
predicate = SpatialOperation.Intersects;
break;
}
final SpatialPrefixTree gridQuad = new QuadPrefixTree(ctx, 10);
final SpatialPrefixTree gridGeohash = new GeohashPrefixTree(ctx, 10);
Collection<SpatialStrategy> strategies = new ArrayList<>();
RecursivePrefixTreeStrategy recursive_geohash = new RecursivePrefixTreeStrategy(gridGeohash, "recursive_geohash");
strategies.add(recursive_geohash);
strategies.add(new TermQueryPrefixTreeStrategy(gridQuad, "termquery_quad"));
strategies.add(PointVectorStrategy.newInstance(ctx, "pointvector"));
strategies.add(BBoxStrategy.newInstance(ctx, "bbox"));
final SerializedDVStrategy serialized = new SerializedDVStrategy(ctx, "serialized");
strategies.add(serialized);
strategies.add(new CompositeSpatialStrategy("composite", recursive_geohash, serialized));
for (SpatialStrategy strategy : strategies) {
testEqualsHashcode(strategy);
}
}
use of org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree in project ddf by codice.
the class GeoNamesQueryLuceneIndex method createSpatialQuery.
private Query createSpatialQuery(Point shapeCenter, int radiusInKm) {
final SpatialPrefixTree grid = new GeohashPrefixTree(SPATIAL_CONTEXT, GeoNamesLuceneConstants.GEOHASH_LEVELS);
final SpatialStrategy strategy = new RecursivePrefixTreeStrategy(grid, GeoNamesLuceneConstants.GEO_FIELD);
// Create a spatial filter that will select the documents that are in the specified
// search radius around the metacard's center.
final double searchRadiusDegrees = radiusInKm * DistanceUtils.KM_TO_DEG;
final SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, SPATIAL_CONTEXT.getShapeFactory().circle(shapeCenter, searchRadiusDegrees));
return strategy.makeQuery(args);
}
use of org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree 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