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

Commit

Permalink
created as OrientDB Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
maggiolo00 authored and maggiolo00 committed May 13, 2014
1 parent 116fa72 commit eac73ec
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 105 deletions.
2 changes: 1 addition & 1 deletion config/orientdb-server-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parameter value="yyyy-MM-dd HH:mm:ss" name="profile.default.mail.date.format"/>
</parameters>
</handler>
<!--<handler class="com.orientechnologies.lucene.OEnterpriseLuceneIndex">-->
<!--<handler class="com.orientechnologies.lucene.OLuceneIndexPlugin">-->

<!--</handler>-->

Expand Down
Binary file removed plugins/studio.zip
Binary file not shown.
8 changes: 2 additions & 6 deletions src/main/assembly/assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@
<include>org.apache.lucene:*</include>
<include>com.spatial4j:*</include>
</includes>
<unpackOptions>
<excludes>
<exclude>**/plugin.json</exclude>
</excludes>
</unpackOptions>

</dependencySet>
</dependencySets>

</assembly>
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,39 @@

package com.orientechnologies.lucene;

import com.orientechnologies.common.util.OClassLoaderHelper;
import com.orientechnologies.lucene.operator.OLuceneNearOperator;
import com.orientechnologies.lucene.operator.OLuceneTextOperator;
import com.orientechnologies.lucene.operator.OLuceneWithinOperator;
import com.orientechnologies.orient.core.index.OIndexes;
import com.orientechnologies.orient.core.sql.OSQLEngine;
import com.orientechnologies.orient.core.sql.functions.OSQLFunction;
import com.orientechnologies.orient.server.OServer;
import com.orientechnologies.orient.server.config.OServerParameterConfiguration;
import com.orientechnologies.orient.server.plugin.OServerPluginAbstract;

