List of usage examples for org.apache.solr.common.params SpatialParams DISTANCE
String DISTANCE
To view the source code for org.apache.solr.common.params SpatialParams DISTANCE.
Click Source Link
From source file:org.eclipse.rdf4j.sail.solr.SolrIndex.java
License:Open Source License
@Override protected Iterable<? extends DocumentDistance> geoQuery(URI geoProperty, Point p, final URI units, double distance, String distanceVar, Var contextVar) throws MalformedQueryException, IOException { double kms = GeoUnits.toKilometres(distance, units); String qstr = "{!geofilt score=recipDistance}"; if (contextVar != null) { Resource ctx = (Resource) contextVar.getValue(); String tq = termQuery(SearchFields.CONTEXT_FIELD_NAME, SearchFields.getContextID(ctx)); if (ctx != null) { qstr = tq + " AND " + qstr; } else {//from w w w .j a v a 2s. c o m qstr = "-" + tq + " AND " + qstr; } } SolrQuery q = new SolrQuery(qstr); q.set(SpatialParams.FIELD, SearchFields.getPropertyField(geoProperty)); q.set(SpatialParams.POINT, p.getY() + "," + p.getX()); q.set(SpatialParams.DISTANCE, Double.toString(kms)); q.addField(SearchFields.URI_FIELD_NAME); // ':' is part of the fl parameter syntax so we can't use the full // property field name // instead we use wildcard + local part of the property URI q.addField("*" + geoProperty.getLocalName()); // always include the distance - needed for sanity checking q.addField(DISTANCE_FIELD + ":geodist()"); boolean requireContext = (contextVar != null && !contextVar.hasValue()); if (requireContext) { q.addField(SearchFields.CONTEXT_FIELD_NAME); } QueryResponse response; try { response = search(q); } catch (SolrServerException e) { throw new IOException(e); } SolrDocumentList results = response.getResults(); return Iterables.transform(results, new Function<SolrDocument, DocumentDistance>() { @Override public DocumentDistance apply(SolrDocument document) { SolrSearchDocument doc = new SolrSearchDocument(document); return new SolrDocumentDistance(doc, units); } }); }