List of usage examples for org.apache.lucene.spatial SpatialStrategy makeQuery
public abstract Query makeQuery(SpatialArgs args);
From source file:com.stratio.cassandra.lucene.search.condition.DateRangeCondition.java
License:Apache License
/** * {@inheritDoc}//from w w w .j a v a 2 s . co m */ @Override public Query query(Schema schema) { Mapper columnMapper = schema.getMapper(field); if (!(columnMapper instanceof DateRangeMapper)) { throw new IllegalArgumentException("Date range mapper required"); } DateRangeMapper mapper = (DateRangeMapper) columnMapper; SpatialStrategy strategy = mapper.getStrategy(); Date start = mapper.base(this.start); Date stop = mapper.base(this.stop); NRShape shape = mapper.makeShape(start, stop); SpatialOperation spatialOperation = parseSpatialOperation(operation); SpatialArgs args = new SpatialArgs(spatialOperation, shape); Query query = strategy.makeQuery(args); query.setBoost(boost); return query; }
From source file:com.stratio.cassandra.lucene.search.condition.GeoBBoxCondition.java
License:Apache License
/** {@inheritDoc} */ @Override//from ww w. j a va2s . c o m public Query query(Schema schema) { Mapper mapper = schema.getMapper(field); if (!(mapper instanceof GeoPointMapper)) { throw new IllegalArgumentException("Geo point mapper required"); } GeoPointMapper geoPointMapper = (GeoPointMapper) mapper; SpatialStrategy spatialStrategy = geoPointMapper.getStrategy(); Rectangle rectangle = spatialContext.makeRectangle(minLongitude, maxLongitude, minLatitude, maxLatitude); SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, rectangle); Query query = spatialStrategy.makeQuery(args); query.setBoost(boost); return query; }
From source file:com.stratio.cassandra.lucene.search.condition.GeoDistanceCondition.java
License:Apache License
private Query query(GeoDistance geoDistance, SpatialStrategy spatialStrategy) { double kms = geoDistance.getValue(GeoDistanceUnit.KILOMETRES); double distance = DistanceUtils.dist2Degrees(kms, DistanceUtils.EARTH_MEAN_RADIUS_KM); Circle circle = spatialContext.makeCircle(longitude, latitude, distance); SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle); return spatialStrategy.makeQuery(args); }
From source file:com.stratio.cassandra.lucene.search.condition.GeoShapeCondition.java
License:Apache License
/** {@inheritDoc} */ @Override// w w w.j a v a 2 s. c o m public Query query(Schema schema) { // Get the spatial strategy from the mapper SpatialStrategy strategy; Mapper mapper = schema.getMapper(field); if (mapper == null) { throw new IndexException("No mapper found for field '%s'", field); } else if (mapper instanceof GeoShapeMapper) { strategy = ((GeoShapeMapper) mapper).strategy; } else if (mapper instanceof GeoPointMapper) { strategy = ((GeoPointMapper) mapper).distanceStrategy; } else { throw new IndexException( "'geo_shape' search requires a mapper of type 'geo_point' or 'geo_shape' " + "but found %s:%s", field, mapper); } // Apply transformations JtsGeometry transformedGeometry = geometry; if (transformations != null) { for (GeoTransformation transformation : transformations) { transformedGeometry = transformation.apply(transformedGeometry, CONTEXT); } } // Build query SpatialArgs args = new SpatialArgs(operation.getSpatialOperation(), transformedGeometry); args.setDistErr(0.0); Query query = strategy.makeQuery(args); query.setBoost(boost); return query; }
From source file:org.codice.ddf.spatial.geocoding.query.GeoNamesQueryLuceneIndex.java
License:Open Source License
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); }
From source file:org.eclipse.rdf4j.sail.lucene.LuceneIndex.java
License:Open Source License
@Override protected Iterable<? extends DocumentDistance> geoQuery(final URI geoProperty, Point p, final URI units, double distance, String distanceVar, Var contextVar) throws MalformedQueryException, IOException { double degs = GeoUnits.toDegrees(distance, units); final String geoField = SearchFields.getPropertyField(geoProperty); SpatialStrategy strategy = getSpatialStrategyMapper().apply(geoField); final Shape boundingCircle = strategy.getSpatialContext().makeCircle(p, degs); Query q = strategy.makeQuery(new SpatialArgs(SpatialOperation.Intersects, boundingCircle)); if (contextVar != null) { q = addContextTerm(q, (Resource) contextVar.getValue()); }//from ww w .j a va 2s .c o m TopDocs docs = search( new CustomScoreQuery(q, new FunctionQuery(strategy.makeRecipDistanceValueSource(boundingCircle)))); final boolean requireContext = (contextVar != null && !contextVar.hasValue()); return Iterables.transform(Arrays.asList(docs.scoreDocs), new Function<ScoreDoc, DocumentDistance>() { @Override public DocumentDistance apply(ScoreDoc doc) { return new LuceneDocumentDistance(doc, geoField, units, boundingCircle.getCenter(), requireContext, LuceneIndex.this); } }); }
From source file:org.eclipse.rdf4j.sail.lucene.LuceneIndex.java
License:Open Source License
@Override protected Iterable<? extends DocumentResult> geoRelationQuery(String relation, URI geoProperty, Shape shape, Var contextVar) throws MalformedQueryException, IOException { SpatialOperation op = toSpatialOp(relation); if (op == null) { return null; }//from w w w.j av a 2 s. co m final String geoField = SearchFields.getPropertyField(geoProperty); SpatialStrategy strategy = getSpatialStrategyMapper().apply(geoField); Query q = strategy.makeQuery(new SpatialArgs(op, shape)); if (contextVar != null) { q = addContextTerm(q, (Resource) contextVar.getValue()); } TopDocs docs = search(q); final Set<String> fields = Sets.newHashSet(SearchFields.URI_FIELD_NAME, geoField); if (contextVar != null && !contextVar.hasValue()) { fields.add(SearchFields.CONTEXT_FIELD_NAME); } return Iterables.transform(Arrays.asList(docs.scoreDocs), new Function<ScoreDoc, DocumentResult>() { @Override public DocumentResult apply(ScoreDoc doc) { return new LuceneDocumentResult(doc, LuceneIndex.this, fields); } }); }
From source file:org.openspaces.spatial.spi.LuceneSpatialQueryExtensionManager.java
License:Open Source License
@Override public QueryExtensionEntryIterator queryByIndex(String typeName, String path, String operationName, Object operand) {/*from w w w . j av a 2s .c o m*/ if (_logger.isLoggable(Level.FINE)) _logger.log(Level.FINE, "query [typeName=" + typeName + ", path=" + path + ", operation=" + operationName + ", operand=" + operand + "]"); final SpatialStrategy spatialStrategy = _luceneConfiguration.getStrategy(path); final Query query = spatialStrategy .makeQuery(new SpatialArgs(toOperation(operationName), toShape(operand))); final LuceneSpatialTypeIndex luceneHolder = _luceneHolderMap.get(typeName); try { // Flush luceneHolder.commit(true); DirectoryReader dr = DirectoryReader.open(luceneHolder.getDirectory()); IndexSearcher is = new IndexSearcher(dr); ScoreDoc[] scores = is.search(query, MAX_RESULTS).scoreDocs; return new LuceneSpatialQueryExtensionEntryIterator(scores, is, dr); } catch (IOException e) { throw new SpaceRuntimeException("Failed to scan index", e); } }