public class OEnterpriseLuceneIndex extends OServerPluginAbstract {
import javax.imageio.spi.ServiceRegistry;
import java.util.Iterator;

public OEnterpriseLuceneIndex() {
public class OLuceneIndexPlugin extends OServerPluginAbstract {

public OLuceneIndexPlugin() {
}

@Override
public String getName() {
return "enterprise-lucene";
return "lucene-index";
}

@Override
public void startup() {
super.startup();
// Orient.instance().addDbLifecycleListener(new OLuceneClassIndexManager());

OIndexes.registerFactory(new OLuceneIndexFactory());
OSQLEngine.registerOperator(new OLuceneTextOperator());
OSQLEngine.registerOperator(new OLuceneWithinOperator());
OSQLEngine.registerOperator(new OLuceneNearOperator());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@

import com.orientechnologies.lucene.collections.OSpatialCompositeKey;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.ODatabaseComplex;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OIndex;
import com.orientechnologies.orient.core.index.OIndexCursor;
import com.orientechnologies.orient.core.index.OIndexDefinition;
import com.orientechnologies.orient.core.index.*;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
Expand All @@ -35,29 +34,30 @@
import com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField;
import com.orientechnologies.orient.core.sql.operator.OIndexReuseType;
import com.orientechnologies.orient.core.sql.operator.OQueryOperatorEqualityNotNulls;
import com.orientechnologies.orient.core.sql.operator.OQueryTargetOperator;
import com.spatial4j.core.context.SpatialContext;
import com.spatial4j.core.distance.DistanceUtils;
import com.spatial4j.core.shape.Point;

public class OLuceneNearOperator extends OQueryOperatorEqualityNotNulls {
public class OLuceneNearOperator extends OQueryTargetOperator {

public OLuceneNearOperator() {
super("NEAR", 5, false, 1, true);
super("NEAR", 5, false);
}

@Override
protected boolean evaluateExpression(OIdentifiable iRecord, OSQLFilterCondition iCondition, Object iLeft, Object iRight,
OCommandContext iContext) {

SpatialContext ctx = SpatialContext.GEO;
Object[] points = parseParams(iRecord, iCondition);
Point p = ctx.makePoint((Double) points[3], (Double) points[2]);

double docDistDEG = ctx.getDistCalc().distance(p, (Double) points[1], (Double) points[0]);
double docDistInKM = DistanceUtils.degrees2Dist(docDistDEG, DistanceUtils.EARTH_EQUATORIAL_RADIUS_KM);
iContext.setVariable("$distance", docDistInKM);
return true;
}
// @Override
// protected boolean evaluateExpression(OIdentifiable iRecord, OSQLFilterCondition iCondition, Object iLeft, Object iRight,
// OCommandContext iContext) {
//
// SpatialContext ctx = SpatialContext.GEO;
// Object[] points = parseParams(iRecord, iCondition);
// Point p = ctx.makePoint((Double) points[3], (Double) points[2]);
//
// double docDistDEG = ctx.getDistCalc().distance(p, (Double) points[1], (Double) points[0]);
// double docDistInKM = DistanceUtils.degrees2Dist(docDistDEG, DistanceUtils.EARTH_EQUATORIAL_RADIUS_KM);
// iContext.setVariable("$distance", docDistInKM);
// return true;
// }

private Object[] parseParams(OIdentifiable iRecord, OSQLFilterCondition iCondition) {

Expand Down Expand Up @@ -109,10 +109,10 @@ public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index,
}
Object indexResult = index.get(new OSpatialCompositeKey(keyParams).setMaxDistance(distance).setLimit(limit));
if (indexResult == null || indexResult instanceof OIdentifiable)
cursor = new OIndexCursor.OIndexCursorSingleValue((OIdentifiable) indexResult, new OSpatialCompositeKey(keyParams));
cursor = new OIndexCursorSingleValue((OIdentifiable) indexResult, new OSpatialCompositeKey(keyParams));
else
cursor = new OIndexCursor.OIndexCursorCollectionValue(((Collection<OIdentifiable>) indexResult).iterator(),
new OSpatialCompositeKey(keyParams));
cursor = new OIndexCursorCollectionValue(((Collection<OIdentifiable>) indexResult).iterator(), new OSpatialCompositeKey(
keyParams));
return cursor;
}

Expand Down Expand Up @@ -142,4 +142,9 @@ public OIndexSearchResult getOIndexSearchResult(OClass iSchemaClass, OSQLFilterC
return OLuceneOperatorUtil.buildOIndexSearchResult(iSchemaClass, iCondition, iIndexSearchResults, context);
}

@Override
public Collection<OIdentifiable> filterRecords(ODatabaseComplex<?> iRecord, List<String> iTargetClasses,
OSQLFilterCondition iCondition, Object iLeft, Object iRight) {
return null;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,38 @@

import com.orientechnologies.lucene.collections.OSpatialCompositeKey;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.ODatabaseComplex;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OCompositeKey;
import com.orientechnologies.orient.core.index.OIndex;
import com.orientechnologies.orient.core.index.OIndexCursor;
import com.orientechnologies.orient.core.index.*;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OIndexSearchResult;
import com.orientechnologies.orient.core.sql.filter.OSQLFilterCondition;
import com.orientechnologies.orient.core.sql.operator.OIndexReuseType;
import com.orientechnologies.orient.core.sql.operator.OQueryOperatorEqualityNotNulls;
import com.orientechnologies.orient.core.sql.operator.OQueryTargetOperator;

public class OLuceneTextOperator extends OQueryOperatorEqualityNotNulls {
public class OLuceneTextOperator extends OQueryTargetOperator {

public OLuceneTextOperator() {
super("LUCENE", 5, false, 1, true);
super("LUCENE", 5, false);
}

@Override
protected boolean evaluateExpression(OIdentifiable iRecord, OSQLFilterCondition iCondition, Object iLeft, Object iRight,
OCommandContext iContext) {
return true;
}
// @Override
// protected boolean evaluateExpression(OIdentifiable iRecord, OSQLFilterCondition iCondition, Object iLeft, Object iRight,
// OCommandContext iContext) {
// return false;
// }

@Override
public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index, List<Object> keyParams, boolean ascSortOrder) {
OIndexCursor cursor;
Object indexResult = index.get(new OCompositeKey(keyParams));
if (indexResult == null || indexResult instanceof OIdentifiable)
cursor = new OIndexCursor.OIndexCursorSingleValue((OIdentifiable) indexResult, new OSpatialCompositeKey(keyParams));
cursor = new OIndexCursorSingleValue((OIdentifiable) indexResult, new OSpatialCompositeKey(keyParams));
else
cursor = new OIndexCursor.OIndexCursorCollectionValue(((Collection<OIdentifiable>) indexResult).iterator(),
cursor = new OIndexCursorCollectionValue(((Collection<OIdentifiable>) indexResult).iterator(),
new OSpatialCompositeKey(keyParams));
return cursor;
}
Expand All @@ -76,4 +77,16 @@ public OIndexSearchResult getOIndexSearchResult(OClass iSchemaClass, OSQLFilterC
List<OIndexSearchResult> iIndexSearchResults, OCommandContext context) {
return OLuceneOperatorUtil.buildOIndexSearchResult(iSchemaClass, iCondition, iIndexSearchResults, context);
}

@Override
public Collection<OIdentifiable> filterRecords(ODatabaseComplex<?> iRecord, List<String> iTargetClasses,
OSQLFilterCondition iCondition, Object iLeft, Object iRight) {
return null;
}

@Override
public Object evaluateRecord(OIdentifiable iRecord, ODocument iCurrentResult, OSQLFilterCondition iCondition, Object iLeft,
Object iRight, OCommandContext iContext) {
return super.evaluateRecord(iRecord, iCurrentResult, iCondition, iLeft, iRight, iContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.index.OIndex;
import com.orientechnologies.orient.core.index.OIndexCursor;
import com.orientechnologies.orient.core.index.OIndexDefinition;
import com.orientechnologies.orient.core.index.*;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.sql.OIndexSearchResult;
Expand All @@ -36,10 +34,9 @@
import java.util.List;
import java.util.Map;


public class OLuceneWithinOperator extends OQueryOperatorEqualityNotNulls {

protected OLuceneWithinOperator() {
public OLuceneWithinOperator() {
super("WITHIN", 5, false, 1, true);
}

Expand All @@ -62,15 +59,13 @@ public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index,
OIndexCursor cursor;
Object indexResult = index.get(new OSpatialCompositeKey(keyParams).setOperation(SpatialOperation.IsWithin));
if (indexResult == null || indexResult instanceof OIdentifiable)
cursor = new OIndexCursor.OIndexCursorSingleValue((OIdentifiable) indexResult, new OSpatialCompositeKey(keyParams));
cursor = new OIndexCursorSingleValue((OIdentifiable) indexResult, new OSpatialCompositeKey(keyParams));
else
cursor = new OIndexCursor.OIndexCursorCollectionValue(((Collection<OIdentifiable>) indexResult).iterator(),
new OSpatialCompositeKey(keyParams));
cursor = new OIndexCursorCollectionValue(((Collection<OIdentifiable>) indexResult).iterator(), new OSpatialCompositeKey(
keyParams));
return cursor;
}



@Override
public ORID getBeginRidRange(Object iLeft, Object iRight) {
return null;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 4 additions & 6 deletions src/main/resources/plugin.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name" : "enterprise-lucene",
"name" : "lucene-index",
"version" : "1.7",
"javaClass": "com.orientechnologies.lucene.OEnterpriseLuceneIndex",
"javaClass": "com.orientechnologies.lucene.OLuceneIndexPlugin",
"parameters" : {},
"description" : "This is the Enterprise Agent, part of the commercial OrientDB Enterprise suite",
"web" : "http://www.orientechnologies.com/enterprise.htm",
"copyrights" : "Orient Technologies LTD",
"license" : "Commercial"
"description" : "This is the Lucene Index integration",
"copyrights" : "Orient Technologies LTD"
}

0 comments on commit eac73ec

Please sign in to comment.