Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Aug 21, 2015
1 parent 3d46f81 commit 5cebe0f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ public OLuceneNearOperator() {
public Object evaluateRecord(OIdentifiable iRecord, ODocument iCurrentResult, OSQLFilterCondition iCondition, Object iLeft,
Object iRight, OCommandContext iContext) {

List<Object> left = (List<Object>) iLeft;
List<Number> left = (List<Number>) iLeft;

double lat = (double) left.get(0);
double lon = (double) left.get(1);
double lat = left.get(0).doubleValue();
double lon = left.get(1).doubleValue();

Shape shape = factory.SPATIAL_CONTEXT.makePoint(lon, lat);
List<Object> right = (List<Object>) iRight;
List<Number> right = (List<Number>) iRight;

double lat1 = (double) right.get(0);
double lon1 = (double) right.get(1);
double lat1 = right.get(0).doubleValue();
double lon1 = right.get(1).doubleValue();
Shape shape1 = factory.SPATIAL_CONTEXT.makePoint(lon1, lat1);

Map map = (Map) right.get(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.orientechnologies.lucene.operator;

import com.orientechnologies.lucene.collections.OSpatialCompositeKey;
import com.orientechnologies.lucene.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 @@ -28,13 +29,18 @@
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.spatial4j.core.context.SpatialContext;
import com.spatial4j.core.shape.Shape;
import com.spatial4j.core.shape.SpatialRelation;
import org.apache.lucene.spatial.query.SpatialOperation;

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

public class OLuceneWithinOperator extends OQueryTargetOperator {

OShapeFactory shapeFactory = OShapeFactory.INSTANCE;

public OLuceneWithinOperator() {
super("WITHIN", 5, false);
}
Expand All @@ -48,11 +54,16 @@ public Collection<OIdentifiable> filterRecords(ODatabase<?> iRecord, List<String
@Override
public Object evaluateRecord(OIdentifiable iRecord, ODocument iCurrentResult, OSQLFilterCondition iCondition, Object iLeft,
Object iRight, OCommandContext iContext) {
if (iContext.getVariable("$luceneIndex") != null) {
return true;
} else {
return false;
}
List<Number> left = (List<Number>) iLeft;

double lat = left.get(0).doubleValue();
double lon = left.get(1).doubleValue();

Shape shape = SpatialContext.GEO.makePoint(lon, lat);

Shape shape1 = shapeFactory.makeShape(new OSpatialCompositeKey((List<?>) iRight), SpatialContext.GEO);

return shape.relate(shape1) == SpatialRelation.WITHIN;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@

package com.orientechnologies.lucene.test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;

import org.testng.Assert;
import org.testng.annotations.Test;

import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.index.OIndex;
Expand All @@ -35,7 +26,10 @@
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.tx.OTransaction;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.Collection;

/**
* Created by enricorisa on 28/06/14.
Expand All @@ -46,7 +40,7 @@ public class LuceneInsertMultithreadTest {

private final static int THREADS = 10;
private final static int RTHREADS = 1;
private final static int CYCLE = 1000;
private final static int CYCLE = 100;
private ODatabaseDocument databaseDocumentTx;

private static String url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void init() {
public void loadCloseDelete() {

ODocument city = new ODocument("City");
int size = 100000;
int size = 1000;
for (int i = 0; i < size; i++) {
city.field("name", "Rome " + i);
databaseDocumentTx.save(city);
Expand Down

0 comments on commit 5cebe0f

Please sign in to comment.