Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java	(revision 985822)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java	(working copy)
@@ -93,10 +93,8 @@
      */
     public QueryResult execute(long offset, long limit)
             throws RepositoryException {
-        SessionImpl session = sessionContext.getSessionImpl();
         LuceneQueryFactory factory = new LuceneQueryFactoryImpl(
-                session, index.getSortComparatorSource(),
-                index.getContext().getHierarchyManager(),
+                sessionContext,
                 index.getNamespaceMappings(), index.getTextAnalyzer(),
                 index.getSynonymProvider(), index.getIndexFormatVersion(),
                 getBindVariableValues());
@@ -106,7 +104,7 @@
         if (qomTree.getConstraint() != null) {
             Constraint c = ConstraintBuilder.create(qomTree.getConstraint(),
                     getBindVariableValues(), qomTree.getSource().getSelectors(),
-                    factory, session.getValueFactory());
+                    factory, sessionContext.getValueFactory());
             query = new FilterMultiColumnQuery(query, c);
         }
 
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/Join.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/Join.java	(revision 985822)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/Join.java	(working copy)
@@ -22,10 +22,10 @@
 import java.util.List;
 
 import org.apache.jackrabbit.commons.query.qom.JoinType;
-import org.apache.jackrabbit.core.HierarchyManager;
 import org.apache.jackrabbit.core.query.lucene.HierarchyResolver;
 import org.apache.jackrabbit.core.query.lucene.MultiColumnQueryHits;
 import org.apache.jackrabbit.core.query.lucene.ScoreNode;
+import org.apache.jackrabbit.core.session.SessionContext;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.commons.query.qom.ChildNodeJoinConditionImpl;
@@ -35,7 +35,6 @@
 import org.apache.jackrabbit.spi.commons.query.qom.JoinConditionImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.SameNodeJoinConditionImpl;
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.SortComparatorSource;
 
 /**
  * <code>Join</code> implements the result of a join.
@@ -113,8 +112,7 @@
      * @param condition the QOM join condition.
      * @param reader    the index reader.
      * @param resolver  the hierarchy resolver.
-     * @param scs       the sort comparator source of the index.
-     * @param hmgr      the hierarchy manager of the workspace.
+     * @param context component context of this session
      * @return the join result.
      * @throws IOException if an error occurs while executing the join.
      */
@@ -124,8 +122,7 @@
                               final JoinConditionImpl condition,
                               final IndexReader reader,
                               final HierarchyResolver resolver,
