Skip to content

Commit

Permalink
#74 Ported in develop
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Oct 12, 2015
1 parent 398cf3d commit 32fdd50
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public OIndexCursor executeIndexQuery(OCommandContext iContext, OIndex<?> index,
if (indexResult == null || indexResult instanceof OIdentifiable)
cursor = new OIndexCursorSingleValue((OIdentifiable) indexResult, new OFullTextCompositeKey(keyParams));
else
cursor = new OIndexCursorCollectionValue(((Collection<OIdentifiable>) indexResult), new OFullTextCompositeKey(
keyParams));
cursor = new OIndexCursorCollectionValue(((Collection<OIdentifiable>) indexResult), new OFullTextCompositeKey(keyParams));
return cursor;
}

Expand Down Expand Up @@ -130,12 +129,23 @@ public Object evaluateRecord(OIdentifiable iRecord, ODocument iCurrentResult, OS
protected OLuceneFullTextIndex involvedIndex(OIdentifiable iRecord, ODocument iCurrentResult, OSQLFilterCondition iCondition,
Object iLeft, Object iRight) {


ODocument doc = iRecord.getRecord();
OClass cls = getDatabase().getMetadata().getSchema().getClass(doc.getClassName());
// Set<OIndex<?>> classInvolvedIndexes = getDatabase().getMetadata().getIndexManager()
// .getClassInvolvedIndexes(doc.getClassName(), fields(iCondition));

if (isChained(iCondition.getLeft())) {

OSQLFilterItemField chained = (OSQLFilterItemField) iCondition.getLeft();

OSQLFilterItemField.FieldChain fieldChain = chained.getFieldChain();
OClass oClass = cls;
for (int i = 0; i < fieldChain.getItemCount() - 1; i++) {
oClass = oClass.getProperty(fieldChain.getItemName(i)).getLinkedClass();
}
if (oClass != null) {
cls = oClass;
}
}
Set<OIndex<?>> classInvolvedIndexes = cls.getInvolvedIndexes(fields(iCondition));
OLuceneFullTextIndex idx = null;
for (OIndex<?> classInvolvedIndex : classInvolvedIndexes) {
Expand All @@ -148,6 +158,14 @@ protected OLuceneFullTextIndex involvedIndex(OIdentifiable iRecord, ODocument iC
return idx;
}


private boolean isChained(Object left) {
if (left instanceof OSQLFilterItemField) {
OSQLFilterItemField field = (OSQLFilterItemField) left;
return field.isFieldChain();
}
return false;
}
protected Collection<String> fields(OSQLFilterCondition iCondition) {

Object left = iCondition.getLeft();
Expand All @@ -168,7 +186,12 @@ protected Collection<String> fields(OSQLFilterCondition iCondition) {
if (left instanceof OSQLFilterItemField) {

OSQLFilterItemField fName = (OSQLFilterItemField) left;
return Arrays.asList(fName.toString());
if (fName.isFieldChain()) {
int itemCount = fName.getFieldChain().getItemCount();
return Arrays.asList(fName.getFieldChain().getItemName(itemCount - 1));
} else {
return Arrays.asList(fName.toString());
}
}
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
package com.orientechnologies.lucene.test;

import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.metadata.schema.OClass;
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.sql.OCommandSQL;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -130,4 +134,44 @@ public void testNamedParams() {

}

@Test
public void dottedNotationTest() {

OrientGraphNoTx db = new OrientGraphNoTx("memory:dotted");

try {
OSchema schema = db.getRawGraph().getMetadata().getSchema();
OClass v = schema.getClass("V");
OClass e = schema.getClass("E");
OClass author = schema.createClass("Author");
author.setSuperClass(v);
author.createProperty("name", OType.STRING);

OClass song = schema.createClass("Song");
song.setSuperClass(v);
song.createProperty("title", OType.STRING);

OClass authorOf = schema.createClass("AuthorOf");
authorOf.createProperty("in", OType.LINK, song);
authorOf.setSuperClass(e);

db.command(new OCommandSQL("create index AuthorOf.in on AuthorOf (in) NOTUNIQUE")).execute();
db.command(new OCommandSQL("create index Song.title on Song (title) FULLTEXT ENGINE LUCENE")).execute();

OrientVertex authorVertex = db.addVertex("class:Author", new String[] { "name", "Bob Dylan" });
OrientVertex songVertex = db.addVertex("class:Song", new String[] { "title", "hurricane" });

authorVertex.addEdge("AuthorOf", songVertex);

List<Object> results = db.getRawGraph().command(new OCommandSQL("select from AuthorOf")).execute();
Assert.assertEquals(results.size(), 1);

results = db.getRawGraph().command(new OCommandSQL("select from AuthorOf where in.title lucene 'hurricane'")).execute();

Assert.assertEquals(results.size(), 1);
} finally {
db.drop();
}
}

}

0 comments on commit 32fdd50

Please sign in to comment.