List of usage examples for org.apache.solr.common.params SpatialParams POINT
String POINT
To view the source code for org.apache.solr.common.params SpatialParams POINT.
Click Source Link
From source file:com.gogobot.DistanceParser.java
License:Apache License
private MultiValueSource parsePoint(FunctionQParser fp) throws SyntaxError { String pt = fp.getParam(SpatialParams.POINT); if (pt == null) return null; double[] point = null; try {//from w ww .ja v a 2 s .co m point = ParseUtils.parseLatitudeLongitude(pt); } catch (InvalidShapeException e) { throw new SyntaxError("Bad spatial pt:" + pt); } return new VectorValueSource(Arrays.<ValueSource>asList(new DoubleConstValueSource(point[0]), new DoubleConstValueSource(point[1]))); }
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 ww w . j av a2s .c om 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); } }); }
From source file:solr2155.solr.search.function.distance.HaversineConstFunction.java
License:Apache License
private static MultiValueSource parsePoint(FunctionQParser fp) throws ParseException { String pt = fp.getParam(SpatialParams.POINT); if (pt == null) return null; double[] point = null; try {//from ww w . j a va 2 s.c o m point = DistanceUtils.parseLatitudeLongitude(pt); } catch (InvalidGeoException e) { throw new ParseException("Bad spatial pt:" + pt); } return new VectorValueSource(Arrays.asList( new ValueSource[] { new DoubleConstValueSource(point[0]), new DoubleConstValueSource(point[1]) })); }