Index: src/main/java/org/apache/jackrabbit/core/query/lucene/sort/RowComparator.java
===================================================================
--- src/main/java/org/apache/jackrabbit/core/query/lucene/sort/RowComparator.java	(revision 1209064)
+++ src/main/java/org/apache/jackrabbit/core/query/lucene/sort/RowComparator.java	(working copy)
@@ -34,7 +34,7 @@
  */
 public class RowComparator implements Comparator<Row> {
 
-    private final ValueComparator comparator = new ValueComparator();
+    private static final ValueComparator comparator = new ValueComparator();
 
     private final Ordering[] orderings;
 
@@ -51,7 +51,7 @@
                 Operand operand = ordering.getOperand();
                 Value[] va = evaluator.getValues(operand, a);
                 Value[] vb = evaluator.getValues(operand, b);
-                int d = compare(va, vb);
+                int d = comparator.compare(va, vb);
                 if (d != 0) {
                     if (JCR_ORDER_DESCENDING.equals(ordering.getOrder())) {
                         return -d;
@@ -66,15 +66,4 @@
                     + b, e);
         }
     }
-
-    private int compare(Value[] a, Value[] b) {
-        for (int i = 0; i < a.length && i < b.length; i++) {
-            int d = comparator.compare(a[i], b[i]);
-            if (d != 0) {
-                return d;
-            }
-        }
-        return a.length - b.length;
-    }
-
-}
\ No newline at end of file
+}
Index: src/main/java/org/apache/jackrabbit/core/query/lucene/sort/ValueComparableWrapper.java
===================================================================
--- src/main/java/org/apache/jackrabbit/core/query/lucene/sort/ValueComparableWrapper.java	(revision 1209064)
+++ src/main/java/org/apache/jackrabbit/core/query/lucene/sort/ValueComparableWrapper.java	(working copy)
@@ -21,7 +21,8 @@
 import org.apache.jackrabbit.core.query.lucene.join.ValueComparator;
 
 class ValueComparableWrapper implements Comparable<ValueComparableWrapper> {
-    private final static ValueComparator comparator = new ValueComparator();
+
+    private static final ValueComparator comparator = new ValueComparator();
 
     private final Value[] v;
 
@@ -30,16 +31,6 @@
     }
 
     public int compareTo(ValueComparableWrapper o) {
-        return compare(v, o.v);
-    }
-
-    private int compare(Value[] a, Value[] b) {
-        for (int i = 0; i < a.length && i < b.length; i++) {
-            int d = comparator.compare(a[i], b[i]);
-            if (d != 0) {
-                return d;
-            }
-        }
-        return a.length - b.length;
+        return comparator.compare(v, o.v);
     }
 }
Index: src/main/java/org/apache/jackrabbit/core/query/lucene/join/ValueComparator.java
===================================================================
--- src/main/java/org/apache/jackrabbit/core/query/lucene/join/ValueComparator.java	(revision 1209064)
+++ src/main/java/org/apache/jackrabbit/core/query/lucene/join/ValueComparator.java	(working copy)
@@ -16,10 +16,6 @@
  */
 package org.apache.jackrabbit.core.query.lucene.join;
 
-import static javax.jcr.PropertyType.DATE;
-import static javax.jcr.PropertyType.DECIMAL;
-import static javax.jcr.PropertyType.DOUBLE;
-import static javax.jcr.PropertyType.LONG;
 import static javax.jcr.query.qom.QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO;
 import static javax.jcr.query.qom.QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN;
 import static javax.jcr.query.qom.QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO;
@@ -28,6 +24,7 @@
 import static javax.jcr.query.qom.QueryObjectModelConstants.JCR_OPERATOR_LIKE;
 import static javax.jcr.query.qom.QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO;
 
+import java.util.Arrays;
 import java.util.Comparator;
 import java.util.regex.Pattern;
 
