Skip to content

Commit

Permalink
Refactor legacy builder.
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Oct 23, 2015
1 parent 980d8e9 commit b5769fd
Show file tree
Hide file tree
Showing 21 changed files with 250 additions and 155 deletions.
Expand Up @@ -63,7 +63,7 @@ public Object getInTx(Object key, OLuceneTxChanges changes) {
return newGeoSearch((Map<String, Object>) key, changes);

} else {
// TODO HANDLE EXCEPTION

}
} catch (Exception e) {
OLogManager.instance().error(this, "Error on getting entry against Lucene index", e);
Expand Down
Expand Up @@ -32,6 +32,8 @@
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.spatial.shape.OShapeBuilder;
import com.orientechnologies.orient.spatial.shape.legacy.OShapeBuilderLegacy;
import com.orientechnologies.orient.spatial.shape.legacy.OShapeBuilderLegacyImpl;
import com.spatial4j.core.distance.DistanceUtils;
import com.spatial4j.core.shape.Point;
import com.spatial4j.core.shape.Shape;
Expand All @@ -55,6 +57,8 @@
*/
public class OLuceneLegacySpatialIndexEngine extends OLuceneSpatialIndexEngineAbstract {

OShapeBuilderLegacy legacyBuilder = OShapeBuilderLegacyImpl.INSTANCE; ;

public OLuceneLegacySpatialIndexEngine(String indexName, OShapeBuilder factory) {
super(indexName, factory);
}
Expand Down Expand Up @@ -99,7 +103,7 @@ public Object searchWithin(OSpatialCompositeKey key, OCommandContext context) th

Set<OIdentifiable> result = new HashSet<OIdentifiable>();

Shape shape = factory.makeShape(key, ctx);
Shape shape = legacyBuilder.makeShape(key, ctx);
if (shape == null)
return null;
SpatialArgs args = new SpatialArgs(SpatialOperation.IsWithin, shape);
Expand Down Expand Up @@ -148,7 +152,7 @@ public void put(Object key, Object value) {
OCompositeKey compositeKey = (OCompositeKey) key;
Collection<OIdentifiable> container = (Collection<OIdentifiable>) value;
for (OIdentifiable oIdentifiable : container) {
addDocument(newGeoDocument(oIdentifiable, factory.makeShape(compositeKey, ctx)));
addDocument(newGeoDocument(oIdentifiable, legacyBuilder.makeShape(compositeKey, ctx)));
}
} else {

Expand Down
Expand Up @@ -17,7 +17,6 @@
package com.orientechnologies.lucene.operator;

import com.orientechnologies.lucene.collections.OSpatialCompositeKey;
import com.orientechnologies.orient.spatial.shape.OShapeFactory;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.ODatabase;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
Expand All @@ -29,6 +28,8 @@
import com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition;
import com.orientechnologies.orient.core.sql.operator.OIndexReuseType;
import com.orientechnologies.orient.core.sql.operator.OQueryTargetOperator;
import com.orientechnologies.orient.spatial.shape.legacy.OShapeBuilderLegacy;
import com.orientechnologies.orient.spatial.shape.legacy.OShapeBuilderLegacyImpl;
import com.spatial4j.core.context.SpatialContext;
import com.spatial4j.core.shape.Shape;
import com.spatial4j.core.shape.SpatialRelation;
Expand All @@ -39,7 +40,7 @@

public class OLuceneWithinOperator extends OQueryTargetOperator {

OShapeFactory shapeFactory = OShapeFactory.INSTANCE;
OShapeBuilderLegacy shapeFactory = OShapeBuilderLegacyImpl.INSTANCE;

public OLuceneWithinOperator() {
super("WITHIN", 5, false);
Expand Down Expand Up @@ -81,8 +82,7 @@ public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index,
if (indexResult == null || indexResult instanceof OIdentifiable)
cursor = new OIndexCursorSingleValue((OIdentifiable) indexResult, new OSpatialCompositeKey(keyParams));
else
cursor = new OIndexCursorCollectionValue(((Collection<OIdentifiable>) indexResult), new OSpatialCompositeKey(
keyParams));
cursor = new OIndexCursorCollectionValue(((Collection<OIdentifiable>) indexResult), new OSpatialCompositeKey(keyParams));

iContext.setVariable("$luceneIndex", true);
return cursor;
Expand Down
Expand Up @@ -54,6 +54,6 @@ public Object execute(Object iThis, OIdentifiable iCurrentRecord, Object iCurren

@Override
public String getSyntax() {
return "ST_AsBinary(<doc>)";
return "ST_AsBuffer(<doc>)";
}
}
Expand Up @@ -20,13 +20,11 @@

import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.db.record.ridbag.DoubleReferenceItem;
import com.orientechnologies.orient.core.sql.parser.OBinaryCompareOperator;
import com.orientechnologies.orient.core.sql.parser.OExpression;
import com.orientechnologies.orient.core.sql.parser.OFromClause;
import com.orientechnologies.orient.spatial.strategy.SpatialQueryBuilderWithin;
import com.orientechnologies.orient.spatial.strategy.SpatialQueryBuilderDWithin;
import com.spatial4j.core.shape.Shape;
import com.spatial4j.core.shape.SpatialRelation;

import java.util.Collection;

Expand All @@ -49,9 +47,9 @@ public Object execute(Object iThis, OIdentifiable iCurrentRecord, Object iCurren

Shape shape1 = factory.fromObject(iParams[1]);

Double distance = (Double) iParams[2];
Double distance = (Double) iParams[2];

return factory.operation().isWithInDistance(shape, shape1,distance);
return factory.operation().isWithInDistance(shape, shape1, distance);
}

@Override
Expand All @@ -75,6 +73,6 @@ public long estimate(OFromClause target, OBinaryCompareOperator operator, Object

@Override
protected String operator() {
return SpatialQueryBuilderWithin.NAME;
return SpatialQueryBuilderDWithin.NAME;
}
}
Expand Up @@ -90,11 +90,6 @@ public String asText(ShapeCollection<Shape> shapes) {
return GEOMETRY_FACTORY.createGeometryCollection(geometries).toText();
}

@Override
public ShapeCollection<Shape> fromText(String wkt) {
return null;
}

@Override
public ODocument toDoc(ShapeCollection<Shape> shapes) {

Expand Down
Expand Up @@ -50,11 +50,6 @@ public void initClazz(ODatabaseDocumentTx db) {
lineString.createProperty(COORDINATES, OType.EMBEDDEDLIST, OType.EMBEDDEDLIST);
}

@Override
public JtsGeometry fromText(String wkt) {
return null;
}

@Override
public JtsGeometry fromDoc(ODocument document) {

Expand Down
Expand Up @@ -63,11 +63,6 @@ public void initClazz(ODatabaseDocumentTx db) {
lineString.createProperty(COORDINATES, OType.EMBEDDEDLIST, OType.EMBEDDEDLIST);
}

@Override
public JtsGeometry fromText(String wkt) {
return null;
}

@Override
public ODocument toDoc(JtsGeometry shape) {
final MultiLineString geom = (MultiLineString) shape.getGeom();
Expand Down
Expand Up @@ -65,11 +65,6 @@ public void initClazz(ODatabaseDocumentTx db) {
multiPoint.createProperty(COORDINATES, OType.EMBEDDEDLIST, OType.EMBEDDEDLIST);
}

@Override
public JtsGeometry fromText(String wkt) {
return null;
}

@Override
public ODocument toDoc(final JtsGeometry shape) {
final MultiPoint geom = (MultiPoint) shape.getGeom();
Expand Down
Expand Up @@ -86,8 +86,4 @@ public ODocument toDoc(JtsGeometry shape) {
return doc;
}

@Override
public JtsGeometry fromText(String wkt) {
return null;
}
}
Expand Up @@ -17,13 +17,11 @@
package com.orientechnologies.orient.spatial.shape;

import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.index.OCompositeKey;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OProperty;
import com.orientechnologies.orient.core.metadata.schema.OSchemaProxy;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.spatial4j.core.context.SpatialContext;
import com.spatial4j.core.shape.Point;

import java.util.ArrayList;
Expand All @@ -43,26 +41,26 @@ public OShapeType getType() {
return OShapeType.POINT;
}

@Override
public Point makeShape(OCompositeKey key, SpatialContext ctx) {
double lat = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(0), Double.class)).doubleValue();
double lng = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(1), Double.class)).doubleValue();
return ctx.makePoint(lng, lat);

}

@Override
public boolean canHandle(OCompositeKey key) {

boolean canHandle = key.getKeys().size() == 2;
for (Object o : key.getKeys()) {
if (!(o instanceof Number)) {
canHandle = false;
break;
}
}
return canHandle;
}
// @Override
// public Point makeShape(OCompositeKey key, SpatialContext ctx) {
// double lat = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(0), Double.class)).doubleValue();
// double lng = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(1), Double.class)).doubleValue();
// return ctx.makePoint(lng, lat);
//
// }
//
// @Override
// public boolean canHandle(OCompositeKey key) {
//
// boolean canHandle = key.getKeys().size() == 2;
// for (Object o : key.getKeys()) {
// if (!(o instanceof Number)) {
// canHandle = false;
// break;
// }
// }
// return canHandle;
// }

@Override
public void initClazz(ODatabaseDocumentTx db) {
Expand All @@ -84,11 +82,6 @@ public Point fromDoc(ODocument document) {
return point;
}

@Override
public Point fromText(String wkt) {
return null;
}

@Override
public ODocument toDoc(final Point shape) {

Expand Down
Expand Up @@ -98,11 +98,6 @@ protected LinearRing createLinearRing(List<List<Number>> coords) {
return GEOMETRY_FACTORY.createLinearRing(crs);
}

@Override
public JtsGeometry fromText(String wkt) {
return null;
}

@Override
public ODocument toDoc(JtsGeometry shape) {

Expand Down
Expand Up @@ -17,18 +17,15 @@
package com.orientechnologies.orient.spatial.shape;

import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.index.OCompositeKey;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OProperty;
import com.orientechnologies.orient.core.metadata.schema.OSchemaProxy;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.spatial4j.core.context.SpatialContext;
import com.spatial4j.core.shape.Point;
import com.spatial4j.core.shape.Rectangle;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class ORectangleShapeBuilder extends OShapeBuilder<Rectangle> {
Expand All @@ -45,45 +42,6 @@ public OShapeType getType() {
return OShapeType.RECTANGLE;
}

@Override
public Rectangle makeShape(OCompositeKey key, SpatialContext ctx) {

Point[] points = new Point[2];
int i = 0;

for (Object o : key.getKeys()) {
List<Number> numbers = (List<Number>) o;
double lat = ((Double) OType.convert(numbers.get(0), Double.class)).doubleValue();
double lng = ((Double) OType.convert(numbers.get(1), Double.class)).doubleValue();
points[i] = ctx.makePoint(lng, lat);
i++;
}

Point lowerLeft = points[0];
Point topRight = points[1];
if (lowerLeft.getX() > topRight.getX()) {
double x = lowerLeft.getX();
lowerLeft = ctx.makePoint(topRight.getX(), lowerLeft.getY());
topRight = ctx.makePoint(x, topRight.getY());
}
return ctx.makeRectangle(lowerLeft, topRight);
}

@Override
public boolean canHandle(OCompositeKey key) {
boolean canHandle = key.getKeys().size() == 2;
for (Object o : key.getKeys()) {
if (!(o instanceof Collection)) {
canHandle = false;
break;
} else if (((Collection) o).size() != 2) {
canHandle = false;
break;
}
}
return canHandle;
}

@Override
public void initClazz(ODatabaseDocumentTx db) {

Expand All @@ -107,11 +65,6 @@ public Rectangle fromDoc(ODocument document) {
return rectangle;
}

@Override
public Rectangle fromText(String wkt) {
return null;
}

@Override
public ODocument toDoc(final Rectangle shape) {

Expand Down

0 comments on commit b5769fd

Please sign in to comment.