[VXQUERY-208] Lucene Index Filters

1) Lucene Index Filter for Values
2) Lucene Index Filter for Attributes
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/RewriteRuleset.java b/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/RewriteRuleset.java
index d5fb32a..aa1dd55 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/RewriteRuleset.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/RewriteRuleset.java
@@ -55,6 +55,7 @@
 import org.apache.hyracks.algebricks.rewriter.rules.SimpleUnnestToProductRule;
 import org.apache.hyracks.algebricks.rewriter.rules.subplan.EliminateSubplanRule;
 import org.apache.hyracks.algebricks.rewriter.rules.subplan.EliminateSubplanWithInputCardinalityOneRule;
+import org.apache.hyracks.algebricks.rewriter.rules.subplan.IntroduceGroupByForSubplanRule;
 import org.apache.hyracks.algebricks.rewriter.rules.subplan.NestedSubplanToJoinRule;
 import org.apache.hyracks.algebricks.rewriter.rules.subplan.PushSubplanIntoGroupByRule;
 import org.apache.hyracks.algebricks.rewriter.rules.subplan.SubplanOutOfGroupRule;
@@ -75,6 +76,7 @@
 import org.apache.vxquery.compiler.rewriter.rules.PushAggregateIntoGroupbyRule;
 import org.apache.vxquery.compiler.rewriter.rules.PushChildIntoDataScanRule;
 import org.apache.vxquery.compiler.rewriter.rules.PushFunctionsOntoEqJoinBranches;
+import org.apache.vxquery.compiler.rewriter.rules.PushIndexingIntoDatascanRule;
 import org.apache.vxquery.compiler.rewriter.rules.PushKeysOrMembersIntoDatascanRule;
 import org.apache.vxquery.compiler.rewriter.rules.PushValueIntoDatascanRule;
 import org.apache.vxquery.compiler.rewriter.rules.RemoveRedundantBooleanExpressionsRule;
@@ -199,6 +201,7 @@
         normalization.add(new RemoveUnusedAssignAndAggregateRule());
         normalization.add(new PushValueIntoDatascanRule());
         normalization.add(new PushKeysOrMembersIntoDatascanRule());
+        normalization.add(new EliminateSubplanForSingleItemsRule());
         return normalization;
     }
 
@@ -217,7 +220,6 @@
         xquery.add(new PushGroupByThroughProduct());
         xquery.add(new PushSelectDownRule());
         xquery.add(new PushSelectIntoJoinRule());
-
         // Clean up
         xquery.add(new RemoveRedundantVariablesRule());
         xquery.add(new RemoveUnusedAssignAndAggregateRule());
@@ -245,7 +247,7 @@
         xquery.add(new IntroJoinInsideSubplanRule());
         xquery.add(new PushMapOperatorDownThroughProductRule());
         xquery.add(new PushSubplanWithAggregateDownThroughProductRule());
-        //xquery.add(new IntroduceGroupByForSubplanRule());
+        xquery.add(new IntroduceGroupByForSubplanRule());
         xquery.add(new SubplanOutOfGroupRule());
         //        xquery.add(new InsertOuterJoinRule());
         xquery.add(new ExtractFunctionsFromJoinConditionRule());
@@ -314,6 +316,7 @@
     public static final List<IAlgebraicRewriteRule> buildConsolidationRuleCollection() {
         List<IAlgebraicRewriteRule> consolidation = new LinkedList<>();
         consolidation.add(new ConsolidateSelectsRule());
+        consolidation.add(new PushIndexingIntoDatascanRule());
         consolidation.add(new ConsolidateAssignsRule());
         consolidation.add(new InlineAssignIntoAggregateRule());
         consolidation.add(new IntroduceGroupByCombinerRule());
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/EliminateSubplanForSingleItemsRule.java b/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/EliminateSubplanForSingleItemsRule.java
index 953a0b2..dafe143 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/EliminateSubplanForSingleItemsRule.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/EliminateSubplanForSingleItemsRule.java
@@ -76,7 +76,8 @@
         return false;
     }
 