@@ -46,20 +43,10 @@
      */
     public int compare(Value a, Value b) {
         try {
-            int ta = a.getType();
-            int tb = b.getType();
-
-            if ((ta == DECIMAL || ta == DOUBLE || ta == LONG)
-                    && (tb == DECIMAL || tb == DOUBLE || tb == LONG)) {
-                return a.getDecimal().compareTo(b.getDecimal());
-            } else if (ta == DATE && tb == DATE) {
-                return a.getDate().compareTo(b.getDate());
-            } else {
-                return a.getString().compareTo(b.getString());
-            }
+            return Util.compare(a, b);
         } catch (RepositoryException e) {
-            throw new RuntimeException(
-                    "Unable to compare values " + a + " and " + b, e);
+            throw new RuntimeException("Unable to compare values " + a
+                    + " and " + b, e);
         }
     }
 
@@ -98,6 +85,15 @@
         }
     }
 
+    public int compare(Value[] a, Value[] b) {
+        try {
+            return Util.compare(a, b);
+        } catch (RepositoryException e) {
+            throw new RuntimeException("Unable to compare values "
+                    + Arrays.toString(a) + " and " + Arrays.toString(b), e);
+        }
+    }
+
     /**
      * Evaluates the given QOM comparison operation with the given value arrays.
      *
@@ -108,15 +104,20 @@
      */
     public boolean evaluate(String operator, Value[] a, Value[] b) {
         if (JCR_OPERATOR_EQUAL_TO.equals(operator)) {
-            for (int i = 0; i < a.length; i++) {
-                for (int j = 0; j < b.length; j++) {
-                    if (compare(a[i], b[j]) == 0) {
-                        return true;
-                    }
-                }
-            }
+            return compare(a, b) == 0;
+        } else if (JCR_OPERATOR_GREATER_THAN.equals(operator)) {
+            return compare(a, b) > 0;
+        } else if (JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO.equals(operator)) {
+            return compare(a, b) >= 0;
+        } else if (JCR_OPERATOR_LESS_THAN.equals(operator)) {
+            return compare(a, b) < 0;
+        } else if (JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO.equals(operator)) {
+            return compare(a, b) <= 0;
+        } else if (JCR_OPERATOR_NOT_EQUAL_TO.equals(operator)) {
+            return compare(a, b) != 0;
         }
-        return false; // FIXME
+        // TODO JCR_OPERATOR_LIKE
+        throw new IllegalArgumentException("Unknown comparison operator: "
+                + operator);
     }
-
-}
\ No newline at end of file
+}
Index: src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
===================================================================
--- src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java	(revision 1209064)
+++ src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java	(working copy)
@@ -16,24 +16,24 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Fieldable;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.index.IndexReader;
-import org.apache.jackrabbit.core.value.InternalValue;
-import org.slf4j.LoggerFactory;
-import org.slf4j.Logger;
-
-import java.util.regex.Pattern;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
+import java.util.regex.Pattern;
 
 import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFormatException;
-import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.Query;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * <code>Util</code> provides various static utility methods.
@@ -236,7 +236,11 @@
     }
 
     /**
-     * Compares two arrays of comparables.
+     * Compares two arrays of Comparable(s) in the same style as
+     * {@link #compare(Value[], Value[])}.
+     * 
+     * The 2 methods *have* to work in the same way for the sort to work
+     * properly
      */
     public static int compare(Comparable<?>[] c1, Comparable<?>[] c2) {
         if (c1 == null) {
@@ -255,6 +259,29 @@
     }
 
     /**
+     * Compares two arrays of Value(s) in the same style as
+     * {@link #compare(Comparable[], Comparable[])}.
+     * 
+     * The 2 methods *have* to work in the same way for the sort to work
+     * properly
+     */
+    public static int compare(Value[] a, Value[] b) throws RepositoryException {
+        if (a == null) {
+            return -1;
+        }
+        if (b == null) {
+            return 1;
+        }
+        for (int i = 0; i < a.length && i < b.length; i++) {
+            int d = compare(a[i], b[i]);
+            if (d != 0) {
+                return d;
+            }
+        }
+        return a.length - b.length;
+    }
+
+    /**
      * Compares the two values. If the values have differing types, then an
      * attempt is made to convert the second value into the type of the first
      * value.