-                              final SortComparatorSource scs,
-                              final HierarchyManager hmgr)
+                              final SessionContext context)
             throws IOException {
         try {
             return (Join) condition.accept(new DefaultQOMTreeVisitor() {
@@ -183,8 +180,10 @@
                         outerPropName = node.getProperty2QName();
                     }
 
-                    Condition c = new EquiJoin(inner, getIndex(inner, innerName),
-                            scs, reader, innerPropName, outerPropName);
+                    Condition c = new EquiJoin(
+                            inner, getIndex(inner, innerName),
+                            context.getItemStateManager(),
+                            innerPropName, outerPropName);
                     return new Join(outer, outerIdx, isInner, c);
                 }
 
@@ -223,8 +222,11 @@
                         if (selector2Path == null || (selector2Path.getLength() == 1 && selector2Path.getNameElement().denotesCurrent())) {
                             c = new SameNodeJoin(src2, node.getSelector2QName(), reader);
                         } else {
-                            c = new DescendantPathNodeJoin(src2, node.getSelector2QName(),
-                                    node.getSelector2QPath(), hmgr);
+                            c = new DescendantPathNodeJoin(
+                                    src2,
+                                    node.getSelector2QName(),
+                                    node.getSelector2QPath(),
+                                    context.getHierarchyManager());
                         }
                     } else {
                         outer = src2;
@@ -233,8 +235,11 @@
                         if (selector2Path == null || (selector2Path.getLength() == 1 && selector2Path.getNameElement().denotesCurrent())) {
                             c = new SameNodeJoin(src1, node.getSelector1QName(), reader);
                         } else {
-                            c = new AncestorPathNodeJoin(src1, node.getSelector1QName(),
-                                    node.getSelector2QPath(), hmgr);
+                            c = new AncestorPathNodeJoin(
+                                    src1,
+                                    node.getSelector1QName(),
+                                    node.getSelector2QPath(),
+                                    context.getHierarchyManager());
                         }
                     }
                     return new Join(outer, outerIdx, isInner, c);
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/EquiJoin.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/EquiJoin.java	(revision 985822)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/EquiJoin.java	(working copy)
@@ -17,14 +17,21 @@
 package org.apache.jackrabbit.core.query.lucene.join;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.core.id.PropertyId;
 import org.apache.jackrabbit.core.query.lucene.MultiColumnQueryHits;
 import org.apache.jackrabbit.core.query.lucene.ScoreNode;
+import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.ItemStateManager;
+import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.SortComparatorSource;
-import org.apache.lucene.search.ScoreDocComparator;
-import org.apache.lucene.search.ScoreDoc;
 
 /**
  * <code>EquiJoin</code> implements an equi join condition.
@@ -32,32 +39,26 @@
 public class EquiJoin extends AbstractCondition {
 
     /**
-     * Reusable score doc for value lookups.
+     * Map of inner score nodes indexed by the value of their join property.
      */
-    private final ScoreDoc sDoc = new ScoreDoc(-1, 1.0f);
+    private final ScoreNodeMap innerScoreNodes = new ScoreNodeMap();
 
     /**
-     * The index reader.
+     * Item state manager of the current session
      */
-    private final IndexReader reader;
+    private final ItemStateManager ism;
 
     /**
-     * Map of inner score nodes indexed by the value of their join property.
+     * Name of the outer property
      */
-    private final ScoreNodeMap innerScoreNodes = new ScoreNodeMap();
+    private final Name outerPropertyName;
 
     /**
-     * The score doc comparator for the outer query hits.
-     */
-    private final ScoreDocComparator outerLookup;
-
-    /**
      * Creates a new equi join condition.
      *
      * @param inner               the inner query hits.
      * @param innerScoreNodeIndex the selector name for the inner query hits.
-     * @param scs                 the sort comparator source.
-     * @param reader              the index reader.
+     * @param ism item state manager of the current session
      * @param innerProperty       the name of the property of the inner query
      *                            hits.
      * @param outerProperty       the name of the property of the outer query
@@ -66,20 +67,19 @@
      */
     public EquiJoin(MultiColumnQueryHits inner,
                     int innerScoreNodeIndex,
-                    SortComparatorSource scs,
-                    IndexReader reader,
+                    ItemStateManager ism,
                     Name innerProperty,
                     Name outerProperty) throws IOException {
         super(inner);
-        this.reader = reader;
-        this.outerLookup = scs.newComparator(reader, outerProperty.toString());
-        ScoreDocComparator comparator = scs.newComparator(reader, innerProperty.toString());
+        this.ism = ism;
+        this.outerPropertyName = outerProperty;
+
+        // create lookup map
         ScoreNode[] nodes;
-        // create lookup map
         while ((nodes = inner.nextScoreNodes()) != null) {
-            sDoc.doc = nodes[innerScoreNodeIndex].getDoc(reader);
-            Comparable value = comparator.sortValue(sDoc);
-            if (value != null) {
+            Set<String> values =
+                getValues(nodes[innerScoreNodeIndex], innerProperty);
+            for (String value : values) {
                 innerScoreNodes.addScoreNodes(value, nodes);
             }
         }
@@ -90,8 +90,38 @@
      */
     public ScoreNode[][] getMatchingScoreNodes(ScoreNode outer)
             throws IOException {
-        sDoc.doc = outer.getDoc(reader);
-        Comparable value = outerLookup.sortValue(sDoc);
-        return innerScoreNodes.getScoreNodes(value);
+        List<ScoreNode[]> result = new ArrayList<ScoreNode[]>();
+        for (String value : getValues(outer, outerPropertyName)) {
+            ScoreNode[][] nodes = innerScoreNodes.getScoreNodes(value);
+            if (nodes != null) {
+                for (ScoreNode[] sn : nodes) {
+                    if (!result.contains(sn)) {
+                        result.add(sn);
+                    }
+                }
+            }
+        }
+        if (result.isEmpty()) {
+            return null;
+        } else {
+            return result.toArray(new ScoreNode[result.size()][]);
+        }
     }
+
+    private Set<String> getValues(ScoreNode node, Name name) {
+        Set<String> values = new HashSet<String>();
+        try {
+            PropertyId id = new PropertyId(node.getNodeId(), name);
+            PropertyState state = (PropertyState) ism.getItemState(id);
+            for (InternalValue value : state.getValues()) {
+                try {
+                    values.add(value.getString());
+                } catch (RepositoryException e) {
+                }
+            }
+        } catch (ItemStateException e) {
+        }
+        return values;
+    }
+
 }
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JoinQuery.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JoinQuery.java	(revision 985822)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JoinQuery.java	(working copy)
@@ -21,6 +21,7 @@
 import org.apache.jackrabbit.commons.query.qom.JoinType;
 import org.apache.jackrabbit.core.HierarchyManager;
 import org.apache.jackrabbit.core.query.lucene.join.Join;
+import org.apache.jackrabbit.core.session.SessionContext;
 import org.apache.jackrabbit.spi.commons.query.qom.JoinConditionImpl;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.search.SortComparatorSource;
@@ -51,37 +52,29 @@
     private final JoinConditionImpl joinCondition;
 
     /**
-     * The sort comparator source of the index.
+     * Component context of this session.
      */
-    private final SortComparatorSource scs;
+    private final SessionContext context;
 
     /**
-     * The hierarchy manager of the workspace.
-     */
-    private final HierarchyManager hmgr;
-
-    /**
      * Creates a new join query.
      *
      * @param left          the left side of the query.
      * @param right         the right side of the query.
      * @param joinType      the join type.
      * @param joinCondition the join condition.
-     * @param scs           the sort comparator source of the index.
-     * @param hmgr          the hierarchy manager of the workspace.
+     * @param context component context of this session
      */
     public JoinQuery(MultiColumnQuery left,
                      MultiColumnQuery right,
                      JoinType joinType,
                      JoinConditionImpl joinCondition,
-                     SortComparatorSource scs,
-                     HierarchyManager hmgr) {
+                     SessionContext context) {
         this.left = left;
         this.right = right;
         this.joinType = joinType;
         this.joinCondition = joinCondition;
-        this.scs = scs;
-        this.hmgr = hmgr;
+        this.context = context;
     }
 
     /**
@@ -95,6 +88,6 @@
         HierarchyResolver resolver = (HierarchyResolver) reader;
         return Join.create(left.execute(searcher, orderings, resultFetchHint),
                 right.execute(searcher, orderings, resultFetchHint),
-                joinType, joinCondition, reader, resolver, scs, hmgr);
+                joinType, joinCondition, reader, resolver, context);
     }
 }
Index: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactoryImpl.java
===================================================================
--- jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactoryImpl.java	(revision 985822)
+++ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryFactoryImpl.java	(working copy)
@@ -32,6 +32,7 @@
 
 import org.apache.jackrabbit.core.HierarchyManager;
 import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.session.SessionContext;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
@@ -58,21 +59,11 @@
 public class LuceneQueryFactoryImpl implements LuceneQueryFactory {
 
     /**
-     * Session of the user executing this query
+     * Component context of this session
      */
-    private final SessionImpl session;
+    private final SessionContext context;
 
     /**
-     * The source comparator source.
-     */
-    private final SortComparatorSource scs;
-
-    /**
-     * The hierarchy manager.
-     */
-    private final HierarchyManager hmgr;
-
-    /**
      * Namespace mappings to internal prefixes
      */
     private final NamespaceMappings nsMappings;
@@ -105,26 +96,20 @@
     /**
      * Creates a new lucene query factory.
      *
-     * @param session         the session that executes the query.
-     * @param scs             the sort comparator source of the index.
-     * @param hmgr            the hierarchy manager of the workspace.
+     * @param context component context of this session
      * @param nsMappings      the index internal namespace mappings.
      * @param analyzer        the analyzer of the index.
      * @param synonymProvider the synonym provider of the index.
      * @param version         the version of the index format.
      * @param bindVariables   the bind variable values of the query
      */
-    public LuceneQueryFactoryImpl(SessionImpl session,
-                                  SortComparatorSource scs,
-                                  HierarchyManager hmgr,
+    public LuceneQueryFactoryImpl(SessionContext context,
                                   NamespaceMappings nsMappings,
                                   Analyzer analyzer,
                                   SynonymProvider synonymProvider,
                                   IndexFormatVersion version,
                                   Map<Name, Value> bindVariables) {
-        this.session = session;
-        this.scs = scs;
-        this.hmgr = hmgr;
+        this.context = context;
         this.nsMappings = nsMappings;
         this.analyzer = analyzer;
         this.synonymProvider = synonymProvider;
@@ -141,10 +126,10 @@
         String mixinTypesField = npResolver.getJCRName(NameConstants.JCR_MIXINTYPES);
         String primaryTypeField = npResolver.getJCRName(NameConstants.JCR_PRIMARYTYPE);
 
-        NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
+        NodeTypeManager ntMgr = context.getNodeTypeManager();
         NodeType base = null;
         try {
-            base = ntMgr.getNodeType(session.getJCRName(selector.getNodeTypeQName()));
+            base = ntMgr.getNodeType(context.getJCRName(selector.getNodeTypeQName()));
         } catch (RepositoryException e) {
             // node type does not exist
         }
@@ -170,7 +155,7 @@
                 NodeType nt = allTypes.nextNodeType();
                 NodeType[] superTypes = nt.getSupertypes();
                 if (Arrays.asList(superTypes).contains(base)) {
-                    Name n = session.getQName(nt.getName());
+                    Name n = context.getQName(nt.getName());
                     String ntName = nsMappings.translateName(n);
                     Term t;
                     if (nt.isMixin()) {
@@ -277,6 +262,6 @@
         MultiColumnQuery left = create((SourceImpl) join.getLeft());
         MultiColumnQuery right = create((SourceImpl) join.getRight());
         return new JoinQuery(left, right, join.getJoinTypeInstance(),
-                (JoinConditionImpl) join.getJoinCondition(), scs, hmgr);
+                (JoinConditionImpl) join.getJoinCondition(), context);
     }
 }
