Example usage for org.apache.solr.common.params SpatialParams FIELD

List of usage examples for org.apache.solr.common.params SpatialParams FIELD

Introduction

In this page you can find the example usage for org.apache.solr.common.params SpatialParams FIELD.

Prototype

String FIELD

To view the source code for org.apache.solr.common.params SpatialParams FIELD.

Click Source Link

Usage

From source file:com.gogobot.DistanceParser.java

License:Apache License

private MultiValueSource parseSfield(FunctionQParser fp) throws SyntaxError {
    String sfield = fp.getParam(SpatialParams.FIELD);
    if (sfield == null)
        return null;
    SchemaField sf = fp.getReq().getSchema().getField(sfield);
    FieldType type = sf.getType();//from w  ww .ja  va  2s  .co  m
    if (type instanceof AbstractSpatialFieldType) {
        AbstractSpatialFieldType asft = (AbstractSpatialFieldType) type;
        return new SpatialStrategyMultiValueSource(asft.getStrategy(sfield));
    }
    ValueSource vs = type.getValueSource(sf, fp);
    if (vs instanceof MultiValueSource) {
        return (MultiValueSource) vs;
    }
    throw new SyntaxError(
            "Spatial field must implement MultiValueSource or extend AbstractSpatialFieldType:" + sf);
}

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 {/*www.j  ava  2 s  . 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 parseSfield(FunctionQParser fp) throws ParseException {
    String sfield = fp.getParam(SpatialParams.FIELD);
    if (sfield == null)
        return null;
    SchemaField sf = fp.getReq().getSchema().getField(sfield);
    ValueSource vs = sf.getType().getValueSource(sf, fp);
    if (!(vs instanceof MultiValueSource)) {
        throw new ParseException("Spatial field must implement MultiValueSource:" + sf);
    }/*from   w  w  w. j  a  va  2  s.c  o  m*/
    return (MultiValueSource) vs;
}