use of org.locationtech.spatial4j.shape.Shape in project lucene-solr by apache.
the class SpatialArgsTest method calcDistanceFromErrPct.
@Test
public void calcDistanceFromErrPct() {
final SpatialContext ctx = SpatialContext.GEO;
//distErrPct
final double DEP = 0.5;
//the result is the diagonal distance from the center to the closest corner,
// times distErrPct
Shape superwide = ctx.makeRectangle(-180, 180, 0, 0);
//0 distErrPct means 0 distance always
assertEquals(0, SpatialArgs.calcDistanceFromErrPct(superwide, 0, ctx), 0);
assertEquals(180 * DEP, SpatialArgs.calcDistanceFromErrPct(superwide, DEP, ctx), 0);
Shape supertall = ctx.makeRectangle(0, 0, -90, 90);
assertEquals(90 * DEP, SpatialArgs.calcDistanceFromErrPct(supertall, DEP, ctx), 0);
Shape upperhalf = ctx.makeRectangle(-180, 180, 0, 90);
assertEquals(45 * DEP, SpatialArgs.calcDistanceFromErrPct(upperhalf, DEP, ctx), 0.0001);
Shape midCircle = ctx.makeCircle(0, 0, 45);
assertEquals(60 * DEP, SpatialArgs.calcDistanceFromErrPct(midCircle, DEP, ctx), 0.0001);
}
use of org.locationtech.spatial4j.shape.Shape in project lucene-solr by apache.
the class SpatialExample method newSampleDocument.
private Document newSampleDocument(int id, Shape... shapes) {
Document doc = new Document();
doc.add(new StoredField("id", id));
doc.add(new NumericDocValuesField("id", id));
// strategies; see the javadocs of the SpatialStrategy impl to see.
for (Shape shape : shapes) {
for (Field f : strategy.createIndexableFields(shape)) {
doc.add(f);
}
//store it too; the format is up to you
// (assume point in this example)
Point pt = (Point) shape;
doc.add(new StoredField(strategy.getFieldName(), pt.getX() + " " + pt.getY()));
}
return doc;
}
use of org.locationtech.spatial4j.shape.Shape in project lucene-solr by apache.
the class DistanceToShapeValueSource method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FunctionValues shapeValues = shapeValueSource.getValues(context, readerContext);
return new DoubleDocValues(this) {
@Override
public double doubleVal(int doc) throws IOException {
Shape shape = (Shape) shapeValues.objectVal(doc);
if (shape == null || shape.isEmpty())
return nullValue;
Point pt = shape.getCenter();
return distCalc.distance(queryPoint, pt) * multiplier;
}
@Override
public Explanation explain(int doc) throws IOException {
Explanation exp = super.explain(doc);
List<Explanation> details = new ArrayList<>(Arrays.asList(exp.getDetails()));
details.add(shapeValues.explain(doc));
return Explanation.match(exp.getValue(), exp.getDescription(), details);
}
};
}
use of org.locationtech.spatial4j.shape.Shape in project lucene-solr by apache.
the class ShapePredicateValueSource method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FunctionValues shapeValues = shapeValuesource.getValues(context, readerContext);
return new BoolDocValues(this) {
@Override
public boolean boolVal(int doc) throws IOException {
Shape indexedShape = (Shape) shapeValues.objectVal(doc);
if (indexedShape == null)
return false;
return op.evaluate(indexedShape, queryShape);
}
@Override
public Explanation explain(int doc) throws IOException {
Explanation exp = super.explain(doc);
List<Explanation> details = new ArrayList<>(Arrays.asList(exp.getDetails()));
details.add(shapeValues.explain(doc));
return Explanation.match(exp.getValue(), exp.getDescription(), details);
}
};
}
use of org.locationtech.spatial4j.shape.Shape in project lucene-solr by apache.
the class DistanceStrategyTest method testRecipScore.
@Test
public void testRecipScore() throws IOException {
Point p100 = ctx.makePoint(2.02, 0.98);
adoc("100", p100);
Point p101 = ctx.makePoint(-1.001, 4.001);
adoc("101", p101);
//test score for nothing
adoc("103", (Shape) null);
//test deleted
adoc("999", ctx.makePoint(2, 1));
commit();
deleteDoc("999");
commit();
double dist = ctx.getDistCalc().distance(p100, p101);
Shape queryShape = ctx.makeCircle(2.01, 0.99, dist);
checkValueSource(strategy.makeRecipDistanceValueSource(queryShape), new float[] { 1.00f, 0.10f, 0f }, 0.09f);
}
Aggregations