fixed failing optimizer test
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
index 3efbcc8..1023c6d 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
@@ -286,10 +286,6 @@
                         if (funcVarIndex == -1) {
                             continue;
                         }
-                        // We only look for index on the first variable of the function, because edit-distance-contains() arguments are asymmetric
-                        if (funcVarIndex > 0 && optFuncExpr.getFuncExpr().getFunctionIdentifier() == AsterixBuiltinFunctions.EDIT_DISTANCE_CONTAINS) {
-                            continue;
-                        }
                         // At this point we have matched the optimizable func expr at optFuncExprIndex to an assigned variable.
                         // Remember matching subtree.
                         optFuncExpr.setOptimizableSubTree(funcVarIndex, subTree);
@@ -310,10 +306,6 @@
                     if (funcVarIndex == -1) {
                         continue;
                     }
-                    // We only look for index on the first variable of the function, because edit-distance-contains() arguments are asymmetric
-                    if (funcVarIndex > 0 && optFuncExpr.getFuncExpr().getFunctionIdentifier() == AsterixBuiltinFunctions.EDIT_DISTANCE_CONTAINS) {
-                        continue;
-                    }
                     // At this point we have matched the optimizable func expr at optFuncExprIndex to an unnest variable.
                     // Remember matching subtree.
                     optFuncExpr.setOptimizableSubTree(funcVarIndex, subTree);
@@ -336,10 +328,6 @@
                 if (funcVarIndex == -1) {
                     continue;
                 }
-                // We only look for index on the first variable of the function, because edit-distance-contains() arguments are asymmetric
-                if (funcVarIndex > 0 && optFuncExpr.getFuncExpr().getFunctionIdentifier() == AsterixBuiltinFunctions.EDIT_DISTANCE_CONTAINS) {
-                    continue;
-                }
                 // The variable value is one of the partitioning fields.
                 String fieldName = DatasetUtils.getPartitioningKeys(subTree.dataset).get(varIndex);
                 // Set the fieldName in the corresponding matched function expression, and remember matching subtree.
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/InvertedIndexAccessMethod.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/InvertedIndexAccessMethod.java
index 640e0b6..1a7a747 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/InvertedIndexAccessMethod.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/optimizer/rules/am/InvertedIndexAccessMethod.java
@@ -409,7 +409,6 @@
     public boolean applyJoinPlanTransformation(Mutable<ILogicalOperator> joinRef,
             OptimizableOperatorSubTree leftSubTree, OptimizableOperatorSubTree rightSubTree, Index chosenIndex,
             AccessMethodAnalysisContext analysisCtx, IOptimizationContext context) throws AlgebricksException {
-        IOptimizableFuncExpr optFuncExpr = AccessMethodUtils.chooseFirstOptFuncExpr(chosenIndex, analysisCtx);
         // Figure out if the index is applicable on the left or right side (if both, we arbitrarily prefer the left side).
         Dataset dataset = analysisCtx.indexDatasetMap.get(chosenIndex);
         // Determine probe and index subtrees based on chosen index.
@@ -422,6 +421,14 @@
             indexSubTree = rightSubTree;
             probeSubTree = leftSubTree;
         }
+        IOptimizableFuncExpr optFuncExpr = AccessMethodUtils.chooseFirstOptFuncExpr(chosenIndex, analysisCtx);
+        // The arguments of edit-distance-contains() function are asymmetrical, we can only use index if the dataset of index subtree and the dataset of first argument's subtree is the same     
+        if (optFuncExpr.getFuncExpr().getFunctionIdentifier() == AsterixBuiltinFunctions.EDIT_DISTANCE_CONTAINS
+                && optFuncExpr.getOperatorSubTree(0).dataset != null
+                && !optFuncExpr.getOperatorSubTree(0).dataset.getDatasetName().equals(
+                        indexSubTree.dataset.getDatasetName())) {
+            return false;
+        }
         InnerJoinOperator join = (InnerJoinOperator) joinRef.getValue();
 
         // Remember the original probe subtree, and its primary-key variables,