diff --git a/src/main/java/com/orientechnologies/lucene/operator/OLuceneTextOperator.java b/src/main/java/com/orientechnologies/lucene/operator/OLuceneTextOperator.java index 56b663b5f2d..6b8b56b98a4 100644 --- a/src/main/java/com/orientechnologies/lucene/operator/OLuceneTextOperator.java +++ b/src/main/java/com/orientechnologies/lucene/operator/OLuceneTextOperator.java @@ -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) indexResult), new OFullTextCompositeKey( - keyParams)); + cursor = new OIndexCursorCollectionValue(((Collection) indexResult), new OFullTextCompositeKey(keyParams)); return cursor; } @@ -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> 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> classInvolvedIndexes = cls.getInvolvedIndexes(fields(iCondition)); OLuceneFullTextIndex idx = null; for (OIndex classInvolvedIndex : classInvolvedIndexes) { @@ -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 fields(OSQLFilterCondition iCondition) { Object left = iCondition.getLeft(); @@ -168,7 +186,12 @@ protected Collection 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(); } diff --git a/src/test/java/com/orientechnologies/lucene/test/LuceneMiscTest.java b/src/test/java/com/orientechnologies/lucene/test/LuceneMiscTest.java index ed35eac099a..20cdf0df9d1 100644 --- a/src/test/java/com/orientechnologies/lucene/test/LuceneMiscTest.java +++ b/src/test/java/com/orientechnologies/lucene/test/LuceneMiscTest.java @@ -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; @@ -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 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(); + } + } + }