-    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
+    public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
+            throws AlgebricksException {
         AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
         if (op.getOperatorTag() != LogicalOperatorTag.SUBPLAN) {
             return false;
@@ -84,13 +85,15 @@
         SubplanOperator subplan = (SubplanOperator) op;
 
         // AGGREGATE($v2, sequence(%expression($v1)) )
-        AbstractLogicalOperator subplanOp1 = (AbstractLogicalOperator) subplan.getNestedPlans().get(0).getRoots()
-                .get(0).getValue();
+        AbstractLogicalOperator subplanOp1 = (AbstractLogicalOperator) subplan.getNestedPlans().get(0).getRoots().get(0)
+                .getValue();
         if (subplanOp1.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
             return false;
         }
         AggregateOperator aggregate = (AggregateOperator) subplanOp1;
-
+        if (aggregate.getExpressions().isEmpty()) {
+            return false;
+        }
         // Check to see if the expression is a function and op:sequence.
         ILogicalExpression logicalExpression1 = (ILogicalExpression) aggregate.getExpressions().get(0).getValue();
         if (logicalExpression1.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
@@ -140,44 +143,47 @@
         }
 
         // Ensure input is from a UNNEST operator.
+        //TODO: Make it check the cardinality of DataScan
         AbstractLogicalOperator subplanInput = (AbstractLogicalOperator) subplan.getInputs().get(0).getValue();
-        if (subplanInput.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
+        if (!(subplanInput.getOperatorTag() == LogicalOperatorTag.ASSIGN
+                || subplanInput.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN)) {
             return false;
         }
-        AssignOperator assign = (AssignOperator) subplanInput;
-        if (!assign.getVariables().contains(vre2.getVariableReference())) {
-            return false;
-        }
+        ILogicalExpression logicalExpression3 = null;
+        if (subplanInput.getOperatorTag() == LogicalOperatorTag.ASSIGN) {
+            AssignOperator assign = (AssignOperator) subplanInput;
+            if (!assign.getVariables().contains(vre2.getVariableReference())) {
+                return false;
+            }
+            logicalExpression3 = (ILogicalExpression) assign.getExpressions().get(0).getValue();
+            if (logicalExpression3.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
+                return false;
+            }
+            AbstractFunctionCallExpression functionCall3 = (AbstractFunctionCallExpression) logicalExpression3;
+            if (!functionCall3.getFunctionIdentifier().equals(BuiltinOperators.TREAT.getFunctionIdentifier())) {
+                return false;
+            }
 
-        // Check to see if the expression is the iterate operator.
-        ILogicalExpression logicalExpression3 = (ILogicalExpression) assign.getExpressions().get(0).getValue();
-        if (logicalExpression3.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
-            return false;
-        }
-        AbstractFunctionCallExpression functionCall3 = (AbstractFunctionCallExpression) logicalExpression3;
-        if (!functionCall3.getFunctionIdentifier().equals(BuiltinOperators.TREAT.getFunctionIdentifier())) {
-            return false;
-        }
+            // Find the treat type.
+            ILogicalExpression argType = functionCall3.getArguments().get(ARG_TYPE).getValue();
+            if (argType.getExpressionTag() != LogicalExpressionTag.CONSTANT) {
+                return false;
+            }
+            TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
+            ExpressionToolbox.getConstantAsPointable((ConstantExpression) argType, tvp);
 
-        // Find the treat type.
-        ILogicalExpression argType = functionCall3.getArguments().get(ARG_TYPE).getValue();
-        if (argType.getExpressionTag() != LogicalExpressionTag.CONSTANT) {
-            return false;
-        }
-        TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
-        ExpressionToolbox.getConstantAsPointable((ConstantExpression) argType, tvp);
-
-        IntegerPointable pTypeCode = (IntegerPointable) IntegerPointable.FACTORY.createPointable();
-        tvp.getValue(pTypeCode);
-        SequenceType sType = dCtx.lookupSequenceType(pTypeCode.getInteger());
-        if (sType.getQuantifier() != Quantifier.QUANT_ONE) {
-            return false;
+            IntegerPointable pTypeCode = (IntegerPointable) IntegerPointable.FACTORY.createPointable();
+            tvp.getValue(pTypeCode);
+            SequenceType sType = dCtx.lookupSequenceType(pTypeCode.getInteger());
+            if (sType.getQuantifier() != Quantifier.QUANT_ONE) {
+                return false;
+            }
         }
 
         // Create replacement assign operator.
         lvm1.setValue(vre2);
-        AssignOperator replacementAssign = new AssignOperator(aggregate.getVariables().get(0), functionCall1
-                .getArguments().get(0));
+        AssignOperator replacementAssign = new AssignOperator(aggregate.getVariables().get(0),
+                functionCall1.getArguments().get(0));
         replacementAssign.getInputs().addAll(subplan.getInputs());
         opRef.setValue(replacementAssign);
 
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/PushIndexingIntoDatascanRule.java b/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/PushIndexingIntoDatascanRule.java
new file mode 100644
index 0000000..9717eaf
--- /dev/null
+++ b/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/PushIndexingIntoDatascanRule.java
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.vxquery.compiler.rewriter.rules;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.mutable.Mutable;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator;
+import org.apache.hyracks.algebricks.core.algebra.base.IOptimizationContext;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalExpressionTag;
+import org.apache.hyracks.algebricks.core.algebra.base.LogicalOperatorTag;
+import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression;
+import org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression;
+import org.apache.hyracks.algebricks.core.algebra.functions.AlgebricksBuiltinFunctions;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator;
+import org.apache.hyracks.algebricks.core.algebra.operators.logical.SelectOperator;
+import org.apache.vxquery.compiler.rewriter.VXQueryOptimizationContext;
+import org.apache.vxquery.compiler.rewriter.rules.util.ExpressionToolbox;
+import org.apache.vxquery.context.StaticContext;
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+import org.apache.vxquery.functions.BuiltinOperators;
+import org.apache.vxquery.metadata.IVXQueryDataSource;
+import org.apache.vxquery.metadata.VXQueryIndexingDataSource;
+import org.apache.vxquery.metadata.VXQueryMetadataProvider;
+import org.apache.vxquery.types.AttributeType;
+import org.apache.vxquery.types.ElementType;
+
+/**
+ * The rule searches for a select operator with a value-eq expression, following an exchange
+ * operator and a data scan operator.
+ *
+ * <pre>
+ * Before
+ *
+ *   plan__parent
+ *   SELECT( value-eq ( $v1, constant )
+ *   DATASCAN( $source : $v1 )
+ *   plan__child
+ *
+ *   Where $v1 is not used in plan__parent.
+ *
+ * After
+ *
+ *   plan__parent
+ *   SELECT( value-eq ( $v1, constant )
+ *   DATASCAN( $source : $v1, constant )
+ *   plan__child
+ * </pre>
+ */
+public class PushIndexingIntoDatascanRule extends AbstractUsedVariablesProcessingRule {
+    StaticContext dCtx = null;
+
+    @Override
+    protected boolean processOperator(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
+            throws AlgebricksException {
+        if (context.checkIfInDontApplySet(this, opRef.getValue())) {
+            return false;
+        }
+        AbstractLogicalOperator op2 = null;
+
+        if (dCtx == null) {
+            VXQueryOptimizationContext vxqueryCtx = (VXQueryOptimizationContext) context;
+            dCtx = ((VXQueryMetadataProvider) vxqueryCtx.getMetadataProvider()).getStaticContext();
+        }
+        AbstractLogicalOperator op1 = (AbstractLogicalOperator) opRef.getValue();
+        if (op1.getOperatorTag() != LogicalOperatorTag.SELECT) {
+            return false;
+        }
+        SelectOperator select = (SelectOperator) op1;
+
+        op2 = (AbstractLogicalOperator) select.getInputs().get(0).getValue();
+
+        if (op2.getOperatorTag() != LogicalOperatorTag.DATASOURCESCAN) {
+            return false;
+        }
+
+        DataSourceScanOperator datascan = (DataSourceScanOperator) op2;
+
+        if (!usedVariables.contains(datascan.getVariables())) {
+
+            Mutable<ILogicalExpression> expressionRef = select.getCondition();
+            if (!(updateDataSource((IVXQueryDataSource) datascan.getDataSource(), expressionRef))) {
+                return false;
+            }
+            context.addToDontApplySet(this, opRef.getValue());
+            return true;
+        }
+
+        return false;
+
+    }
+
+    private boolean updateDataSource(IVXQueryDataSource dataSource, Mutable<ILogicalExpression> expression) {
+        if (!dataSource.usingIndex()) {
+            return false;
+        }
+        VXQueryIndexingDataSource ids = (VXQueryIndexingDataSource) dataSource;
+        boolean added = false;
+        findChildren(ids, expression);
+        added = true;
+        return added;
+    }
+
+    public Byte[] convertConstantToInteger(Mutable<ILogicalExpression> finds) {
+        TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
+        ExpressionToolbox.getConstantAsPointable((ConstantExpression) finds.getValue(), tvp);
+
+        return ArrayUtils.toObject(tvp.getByteArray());
+    }
+
+    public void findChildren(VXQueryIndexingDataSource ids, Mutable<ILogicalExpression> expression) {
+        List<Mutable<ILogicalExpression>> children = new ArrayList<>();
+        List<Mutable<ILogicalExpression>> valueEqch = new ArrayList<>();
+        ExpressionToolbox.findAllFunctionExpressions(expression, BuiltinOperators.GENERAL_EQ.getFunctionIdentifier(),
+                valueEqch);
+        if (valueEqch.isEmpty()) {
+            ExpressionToolbox.findAllFunctionExpressions(expression, AlgebricksBuiltinFunctions.EQ, valueEqch);
+            if (valueEqch.isEmpty()) {
+                return;
+            }
+        }
+        ExpressionToolbox.findAllFunctionExpressions(valueEqch.get(valueEqch.size() - 1),
+                BuiltinOperators.CHILD.getFunctionIdentifier(), children);
+        for (int i = children.size(); i > 0; --i) {
+            int typeId = ExpressionToolbox.getTypeExpressionTypeArgument(children.get(i - 1));
+            if (typeId > 0) {
+                ElementType it = (ElementType) dCtx.lookupSequenceType(typeId).getItemType();
+                ElementType et = ElementType.ANYELEMENT;
+
+                if (it.getContentType().equals(et.getContentType())) {
+                    ids.addIndexChildSeq(typeId);
+                }
+            }
+        }
+        findAttributes(ids, valueEqch.get(valueEqch.size() - 1));
+    }
+
+    public void findAttributes(VXQueryIndexingDataSource ids, Mutable<ILogicalExpression> expression) {
+        List<Mutable<ILogicalExpression>> attsEqch = new ArrayList<>();
+        ExpressionToolbox.findAllFunctionExpressions(expression, BuiltinOperators.ATTRIBUTE.getFunctionIdentifier(),
+                attsEqch);
+        for (int i = attsEqch.size(); i > 0; --i) {
+            int typeId = ExpressionToolbox.getTypeExpressionTypeArgument(attsEqch.get(i - 1));
+            if (typeId > 0) {
+                AttributeType it = (AttributeType) dCtx.lookupSequenceType(typeId).getItemType();
+                AttributeType et = AttributeType.ANYATTRIBUTE;
+
+                if (it.getContentType().equals(et.getContentType())) {
+                    ids.addIndexAttsSeq(typeId);
+                }
+            }
+        }
+        findValues(ids, expression);
+    }
+
+    public void findValues(VXQueryIndexingDataSource ids, Mutable<ILogicalExpression> expression) {
+        Byte[] index = null;
+        AbstractFunctionCallExpression valueEq = (AbstractFunctionCallExpression) expression.getValue();
+        if (valueEq.getArguments().get(1).getValue().getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
+            index = ExpressionToolbox.getConstantArgument(valueEq.getArguments().get(1), 0);
+        } else {
+            index = convertConstantToInteger(valueEq.getArguments().get(1));
+        }
+        ids.addIndexValueSeq(index);
+    }
+
+}
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/index/IndexAttributes.java b/vxquery-core/src/main/java/org/apache/vxquery/index/IndexAttributes.java
index cf8e3c0..676376b 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/index/IndexAttributes.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/index/IndexAttributes.java
@@ -16,6 +16,7 @@
  */
 package org.apache.vxquery.index;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import org.xml.sax.Attributes;
@@ -30,15 +31,48 @@
     List<String> types;
     List<String> qnames;
 
-    public IndexAttributes(List<String> n, List<String> v, List<String> u, List<String> l, List<String> t,
-            List<String> q) {
-        length = n.size();
-        names = n;
-        values = v;
-        uris = u;
-        localnames = l;
-        types = t;
-        qnames = q;
+    public IndexAttributes() {
+        names = new ArrayList<>();
+        values = new ArrayList<>();
+        uris = new ArrayList<>();
+        localnames = new ArrayList<>();
+        types = new ArrayList<>();
+        qnames = new ArrayList<>();
+    }
+
+    public void reset() {
+        length = names.size();
+        names.clear();
+        values.clear();
+        uris.clear();
+        localnames.clear();
+        types.clear();
+        qnames.clear();
+    }
+
+    public void addNames(String name) {
+        names.add(name);
+        length = names.size();
+    }
+
+    public void addValues(String value) {
+        values.add(value);
+    }
+
+    public void addUris(String uri) {
+        uris.add(uri);
+    }
+
+    public void addLocalNames(String localname) {
+        localnames.add(localname);
+    }
+
+    public void addTypes(String type) {
+        types.add(type);
+    }
+
+    public void addqNames(String qname) {
+        qnames.add(qname);
     }
 
     /**
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/index/IndexDocumentBuilder.java b/vxquery-core/src/main/java/org/apache/vxquery/index/IndexDocumentBuilder.java
index 1df31dd..3d0ec35 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/index/IndexDocumentBuilder.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/index/IndexDocumentBuilder.java
@@ -107,7 +107,7 @@
 
         doc.add(new StringField(Constants.FIELD_PATH, filePath, Field.Store.YES));
         print(bstart, sstart, lstart, "0", "");
-        for (int i = 1; i < results.size() - 1; i++) {
+        for (int i = 1; i < results.size(); i++) {
             //TODO: Since each doc is a file,
             //we can only handle files
             //small enough to fit in memory
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/metadata/AbstractVXQueryDataSource.java b/vxquery-core/src/main/java/org/apache/vxquery/metadata/AbstractVXQueryDataSource.java
index 2459944..1cb9231 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/metadata/AbstractVXQueryDataSource.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/metadata/AbstractVXQueryDataSource.java
@@ -30,6 +30,9 @@
     protected String[] collectionPartitions;
 
     protected List<Integer> childSeq;
+    protected List<Integer> indexChildSeq;
+    protected List<Byte[]> indexValueSeq;
+    protected List<Integer> indexAttsSeq;
     protected List<Byte[]> valueSeq;
     protected int totalDataSources;
     protected String tag;
@@ -98,6 +101,30 @@
     public List<Integer> getChildSeq() {
         return childSeq;
     }
+    
+    public void addIndexChildSeq(int integer) {
+        indexChildSeq.add(integer);
+    }
+
+    public List<Integer> getIndexChildSeq() {
+        return indexChildSeq;
+    }
+    
+    public void addIndexAttsSeq(int integer) {
+        indexAttsSeq.add(integer);
+    }
+
+    public List<Integer> getIndexAttsSeq() {
+        return indexAttsSeq;
+    }
+    
+    public void addIndexValueSeq(Byte[] index) {
+        indexValueSeq.add(index);
+    }
+
+    public List<Byte[]> getIndexValueSeq() {
+        return indexValueSeq;
+    }
 
     public void addValueSeq(Byte[] value) {
         valueSeq.add(value);
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryIndexingDataSource.java b/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryIndexingDataSource.java
index d55530d..044c87a 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryIndexingDataSource.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryIndexingDataSource.java
@@ -50,6 +50,9 @@
         };
         this.tag = null;
         this.childSeq = new ArrayList<>();
+        this.indexChildSeq = new ArrayList<>();
+        this.indexAttsSeq = new ArrayList<>();
+        this.indexValueSeq = new ArrayList<>();
         this.valueSeq = new ArrayList<>();
     }
 
@@ -64,7 +67,7 @@
     @Override
     public String toString() {
         return "VXQueryIndexingDataSource [collectionName=" + collectionName + ", elementPath=" + this.childSeq
-                + ", function=" + function + "]";
+                + ", searchPath=" + this.indexValueSeq + ", function=" + function + "]";
     }
 
     public boolean usingIndex() {
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryIndexingOperatorDescriptor.java b/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryIndexingOperatorDescriptor.java
index 3563713..9353319 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryIndexingOperatorDescriptor.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryIndexingOperatorDescriptor.java
@@ -58,6 +58,9 @@
     private String[] collectionPartitions;
     private final String functionCall;
     private List<Integer> childSeq;
+    private List<Integer> indexChildSeq;
+    private List<Integer> indexAttsSeq;
+    private List<Byte[]> indexSeq;
 
     public VXQueryIndexingOperatorDescriptor(IOperatorDescriptorRegistry spec, VXQueryIndexingDataSource ds,
             RecordDescriptor rDesc) {
@@ -68,6 +71,9 @@
         totalDataSources = (short) ds.getTotalDataSources();
         recordDescriptors[0] = rDesc;
         childSeq = ds.getChildSeq();
+        indexChildSeq = ds.getIndexChildSeq();
+        indexAttsSeq = ds.getIndexAttsSeq();
+        indexSeq = ds.getIndexValueSeq();
     }
 
     @Override
@@ -196,7 +202,8 @@
 
             public void usingIndex(IPointable result) throws HyracksDataException {
                 String indexModifiedName = indexCentralizerUtil.getIndexForCollection(collectionModifiedName);
-                VXQueryIndexReader indexReader = new VXQueryIndexReader(ctx, indexModifiedName, childSeq, appender);
+                VXQueryIndexReader indexReader = new VXQueryIndexReader(ctx, indexModifiedName, childSeq, indexChildSeq,
+                        indexAttsSeq, indexSeq, appender);
                 try {
                     indexReader.init();
                     for (int tupleIndex = 0; tupleIndex < fta.getTupleCount(); ++tupleIndex) {
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/index/VXQueryIndexReader.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/index/VXQueryIndexReader.java
index cf781ab..518d6a0 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/index/VXQueryIndexReader.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/index/VXQueryIndexReader.java
@@ -19,13 +19,16 @@
 import java.io.IOException;
 import java.nio.file.Paths;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.api.comm.IFrameFieldAppender;
 import org.apache.hyracks.api.comm.IFrameWriter;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.LongPointable;
 import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.document.Document;
@@ -39,10 +42,13 @@
 import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.store.FSDirectory;
 import org.apache.vxquery.context.DynamicContext;
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+import org.apache.vxquery.datamodel.values.ValueTag;
 import org.apache.vxquery.exceptions.ErrorCode;
 import org.apache.vxquery.exceptions.SystemException;
 import org.apache.vxquery.index.IndexAttributes;
 import org.apache.vxquery.runtime.functions.util.FunctionHelper;
+import org.apache.vxquery.types.AttributeType;
 import org.apache.vxquery.types.ElementType;
 import org.apache.vxquery.types.NameTest;
 import org.apache.vxquery.types.NodeType;
@@ -60,6 +66,7 @@
     private int indexPlace;
     private int indexLength;
     private String elementPath;
+    private String returnPath;
     private String indexName;
     private List<SequenceType> childSequenceTypes;
     private IndexReader reader;
@@ -74,18 +81,33 @@
     private String[] childLocalName = null;
     private IFrameFieldAppender appender;
     private boolean firstElement;
+    private List<Byte[]> indexSeq;
+    private List<Integer> indexAttsSeq;
 
     public VXQueryIndexReader(IHyracksTaskContext context, String indexPath, List<Integer> childSeq,
+            List<Integer> indexChildSeq, List<Integer> indexAttsSeq, List<Byte[]> indexSeq,
             IFrameFieldAppender appender) {
         this.ctx = context;
+        this.indexSeq = indexSeq;
+        this.indexAttsSeq = indexAttsSeq;
         this.indexName = indexPath;
         this.appender = appender;
         final DynamicContext dCtx = (DynamicContext) ctx.getJobletContext().getGlobalJobData();
         childSequenceTypes = new ArrayList<>();
+        int searchSize = 0;
         for (int typeCode : childSeq) {
             childSequenceTypes.add(dCtx.getStaticContext().lookupSequenceType(typeCode));
         }
-        childLocalName = new String[childSequenceTypes.size()];
+        if (!indexSeq.isEmpty()) {
+            searchSize = indexSeq.size();
+            if (!indexChildSeq.isEmpty()) {
+                searchSize += indexChildSeq.size();
+            }
+            if (!indexAttsSeq.isEmpty()) {
+                searchSize += indexAttsSeq.size();
+            }
+        }
+        childLocalName = new String[childSequenceTypes.size() + searchSize];
         int index = 0;
         StringBuilder stb = new StringBuilder();
         stb.append("/");
@@ -94,14 +116,68 @@
             ElementType eType = (ElementType) nodeType;
             NameTest nameTest = eType.getNameTest();
             childLocalName[index] = FunctionHelper.getStringFromBytes(nameTest.getLocalName());
-
             stb.append(childLocalName[index]);
             if (index != childSequenceTypes.size() - 1) {
                 stb.append("/");
             }
             ++index;
         }
-        elementPath = stb.toString();
+        returnPath = stb.toString();
+        stb.append("/");
+        if (!indexSeq.isEmpty()) {
+            addChildren(indexChildSeq, dCtx, index, stb);
+            addAtts(dCtx, index, stb);
+            addValue(stb);
+            elementPath = stb.toString();
+        }
+    }
+
+    public void addChildren(List<Integer> indexChildSeq, DynamicContext dCtx, int index, StringBuilder stb) {
+        for (Integer integer : indexChildSeq) {
+            SequenceType sType = dCtx.getStaticContext().lookupSequenceType(integer);
+            NodeType nodeType = (NodeType) sType.getItemType();
+            ElementType eType = (ElementType) nodeType;
+            NameTest nameTest = eType.getNameTest();
+            childLocalName[index] = FunctionHelper.getStringFromBytes(nameTest.getLocalName());
+
+            stb.append(childLocalName[index]);
+            stb.append("/");
+            ++index;
+        }
+    }
+
+    public void addAtts(DynamicContext dCtx, int index, StringBuilder stb) {
+        for (Integer integer : indexAttsSeq) {
+            SequenceType sType = dCtx.getStaticContext().lookupSequenceType(integer);
+            NodeType nodeType = (NodeType) sType.getItemType();
+            AttributeType eType = (AttributeType) nodeType;
+            NameTest nameTest = eType.getNameTest();
+            childLocalName[index] = FunctionHelper.getStringFromBytes(nameTest.getLocalName());
+
+            stb.append(childLocalName[index]);
+            stb.append("/");
+            ++index;
+        }
+    }
+
+    public void addValue(StringBuilder stb) {
+        byte[] indexBytes = new byte[indexSeq.get(0).length];
+        int i = 0;
+        for (Byte b : indexSeq.get(0)) {
+            indexBytes[i++] = b.byteValue();
+
+        }
+        TaggedValuePointable tvp = new TaggedValuePointable();
+        tvp.set(ArrayUtils.toPrimitive(indexSeq.get(0)), 0, ArrayUtils.toPrimitive(indexSeq.get(0)).length);
+        if (tvp.getTag() == ValueTag.XS_STRING_TAG) {
+            childLocalName[childLocalName.length - 1] = FunctionHelper
+                    .getStringFromBytes(Arrays.copyOfRange(indexBytes, 1, indexBytes.length));
+        } else {
+            LongPointable intPoint = (LongPointable) LongPointable.FACTORY.createPointable();
+            intPoint.set(indexBytes, 1, indexBytes.length);
+            childLocalName[childLocalName.length - 1] = String.valueOf(intPoint.longValue());
+        }
+        stb.append(childLocalName[childLocalName.length - 1]);
     }
 
     public boolean step(IPointable result, IFrameWriter writer, int tupleIndex) throws AlgebricksException {
@@ -153,13 +229,33 @@
 
         parser = new CaseSensitiveQueryParser("item", analyzer);
 
-        String queryString = elementPath.replaceAll("/", ".");
+        String queryString = "";
+        queryString = returnPath.replaceAll("/", ".");
         queryString = "item:" + queryString + "*";
 
-        int lastslash = elementPath.lastIndexOf('/');
-        elementPath = elementPath.substring(0, lastslash) + ":" + elementPath.substring(lastslash + 1);
-        elementPath = elementPath.replaceAll("/", ".") + ".element";
+        if (!indexSeq.isEmpty()) {
+            int lastSlash = elementPath.lastIndexOf('/');
+            queryString = elementPath.replaceAll("/", ".");
+            String prefixString = "";
+            prefixString = queryString.substring(0, lastSlash);
+            String valueString = queryString.substring(lastSlash + 1);
+            valueString = valueString.replaceAll(":", "\\\\:");
+            queryString = prefixString + "\\:" + valueString;
+            queryString = "item:" + queryString + "*";
+        }
+        int lastreturnslash = returnPath.lastIndexOf('/');
 
+        returnPath = returnPath.substring(0, lastreturnslash) + ":" + returnPath.substring(lastreturnslash + 1);
+        returnPath = returnPath.replaceAll("/", ".") + ".element";
+        if (!indexSeq.isEmpty()) {
+            String type = ".textnode";
+            if (!indexAttsSeq.isEmpty()) {
+                type = ".text";
+            }
+            int lastslash = elementPath.lastIndexOf('/');
+            elementPath = elementPath.substring(0, lastslash) + ":" + elementPath.substring(lastslash + 1);
+            elementPath = elementPath.replaceAll("/", ".") + type;
+        }
         TopDocs results = null;
         try {
             query = parser.parse(queryString);
@@ -176,13 +272,22 @@
     }
 
     public void parse(ArrayBackedValueStorage abvsFileNode) throws IOException {
+        int iPath = 0;
         try {
             for (int i = 0; i < fields.size(); i++) {
                 String fieldValue = fields.get(i).stringValue();
-                if (fieldValue.equals(elementPath)) {
+                if (fieldValue.equals(returnPath)) {
+                    iPath = i;
+                    if (indexSeq.isEmpty()) {
+                        handler.startDocument();
+                        this.firstElement = true;
+                        buildElement(abvsFileNode, iPath);
+                    }
+                }
+                if (!indexSeq.isEmpty() && fieldValue.equals(elementPath)) {
                     handler.startDocument();
                     this.firstElement = true;
-                    buildElement(abvsFileNode, i);
+                    buildElement(abvsFileNode, iPath);
                 }
             }
         } catch (Exception e) {
@@ -192,33 +297,31 @@
 
     private int buildElement(ArrayBackedValueStorage abvsFileNode, int fieldNum) throws SAXException {
         int whereIFinish = fieldNum;
-        int firstFinish;
         IndexableField field = fields.get(fieldNum);
         String contents = field.stringValue();
         String uri = "";
-
+        IndexAttributes atts = new IndexAttributes();
         int firstColon = contents.indexOf(':');
         int lastDot = contents.lastIndexOf('.');
         String type = contents.substring(lastDot + 1);
         String lastBit = contents.substring(firstColon + 1, lastDot);
-
+        int dots = contents.indexOf(".");
+        int nextdot;
+        String element = "";
+        int elements = 0;
         if (this.firstElement) {
             this.firstElement = false;
-            firstFinish = whereIFinish - this.childSequenceTypes.size() + 1;
-            String firstBit = contents.substring(1, firstColon);
-            List<String> names = new ArrayList<>();
-            List<String> values = new ArrayList<>();
-            List<String> uris = new ArrayList<>();
-            List<String> localNames = new ArrayList<>();
-            List<String> types = new ArrayList<>();
-            List<String> qNames = new ArrayList<>();
-            firstFinish = findAttributeChildren(firstFinish, names, values, uris, localNames, types, qNames);
-            Attributes atts = new IndexAttributes(names, values, uris, localNames, types, qNames);
-
-            handler.startElement(uri, firstBit, firstBit, atts);
-            buildElement(abvsFileNode, firstFinish + 1);
-            handler.endElement(uri, firstBit, firstBit);
-
+            while (dots < firstColon) {
+                nextdot = dots;
+                dots = contents.indexOf(".", dots + 1);
+                element = contents.substring(nextdot + 1, dots);
+                if (dots > firstColon) {
+                    element = contents.substring(nextdot + 1, firstColon);
+                }
+                atts.reset();
+                handler.startElement(uri, element, element, (Attributes) atts);
+                elements++;
+            }
         }
 
         if ("textnode".equals(type)) {
@@ -227,16 +330,9 @@
 
         }
         if ("element".equals(type)) {
-            List<String> names = new ArrayList<>();
-            List<String> values = new ArrayList<>();
-            List<String> uris = new ArrayList<>();
-            List<String> localNames = new ArrayList<>();
-            List<String> types = new ArrayList<>();
-            List<String> qNames = new ArrayList<>();
-            whereIFinish = findAttributeChildren(whereIFinish, names, values, uris, localNames, types, qNames);
-            Attributes atts = new IndexAttributes(names, values, uris, localNames, types, qNames);
-
-            handler.startElement(uri, lastBit, lastBit, atts);
+            atts.reset();
+            whereIFinish = findAttributeChildren(whereIFinish, atts);
+            handler.startElement(uri, lastBit, lastBit, (Attributes) atts);
 
             boolean noMoreChildren = false;
 
@@ -251,14 +347,18 @@
             handler.endElement(uri, lastBit, lastBit);
 
         }
+
+        while (elements > 0) {
+            handler.endElement(uri, element, element);
+            elements--;
+        }
         return whereIFinish;
     }
 
     /*This function creates the attribute children for an element node
      *
      */
-    int findAttributeChildren(int fieldnum, List<String> n, List<String> v, List<String> u, List<String> l,
-            List<String> t, List<String> q) {
+    int findAttributeChildren(int fieldnum, IndexAttributes atts) {
         int nextindex = fieldnum + 1;
         boolean foundattributes = false;
         if (nextindex < fields.size()) {
@@ -273,17 +373,17 @@
 
                 if (isDirectChildAttribute(nextguy, fields.get(fieldnum))) {
                     foundattributes = true;
-                    n.add(lastbit);
+                    atts.addNames(lastbit);
                     IndexableField nextnextguy = fields.get(nextindex + 1);
                     contents = nextnextguy.stringValue();
                     firstcolon = contents.indexOf(':');
                     lastdot = contents.lastIndexOf('.');
                     String nextlastbit = contents.substring(firstcolon + 1, lastdot);
-                    v.add(nextlastbit);
-                    u.add(lastbit);
-                    l.add(lastbit);
-                    t.add(lastbit);
-                    q.add(lastbit);
+                    atts.addValues(nextlastbit);
+                    atts.addUris("");
+                    atts.addLocalNames(lastbit);
+                    atts.addTypes(lastbit);
+                    atts.addqNames(lastbit);
                 } else {
                     break;
                 }
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/showIndexes1.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/showIndexes1.txt
index 17d6fec..8a3b40d 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/showIndexes1.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/showIndexes1.txt
@@ -1 +1,2 @@
+src/test/resources/TestSources/xml
 src/test/resources/TestSources/ghcnd
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/showIndexes2.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/showIndexes2.txt
index 8b13789..547c1de 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/showIndexes2.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/showIndexes2.txt
@@ -1 +1 @@
-
+src/test/resources/TestSources/xml
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex1.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex1.txt
index baf9dca..28001eb 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex1.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex1.txt
@@ -1,2 +1,2 @@
 <data><date>2003-03-03T00:00:00.000</date><dataType>TMIN</dataType><station>GHCND:AS000000003</station><value>13.75</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
-<data><date>2003-03-03T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:AS000000003</station><value>33</value><attributes><attribute/><attribute/><attribute>a</attribute></attributes></data>
\ No newline at end of file
+<data><date>2003-03-03T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:AS000000003</station><value>33</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex1_user.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex1_user.txt
index baf9dca..28001eb 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex1_user.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex1_user.txt
@@ -1,2 +1,2 @@
 <data><date>2003-03-03T00:00:00.000</date><dataType>TMIN</dataType><station>GHCND:AS000000003</station><value>13.75</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
-<data><date>2003-03-03T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:AS000000003</station><value>33</value><attributes><attribute/><attribute/><attribute>a</attribute></attributes></data>
\ No newline at end of file
+<data><date>2003-03-03T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:AS000000003</station><value>33</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex2.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex2.txt
index ef8dde4..82de09d 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex2.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex2.txt
@@ -1 +1 @@
-<data><date>2001-01-01T00:00:00.000</date><dataType>AWND</dataType><station>GHCND:US000000001</station><value>1000</value><attributes><attribute/><attribute/><attribute>a</attribute></attributes></data>
\ No newline at end of file
+<data><date>2001-01-01T00:00:00.000</date><dataType>AWND</dataType><station>GHCND:US000000001</station><value>1000</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex5.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex5.txt
index c84c360..e6134af 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex5.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex5.txt
@@ -1,3 +1,3 @@
 <data><date>2002-02-02T00:00:00.000</date><dataType>TMIN</dataType><station>GHCND:US000000002</station><value>12.5</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
 <data><date>2002-02-02T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:US000000002</station><value>32</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
-<data><date>2002-02-02T00:00:00.000</date><dataType>PRCP</dataType><station>GHCND:US000000002</station><value>20</value><attributes><attribute/><attribute/><attribute>a</attribute></attributes></data>
\ No newline at end of file
+<data><date>2002-02-02T00:00:00.000</date><dataType>PRCP</dataType><station>GHCND:US000000002</station><value>20</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex6.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex6.txt
index 9abedff..2a1c83a 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex6.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex6.txt
@@ -1,2 +1,2 @@
-<station><id>GHCND:US000000001</id><displayName>Station 1</displayName><latitude>10.000</latitude><longitude>-10.000</longitude><elevation>1000.0</elevation><locationLabels><type>ST</type><id>FIPS:1</id><displayName>State 1</displayName></locationLabels><locationLabels><type>CNTY</type><id>FIPS:-9999</id><displayName>County 1</displayName></locationLabels><locationLabels><type>CNTRY</type><id>FIPS:US</id><displayName/></locationLabels></station>
-<station><id>GHCND:US000000002</id><displayName>Station 2</displayName><latitude>20.000</latitude><longitude>-20.000</longitude><elevation>2000.0</elevation><locationLabels><type>ST</type><id>FIPS:1</id><displayName>State 1</displayName></locationLabels><locationLabels><type>CNTY</type><id>FIPS:-9999</id><displayName>County 2</displayName></locationLabels><locationLabels><type>CNTRY</type><id>FIPS:US</id><displayName/></locationLabels></station>
\ No newline at end of file
+<station><id>GHCND:US000000001</id><displayName>Station 1</displayName><latitude>10.000</latitude><longitude>-10.000</longitude><elevation>1000.0</elevation><locationLabels><type>ST</type><id>FIPS:1</id><displayName>State 1</displayName></locationLabels><locationLabels><type>CNTY</type><id>FIPS:-9999</id><displayName>County 1</displayName></locationLabels><locationLabels><type>CNTRY</type><id>FIPS:US</id><displayName>UNITED STATES</displayName></locationLabels></station>
+<station><id>GHCND:US000000002</id><displayName>Station 2</displayName><latitude>20.000</latitude><longitude>-20.000</longitude><elevation>2000.0</elevation><locationLabels><type>ST</type><id>FIPS:1</id><displayName>State 1</displayName></locationLabels><locationLabels><type>CNTY</type><id>FIPS:-9999</id><displayName>County 2</displayName></locationLabels><locationLabels><type>CNTRY</type><id>FIPS:US</id><displayName>UNITED STATES</displayName></locationLabels></station>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex7.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex7.txt
index c84c360..e6134af 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex7.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-1/useIndex7.txt
@@ -1,3 +1,3 @@
 <data><date>2002-02-02T00:00:00.000</date><dataType>TMIN</dataType><station>GHCND:US000000002</station><value>12.5</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
 <data><date>2002-02-02T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:US000000002</station><value>32</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
-<data><date>2002-02-02T00:00:00.000</date><dataType>PRCP</dataType><station>GHCND:US000000002</station><value>20</value><attributes><attribute/><attribute/><attribute>a</attribute></attributes></data>
\ No newline at end of file
+<data><date>2002-02-02T00:00:00.000</date><dataType>PRCP</dataType><station>GHCND:US000000002</station><value>20</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/showIndexes1.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/showIndexes1.txt
index 31d670b..355c7dd 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/showIndexes1.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/showIndexes1.txt
@@ -1,2 +1,3 @@
+src/test/resources/TestSources/xml
 src/test/resources/TestSources/ghcnd/half_1
 src/test/resources/TestSources/ghcnd/half_2
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex1.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex1.txt
index baf9dca..28001eb 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex1.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex1.txt
@@ -1,2 +1,2 @@
 <data><date>2003-03-03T00:00:00.000</date><dataType>TMIN</dataType><station>GHCND:AS000000003</station><value>13.75</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
-<data><date>2003-03-03T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:AS000000003</station><value>33</value><attributes><attribute/><attribute/><attribute>a</attribute></attributes></data>
\ No newline at end of file
+<data><date>2003-03-03T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:AS000000003</station><value>33</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex1_user.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex1_user.txt
index baf9dca..28001eb 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex1_user.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex1_user.txt
@@ -1,2 +1,2 @@
 <data><date>2003-03-03T00:00:00.000</date><dataType>TMIN</dataType><station>GHCND:AS000000003</station><value>13.75</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
-<data><date>2003-03-03T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:AS000000003</station><value>33</value><attributes><attribute/><attribute/><attribute>a</attribute></attributes></data>
\ No newline at end of file
+<data><date>2003-03-03T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:AS000000003</station><value>33</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex2.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex2.txt
index ef8dde4..82de09d 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex2.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex2.txt
@@ -1 +1 @@
-<data><date>2001-01-01T00:00:00.000</date><dataType>AWND</dataType><station>GHCND:US000000001</station><value>1000</value><attributes><attribute/><attribute/><attribute>a</attribute></attributes></data>
\ No newline at end of file
+<data><date>2001-01-01T00:00:00.000</date><dataType>AWND</dataType><station>GHCND:US000000001</station><value>1000</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex5.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex5.txt
index c84c360..e6134af 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex5.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex5.txt
@@ -1,3 +1,3 @@
 <data><date>2002-02-02T00:00:00.000</date><dataType>TMIN</dataType><station>GHCND:US000000002</station><value>12.5</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
 <data><date>2002-02-02T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:US000000002</station><value>32</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
-<data><date>2002-02-02T00:00:00.000</date><dataType>PRCP</dataType><station>GHCND:US000000002</station><value>20</value><attributes><attribute/><attribute/><attribute>a</attribute></attributes></data>
\ No newline at end of file
+<data><date>2002-02-02T00:00:00.000</date><dataType>PRCP</dataType><station>GHCND:US000000002</station><value>20</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex6.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex6.txt
index 9abedff..2a1c83a 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex6.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex6.txt
@@ -1,2 +1,2 @@
-<station><id>GHCND:US000000001</id><displayName>Station 1</displayName><latitude>10.000</latitude><longitude>-10.000</longitude><elevation>1000.0</elevation><locationLabels><type>ST</type><id>FIPS:1</id><displayName>State 1</displayName></locationLabels><locationLabels><type>CNTY</type><id>FIPS:-9999</id><displayName>County 1</displayName></locationLabels><locationLabels><type>CNTRY</type><id>FIPS:US</id><displayName/></locationLabels></station>
-<station><id>GHCND:US000000002</id><displayName>Station 2</displayName><latitude>20.000</latitude><longitude>-20.000</longitude><elevation>2000.0</elevation><locationLabels><type>ST</type><id>FIPS:1</id><displayName>State 1</displayName></locationLabels><locationLabels><type>CNTY</type><id>FIPS:-9999</id><displayName>County 2</displayName></locationLabels><locationLabels><type>CNTRY</type><id>FIPS:US</id><displayName/></locationLabels></station>
\ No newline at end of file
+<station><id>GHCND:US000000001</id><displayName>Station 1</displayName><latitude>10.000</latitude><longitude>-10.000</longitude><elevation>1000.0</elevation><locationLabels><type>ST</type><id>FIPS:1</id><displayName>State 1</displayName></locationLabels><locationLabels><type>CNTY</type><id>FIPS:-9999</id><displayName>County 1</displayName></locationLabels><locationLabels><type>CNTRY</type><id>FIPS:US</id><displayName>UNITED STATES</displayName></locationLabels></station>
+<station><id>GHCND:US000000002</id><displayName>Station 2</displayName><latitude>20.000</latitude><longitude>-20.000</longitude><elevation>2000.0</elevation><locationLabels><type>ST</type><id>FIPS:1</id><displayName>State 1</displayName></locationLabels><locationLabels><type>CNTY</type><id>FIPS:-9999</id><displayName>County 2</displayName></locationLabels><locationLabels><type>CNTRY</type><id>FIPS:US</id><displayName>UNITED STATES</displayName></locationLabels></station>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex7.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex7.txt
index c84c360..e6134af 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex7.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-2/useIndex7.txt
@@ -1,3 +1,3 @@
 <data><date>2002-02-02T00:00:00.000</date><dataType>TMIN</dataType><station>GHCND:US000000002</station><value>12.5</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
 <data><date>2002-02-02T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:US000000002</station><value>32</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
-<data><date>2002-02-02T00:00:00.000</date><dataType>PRCP</dataType><station>GHCND:US000000002</station><value>20</value><attributes><attribute/><attribute/><attribute>a</attribute></attributes></data>
\ No newline at end of file
+<data><date>2002-02-02T00:00:00.000</date><dataType>PRCP</dataType><station>GHCND:US000000002</station><value>20</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/showIndexes1.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/showIndexes1.txt
index e696773..3e705e3 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/showIndexes1.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/showIndexes1.txt
@@ -1,3 +1,4 @@
+src/test/resources/TestSources/xml
 src/test/resources/TestSources/ghcnd/half_2/quarter_3
 src/test/resources/TestSources/ghcnd/half_1
 src/test/resources/TestSources/ghcnd/half_2/quarter_4
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex1.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex1.txt
index baf9dca..28001eb 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex1.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex1.txt
@@ -1,2 +1,2 @@
 <data><date>2003-03-03T00:00:00.000</date><dataType>TMIN</dataType><station>GHCND:AS000000003</station><value>13.75</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
-<data><date>2003-03-03T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:AS000000003</station><value>33</value><attributes><attribute/><attribute/><attribute>a</attribute></attributes></data>
\ No newline at end of file
+<data><date>2003-03-03T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:AS000000003</station><value>33</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex1_user.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex1_user.txt
index baf9dca..28001eb 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex1_user.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex1_user.txt
@@ -1,2 +1,2 @@
 <data><date>2003-03-03T00:00:00.000</date><dataType>TMIN</dataType><station>GHCND:AS000000003</station><value>13.75</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
-<data><date>2003-03-03T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:AS000000003</station><value>33</value><attributes><attribute/><attribute/><attribute>a</attribute></attributes></data>
\ No newline at end of file
+<data><date>2003-03-03T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:AS000000003</station><value>33</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex2.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex2.txt
index ef8dde4..82de09d 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex2.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex2.txt
@@ -1 +1 @@
-<data><date>2001-01-01T00:00:00.000</date><dataType>AWND</dataType><station>GHCND:US000000001</station><value>1000</value><attributes><attribute/><attribute/><attribute>a</attribute></attributes></data>
\ No newline at end of file
+<data><date>2001-01-01T00:00:00.000</date><dataType>AWND</dataType><station>GHCND:US000000001</station><value>1000</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex5.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex5.txt
index c84c360..e6134af 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex5.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex5.txt
@@ -1,3 +1,3 @@
 <data><date>2002-02-02T00:00:00.000</date><dataType>TMIN</dataType><station>GHCND:US000000002</station><value>12.5</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
 <data><date>2002-02-02T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:US000000002</station><value>32</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
-<data><date>2002-02-02T00:00:00.000</date><dataType>PRCP</dataType><station>GHCND:US000000002</station><value>20</value><attributes><attribute/><attribute/><attribute>a</attribute></attributes></data>
\ No newline at end of file
+<data><date>2002-02-02T00:00:00.000</date><dataType>PRCP</dataType><station>GHCND:US000000002</station><value>20</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex6.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex6.txt
index 9abedff..2a1c83a 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex6.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex6.txt
@@ -1,2 +1,2 @@
-<station><id>GHCND:US000000001</id><displayName>Station 1</displayName><latitude>10.000</latitude><longitude>-10.000</longitude><elevation>1000.0</elevation><locationLabels><type>ST</type><id>FIPS:1</id><displayName>State 1</displayName></locationLabels><locationLabels><type>CNTY</type><id>FIPS:-9999</id><displayName>County 1</displayName></locationLabels><locationLabels><type>CNTRY</type><id>FIPS:US</id><displayName/></locationLabels></station>
-<station><id>GHCND:US000000002</id><displayName>Station 2</displayName><latitude>20.000</latitude><longitude>-20.000</longitude><elevation>2000.0</elevation><locationLabels><type>ST</type><id>FIPS:1</id><displayName>State 1</displayName></locationLabels><locationLabels><type>CNTY</type><id>FIPS:-9999</id><displayName>County 2</displayName></locationLabels><locationLabels><type>CNTRY</type><id>FIPS:US</id><displayName/></locationLabels></station>
\ No newline at end of file
+<station><id>GHCND:US000000001</id><displayName>Station 1</displayName><latitude>10.000</latitude><longitude>-10.000</longitude><elevation>1000.0</elevation><locationLabels><type>ST</type><id>FIPS:1</id><displayName>State 1</displayName></locationLabels><locationLabels><type>CNTY</type><id>FIPS:-9999</id><displayName>County 1</displayName></locationLabels><locationLabels><type>CNTRY</type><id>FIPS:US</id><displayName>UNITED STATES</displayName></locationLabels></station>
+<station><id>GHCND:US000000002</id><displayName>Station 2</displayName><latitude>20.000</latitude><longitude>-20.000</longitude><elevation>2000.0</elevation><locationLabels><type>ST</type><id>FIPS:1</id><displayName>State 1</displayName></locationLabels><locationLabels><type>CNTY</type><id>FIPS:-9999</id><displayName>County 2</displayName></locationLabels><locationLabels><type>CNTRY</type><id>FIPS:US</id><displayName>UNITED STATES</displayName></locationLabels></station>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex7.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex7.txt
index c84c360..e6134af 100644
--- a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex7.txt
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Partition-4/useIndex7.txt
@@ -1,3 +1,3 @@
 <data><date>2002-02-02T00:00:00.000</date><dataType>TMIN</dataType><station>GHCND:US000000002</station><value>12.5</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
 <data><date>2002-02-02T00:00:00.000</date><dataType>TMAX</dataType><station>GHCND:US000000002</station><value>32</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
-<data><date>2002-02-02T00:00:00.000</date><dataType>PRCP</dataType><station>GHCND:US000000002</station><value>20</value><attributes><attribute/><attribute/><attribute>a</attribute></attributes></data>
\ No newline at end of file
+<data><date>2002-02-02T00:00:00.000</date><dataType>PRCP</dataType><station>GHCND:US000000002</station><value>20</value><attributes><attribute/><attribute/><attribute>a</attribute><attribute/></attributes></data>
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Students/createIndexAtts.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Students/createIndexAtts.txt
new file mode 100644
index 0000000..27ba77d
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Students/createIndexAtts.txt
@@ -0,0 +1 @@
+true
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Students/selectAtts.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Students/selectAtts.txt
new file mode 100644
index 0000000..e8ac323
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Students/selectAtts.txt
@@ -0,0 +1 @@
+<student id="22"><name>Charles</name><office>X</office><attendance>2004-01-01</attendance></student>
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Students/useIndexAtts.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Students/useIndexAtts.txt
new file mode 100644
index 0000000..e8ac323
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Students/useIndexAtts.txt
@@ -0,0 +1 @@
+<student id="22"><name>Charles</name><office>X</office><attendance>2004-01-01</attendance></student>
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Students/useIndexAtts2.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Students/useIndexAtts2.txt
new file mode 100644
index 0000000..fbbfc12
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Indexing/Students/useIndexAtts2.txt
@@ -0,0 +1,5 @@
+id="23"
+id="25"
+id="24"
+id="26"
+id="27"
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Indexing/Students/createIndexAtts.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Indexing/Students/createIndexAtts.xq
new file mode 100644
index 0000000..eda6941
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Indexing/Students/createIndexAtts.xq
@@ -0,0 +1,19 @@
+(: Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+   
+     http://www.apache.org/licenses/LICENSE-2.0
+   
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License. :)
+   
+(: Build Lucene Index :)
+build-index-on-collection("src/test/resources/TestSources/xml")
diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Indexing/Students/selectAtts.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Indexing/Students/selectAtts.xq
new file mode 100644
index 0000000..ed0c730
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Indexing/Students/selectAtts.xq
@@ -0,0 +1,20 @@
+(: Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+   
+     http://www.apache.org/licenses/LICENSE-2.0
+   
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License. :)
+   
+for $i in collection("src/test/resources/TestSources/xml")/students/student
+where $i/@id = 22
+return $i
diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Indexing/Students/useIndexAtts.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Indexing/Students/useIndexAtts.xq
new file mode 100644
index 0000000..48c654e
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Indexing/Students/useIndexAtts.xq
@@ -0,0 +1,20 @@
+(: Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+   
+     http://www.apache.org/licenses/LICENSE-2.0
+   
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License. :)
+   
+for $s in collection("src/test/resources/TestSources/xml")/students/student
+where $s/name eq "Charles"
+return $s
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Indexing/Students/useIndexAtts2.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Indexing/Students/useIndexAtts2.xq
new file mode 100644
index 0000000..596fbb0
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Indexing/Students/useIndexAtts2.xq
@@ -0,0 +1,20 @@
+(: Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+   
+     http://www.apache.org/licenses/LICENSE-2.0
+   
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License. :)
+   
+for $i in collection("src/test/resources/TestSources/xml")/students/student
+where $i/@id > 22
+return $i/@id
diff --git a/vxquery-xtest/src/test/resources/TestSources/xml/students.xml b/vxquery-xtest/src/test/resources/TestSources/xml/students.xml
new file mode 100644
index 0000000..18a477d
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/TestSources/xml/students.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

+<!--

+  Licensed to the Apache Software Foundation (ASF) under one or more

+  contributor license agreements.  See the NOTICE file distributed with

+  this work for additional information regarding copyright ownership.

+  The ASF licenses this file to You under the Apache License, Version 2.0

+  (the "License"); you may not use this file except in compliance with

+  the License.  You may obtain a copy of the License at

+

+      http://www.apache.org/licenses/LICENSE-2.0

+

+  Unless required by applicable law or agreed to in writing, software

+  distributed under the License is distributed on an "AS IS" BASIS,

+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+  See the License for the specific language governing permissions and

+  limitations under the License.

+-->

+<students><student id="22"><name>Charles</name><office>X</office><attendance>2004-01-01</attendance></student><student id="23"><name>Frank</name><office>Y</office><attendance>2004-01-01</attendance></student><student id="25"><name>Karen</name> <office>Y</office><attendance> 2009-01-01</attendance></student><student id="24"><name>Mary</name> <office>Y</office><attendance>2005-01-01</attendance></student><student id="21"><name>Olga</name> <office>Z</office><attendance>2003-01-01</attendance></student><student id="26"><name>Steve</name> <office>Z</office><attendance>2010-01-01</attendance></student><student id="27"><name>Tess</name> <office>X</office><attendance>2010-01-01</attendance></student></students>

+	
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/VXQueryCatalog.xml b/vxquery-xtest/src/test/resources/VXQueryCatalog.xml
index 8e28135..7a4438e 100644
--- a/vxquery-xtest/src/test/resources/VXQueryCatalog.xml
+++ b/vxquery-xtest/src/test/resources/VXQueryCatalog.xml
@@ -142,6 +142,9 @@
         <source ID="nested_array_object_json_file" FileName="TestSources/json/array/nested_array_object.json" Creator="Christina Pavlopoulou">
             <description last-mod="2016-07-05">File</description>
         </source>
+        <source ID="xmlCollection" FileName="TestSources/xml" Creator="Christina Pavlopoulou">
+            <description last-mod="2017-08-03">File</description>
+        </source>
     </sources>
     <test-group name="SingleQuery" featureOwner="Preston Carman">
         <GroupInfo>
diff --git a/vxquery-xtest/src/test/resources/cat/IndexingQueries.xml b/vxquery-xtest/src/test/resources/cat/IndexingQueries.xml
index cc6b65b..94c710b 100644
--- a/vxquery-xtest/src/test/resources/cat/IndexingQueries.xml
+++ b/vxquery-xtest/src/test/resources/cat/IndexingQueries.xml
@@ -20,6 +20,26 @@
       <title>Indexing</title>
       <description/>
    </GroupInfo>
+   <test-case name="create-index-atts" FilePath="Indexing/Students/" Creator="Christina Pavlopoulou">
+      <description>Create Lucene Index from Collection.</description>
+      <query name="createIndexAtts" date="2017-08-03"/>
+      <output-file compare="Text">createIndexAtts.txt</output-file>
+   </test-case>
+   <test-case name="use-index-atts" FilePath="Indexing/Students/" Creator="Christina Pavlopoulou">
+      <description>Get Collection From Lucene Index.</description>
+      <query name="useIndexAtts" date="2016-05-26"/>
+      <output-file compare="Text">useIndexAtts.txt</output-file>
+   </test-case>
+   <test-case name="use-index-atts-2" FilePath="Indexing/Students/" Creator="Christina Pavlopoulou">
+      <description>Get Collection From Lucene Index.</description>
+      <query name="useIndexAtts2" date="2017-08-25"/>
+      <output-file compare="Text">useIndexAtts2.txt</output-file>
+   </test-case>
+   <test-case name="select-atts" FilePath="Indexing/Students/" Creator="Christina Pavlopoulou">
+      <description>Get Collection From Lucene Index.</description>
+      <query name="selectAtts" date="2016-05-26"/>
+      <output-file compare="Text">selectAtts.txt</output-file>
+   </test-case>
    <test-case name="create-index" FilePath="Indexing/Partition-1/" Creator="Steven Jacobs">
       <description>Create Lucene Index from Collection.</description>
       <query name="createIndex" date="2016-05-26"/>