jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1063730 - in /jackrabbit/sandbox/JCR-2415-lucene-3.0: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/ jackrabbit-parent/
Date Wed, 26 Jan 2011 14:15:54 GMT
Author: mduerig
Date: Wed Jan 26 14:15:53 2011
New Revision: 1063730

URL: http://svn.apache.org/viewvc?rev=1063730&view=rev
Log:
JCR-2415: Update Lucene to 3.0
- upgrade to lucene 3.0.3

Added:
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FieldComparatorBase.java
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FieldComparatorDecorator.java
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldComparatorSource.java
Removed:
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractScoreDocComparator.java
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldSortComparator.java
Modified:
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CaseTermQuery.java
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LengthSortComparator.java
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LowerCaseSortComparator.java
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Ordering.java
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SortedLuceneQueryHits.java
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SortedMultiColumnQueryHits.java
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/UpperCaseSortComparator.java
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java
    jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-parent/pom.xml

Modified: jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java?rev=1063730&r1=1063729&r2=1063730&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java (original)
+++ jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractIndex.java Wed Jan 26 14:15:53 2011
@@ -16,16 +16,6 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.BitSet;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
@@ -40,6 +30,16 @@ import org.apache.tika.io.IOExceptionWit
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+
 /**
  * Implements common functionality for a lucene index.
  * <p/>
@@ -489,7 +489,7 @@ abstract class AbstractIndex {
             // mark the document that reindexing is required
             copy.add(new Field(FieldNames.REINDEXING_REQUIRED, "",
                     Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
-            for (Fieldable f : (List<Fieldable>) doc.getFields()) {
+            for (Fieldable f : doc.getFields()) {
                 Fieldable field = null;
                 Field.TermVector tv = getTermVectorParameter(f);
                 Field.Store stored = f.isStored() ? Field.Store.YES : Field.Store.NO;
@@ -501,7 +501,7 @@ abstract class AbstractIndex {
                     field = new Field(f.name(), f.stringValue(),
                             stored, indexed, tv);
                 } else if (f.isBinary()) {
-                    field = new Field(f.name(), f.binaryValue(), stored);
+                    field = new Field(f.name(), f.getBinaryValue(), stored);
                 }
                 if (field != null) {
                     field.setOmitNorms(f.getOmitNorms());

Modified: jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CaseTermQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CaseTermQuery.java?rev=1063730&r1=1063729&r2=1063730&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CaseTermQuery.java (original)
+++ jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/CaseTermQuery.java Wed Jan 26 14:15:53 2011
@@ -21,6 +21,7 @@ import org.apache.lucene.index.IndexRead
 import org.apache.lucene.index.TermEnum;
 import org.apache.lucene.search.MultiTermQuery;
 import org.apache.lucene.search.FilteredTermEnum;
+import org.apache.lucene.util.ToStringUtils;
 
 import java.io.IOException;
 import java.util.List;
@@ -41,9 +42,9 @@ abstract class CaseTermQuery extends Mul
      * upper-cased.
      */
     protected final int transform;
+    private final Term term;
 
     CaseTermQuery(Term term, int transform) {
-        super();
         this.term = term;
         this.transform = transform;
     }
@@ -51,10 +52,24 @@ abstract class CaseTermQuery extends Mul
     /**
      * {@inheritDoc}
      */
+    @Override
     protected FilteredTermEnum getEnum(IndexReader reader) throws IOException {
         return new CaseTermEnum(reader);
     }
 
+    /** Prints a user-readable version of this query. */
+    @Override
+    public String toString(String field) {
+        StringBuffer buffer = new StringBuffer();
+        if (!term.field().equals(field)) {
+            buffer.append(term.field());
+            buffer.append(':');
+        }
+        buffer.append(term.text());
+        buffer.append(ToStringUtils.boost(getBoost()));
+        return buffer.toString();
+    }
+
     static final class Upper extends CaseTermQuery {
 
         Upper(Term term) {
@@ -67,7 +82,6 @@ abstract class CaseTermQuery extends Mul
         Lower(Term term) {
             super(term, TRANSFORM_LOWER_CASE);
         }
-
     }
 
     private final class CaseTermEnum extends FilteredTermEnum {
@@ -158,20 +172,24 @@ abstract class CaseTermQuery extends Mul
                     getNext();
                 }
 
+                @Override
                 public boolean next() {
                     getNext();
                     return current != null;
                 }
 
+                @Override
                 public Term term() {
                     return current;
                 }
 
+                @Override
                 public int docFreq() {
                     Integer docFreq = orderedTerms.get(current);
                     return docFreq != null ? docFreq : 0;
                 }
 
+                @Override
                 public void close() {
                     // nothing to close
                 }
@@ -182,15 +200,18 @@ abstract class CaseTermQuery extends Mul
             });
         }
 
+        @Override
         protected boolean termCompare(Term term) {
             // they all match
             return true;
         }
 
+        @Override
         public float difference() {
             return 1.0f;
         }
 
+        @Override
         protected boolean endEnum() {
             // todo correct?
             return false;

Added: jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FieldComparatorBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FieldComparatorBase.java?rev=1063730&view=auto
==============================================================================
--- jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FieldComparatorBase.java (added)
+++ jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FieldComparatorBase.java Wed Jan 26 14:15:53 2011
@@ -0,0 +1,104 @@
+/*
+ * 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.jackrabbit.core.query.lucene;
+
+import org.apache.lucene.search.FieldComparator;
+
+import java.io.IOException;
+
+/**
+ * Abstract base class for <code>FieldComparator</code> implementations
+ * which are based on values in the form of <code>Comparables</code>.
+ */
+abstract class FieldComparatorBase extends FieldComparator {
+
+    /**
+     * The bottom value.
+     */
+    private Comparable bottom;
+
+    /**
+     * Value for a document
+     *
+     * @param doc  id of the document
+     * @return  the value for the given id
+     */
+    protected abstract Comparable sortValue(int doc);
+
+    /**
+     * Retrieves the value of a given slot
+     *
+     * @param slot  index of the value to retrieve
+     * @return  the value in the given slot
+     */
+    protected abstract Comparable getValue(int slot);
+
+    /**
+     * Puts a value into a given slot
+     *
+     * @param slot  index where to put the value
+     * @param value  the value to put into the given slot
+     */
+    protected abstract void setValue(int slot, Comparable value);
+
+    @Override
+    public int compare(int slot1, int slot2) {
+        return compare(getValue(slot1), getValue(slot2));
+    }
+
+    @Override
+    public int compareBottom(int doc) throws IOException {
+        return compare(bottom, sortValue(doc));
+    }
+
+    @Override
+    public void setBottom(int slot) {
+        bottom = getValue(slot);
+    }
+
+    /**
+     * Compare two values
+     *
+     * @param val1  first value
+     * @param val2  second value
+     * @return  A negative integer if <code>val1</code> comes before <code>val2</code>,
+     *   a positive integer if <code>val1</code> comes after <code>val2</code> and
+     *   <code>0</code> if <code>val1</code> and <code>val2</code> are equal.
+     */
+    protected int compare(Comparable val1, Comparable val2) {
+        if (val1 == null) {
+            if (val2 == null) {
+                return 0;
+            }
+            return -1;
+        }
+        else if (val2 == null) {
+            return 1;
+        }
+        return Util.compare(val1, val2);
+    }
+
+    @Override
+    public void copy(int slot, int doc) throws IOException {
+        setValue(slot, sortValue(doc));
+    }
+
+    @Override
+    public Comparable value(int slot) {
+        return getValue(slot);
+    }
+}

Added: jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FieldComparatorDecorator.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FieldComparatorDecorator.java?rev=1063730&view=auto
==============================================================================
--- jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FieldComparatorDecorator.java (added)
+++ jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/FieldComparatorDecorator.java Wed Jan 26 14:15:53 2011
@@ -0,0 +1,62 @@
+/*
+ * 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.jackrabbit.core.query.lucene;
+
+import org.apache.lucene.index.IndexReader;
+
+import java.io.IOException;
+
+/**
+ * Implements a <code>FieldComparator</code> which decorates a
+ * base comparator.
+ */
+abstract class FieldComparatorDecorator extends FieldComparatorBase {
+
+    /**
+     * The base comparator
+     */
+    private final FieldComparatorBase base;
+
+    /**
+     * Create a new instance which delegates to a base comparator.
+     * @param base  delegatee
+     */
+    public FieldComparatorDecorator(FieldComparatorBase base) {
+        this.base = base;
+    }
+
+    @Override
+    public void setNextReader(IndexReader reader, int docBase) throws IOException {
+        base.setNextReader(reader, docBase);
+    }
+
+    @Override
+    protected Comparable sortValue(int doc) {
+        return base.sortValue(doc);
+    }
+
+    @Override
+    protected Comparable getValue(int slot) {
+        return base.getValue(slot);
+    }
+
+    @Override
+    protected void setValue(int slot, Comparable value) {
+        base.setValue(slot, value);
+    }
+}

Modified: jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LengthSortComparator.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LengthSortComparator.java?rev=1063730&r1=1063729&r2=1063730&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LengthSortComparator.java (original)
+++ jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LengthSortComparator.java Wed Jan 26 14:15:53 2011
@@ -16,23 +16,20 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import java.io.IOException;
-
-import org.apache.lucene.search.SortComparatorSource;
-import org.apache.lucene.search.ScoreDocComparator;
-import org.apache.lucene.search.ScoreDoc;
-import org.apache.lucene.index.IndexReader;
+import org.apache.jackrabbit.core.query.lucene.SharedFieldComparatorSource.SimpleFieldComparator;
 import org.apache.jackrabbit.spi.NameFactory;
-import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
 import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
+import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.FieldComparatorSource;
+
+import java.io.IOException;
 
 /**
- * <code>LengthSortComparator</code> implements a sort comparator source that
+ * <code>LengthSortComparator</code> implements a <code>FieldComparator</code> which
  * sorts on the length of property values.
  */
-public class LengthSortComparator implements SortComparatorSource {
-
-    private static final long serialVersionUID = 2513564768671391632L;
+public class LengthSortComparator extends FieldComparatorSource {
 
     /**
      * The index internal namespace mappings.
@@ -43,52 +40,15 @@ public class LengthSortComparator implem
         this.nsMappings = nsMappings;
     }
 
-    /**
-     * Creates a new comparator.
-     *
-     * @param reader    the current index reader.
-     * @param fieldname the name of the property to sort on. This is the string
-     *                  representation of {@link org.apache.jackrabbit.spi.Name
-     *                  Name}.
-     * @return the score doc comparator.
-     * @throws IOException if an error occurs while reading from the index.
-     */
-    public ScoreDocComparator newComparator(IndexReader reader,
-                                            String fieldname)
-            throws IOException {
+    @Override
+    public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
         NameFactory factory = NameFactoryImpl.getInstance();
         try {
-            return new Comparator(reader,
-                    nsMappings.translateName(factory.create(fieldname)));
-        } catch (IllegalNameException e) {
+            return new SimpleFieldComparator(nsMappings.translateName(factory.create(fieldname)), FieldNames.PROPERTY_LENGTHS, numHits);
+        }
+        catch (IllegalNameException e) {
             throw Util.createIOException(e);
         }
     }
 
-    private final class Comparator extends AbstractScoreDocComparator {
-
-        /**
-         * The term look ups of the index segments.
-         */
-        protected final SharedFieldCache.ValueIndex[] indexes;
-
-        public Comparator(IndexReader reader,
-                          String propertyName) throws IOException {
-            super(reader);
-            this.indexes = new SharedFieldCache.ValueIndex[readers.size()];
-
-            String namedLength = FieldNames.createNamedValue(propertyName, "");
-            for (int i = 0; i < readers.size(); i++) {
-                IndexReader r = readers.get(i);
-                indexes[i] = SharedFieldCache.INSTANCE.getValueIndex(
-                        r, FieldNames.PROPERTY_LENGTHS,
-                        namedLength, LengthSortComparator.this);
-            }
-        }
-
-        public Comparable sortValue(ScoreDoc i) {
-            int idx = readerIndex(i.doc);
-            return indexes[idx].getValue(i.doc - starts[idx]);
-        }
-    }
 }

Modified: jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LowerCaseSortComparator.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LowerCaseSortComparator.java?rev=1063730&r1=1063729&r2=1063730&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LowerCaseSortComparator.java (original)
+++ jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/LowerCaseSortComparator.java Wed Jan 26 14:15:53 2011
@@ -16,71 +16,43 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import java.io.IOException;
+import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.FieldComparatorSource;
 
-import org.apache.lucene.search.ScoreDocComparator;
-import org.apache.lucene.search.ScoreDoc;
-import org.apache.lucene.search.SortField;
-import org.apache.lucene.search.SortComparatorSource;
-import org.apache.lucene.index.IndexReader;
+import java.io.IOException;
 
 /**
- * <code>LowerCaseSortComparator</code> implements a sort comparator that
- * compares the lower-cased string values of a base sort comparator.
+ * <code>LowerCaseSortComparator</code> implements a <code>FieldComparator</code> which
+ * compares the lower-cased string values of a base comparator.
  */
-public class LowerCaseSortComparator implements SortComparatorSource {
-
-    private static final long serialVersionUID = 5396206509020979445L;
+public class LowerCaseSortComparator extends FieldComparatorSource {
 
     /**
-     * The base sort comparator.
+     * The base comparator.
      */
-    private final SortComparatorSource base;
+    private final FieldComparatorSource base;
 
     /**
-     * Creates a new lower case sort comparator.
+     * Creates a new upper case sort comparator.
      *
      * @param base the base sort comparator source.
      */
-    public LowerCaseSortComparator(SortComparatorSource base) {
+    public LowerCaseSortComparator(FieldComparatorSource base) {
         this.base = base;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public ScoreDocComparator newComparator(IndexReader reader,
-                                            String fieldname)
-            throws IOException {
-        return new Comparator(base.newComparator(reader, fieldname));
-    }
-
-    private static final class Comparator implements ScoreDocComparator {
-
-        private ScoreDocComparator base;
-
-        private Comparator(ScoreDocComparator base) {
-            this.base = base;
-        }
-
-        /**
-         * @see Util#compare(Comparable, Comparable)
-         */
-        public int compare(ScoreDoc i, ScoreDoc j) {
-            return Util.compare(sortValue(i), sortValue(j));
-        }
-
-        public Comparable sortValue(ScoreDoc i) {
-            Comparable c = base.sortValue(i);
-            if (c != null) {
-                return c.toString().toLowerCase();
-            } else {
-                return null;
+    @Override
+    public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
+        FieldComparator comparator = base.newComparator(fieldname, numHits, sortPos, reversed);
+        assert comparator instanceof FieldComparatorBase;
+
+        return new FieldComparatorDecorator((FieldComparatorBase) comparator) {
+            @Override
+            protected Comparable sortValue(int doc) {
+                Comparable c = super.sortValue(doc);
+                return c == null ? null : c.toString().toLowerCase();
             }
-        }
-
-        public int sortType() {
-            return SortField.CUSTOM;
-        }
+        };
     }
+
 }

Modified: jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Ordering.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Ordering.java?rev=1063730&r1=1063729&r2=1063730&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Ordering.java (original)
+++ jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Ordering.java Wed Jan 26 14:15:53 2011
@@ -16,22 +16,21 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import javax.jcr.RepositoryException;
-
-import org.apache.jackrabbit.spi.commons.query.qom.OrderingImpl;
-import org.apache.jackrabbit.spi.commons.query.qom.QOMTreeVisitor;
+import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.query.qom.DefaultTraversingQOMTreeVisitor;
-import org.apache.jackrabbit.spi.commons.query.qom.LengthImpl;
-import org.apache.jackrabbit.spi.commons.query.qom.PropertyValueImpl;
-import org.apache.jackrabbit.spi.commons.query.qom.LowerCaseImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.DynamicOperandImpl;
-import org.apache.jackrabbit.spi.commons.query.qom.UpperCaseImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.FullTextSearchScoreImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.LengthImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.LowerCaseImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.NodeLocalNameImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.NodeNameImpl;
-import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.commons.query.qom.OrderingImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.PropertyValueImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.QOMTreeVisitor;
+import org.apache.jackrabbit.spi.commons.query.qom.UpperCaseImpl;
 import org.apache.lucene.search.SortField;
-import org.apache.lucene.search.SortComparatorSource;
+
+import javax.jcr.RepositoryException;
 
 /**
  * <code>Ordering</code> implements a single ordering specification.
@@ -84,7 +83,7 @@ public class Ordering {
      *                             QOM ordering.
      */
     public static Ordering fromQOM(final OrderingImpl ordering,
-                                    final SortComparatorSource scs,
+                                    final SharedFieldComparatorSource scs,
                                     final NamespaceMappings nsMappings)
             throws RepositoryException {
         final Name[] selectorName = new Name[1];
@@ -103,7 +102,7 @@ public class Ordering {
                 SortField sf = (SortField) ((DynamicOperandImpl) node.getOperand()).accept(this, data);
                 selectorName[0] = node.getSelectorQName();
                 return new SortField(sf.getField(),
-                        new LowerCaseSortComparator(sf.getFactory()),
+                        new LowerCaseSortComparator(sf.getComparatorSource()),
                         !ordering.isAscending());
             }
 
@@ -112,7 +111,7 @@ public class Ordering {
                 SortField sf = (SortField) ((DynamicOperandImpl) node.getOperand()).accept(this, data);
                 selectorName[0] = node.getSelectorQName();
                 return new SortField(sf.getField(),
-                        new UpperCaseSortComparator(sf.getFactory()),
+                        new UpperCaseSortComparator(sf.getComparatorSource()),
                         !ordering.isAscending());
             }
 

Modified: jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=1063730&r1=1063729&r2=1063730&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java (original)
+++ jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java Wed Jan 26 14:15:53 2011
@@ -58,7 +58,6 @@ import org.apache.lucene.search.IndexSea
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.Similarity;
 import org.apache.lucene.search.Sort;
-import org.apache.lucene.search.SortComparatorSource;
 import org.apache.lucene.search.SortField;
 import org.apache.lucene.search.TermQuery;
 import org.apache.tika.parser.Parser;
@@ -442,9 +441,9 @@ public class SearchIndex extends Abstrac
     private int termInfosIndexDivisor = DEFAULT_TERM_INFOS_INDEX_DIVISOR;
 
     /**
-     * The sort comparator source for indexed properties.
+     * The field comparator source for indexed properties.
      */
-    private SortComparatorSource scs;
+    private SharedFieldComparatorSource scs;
 
     /**
      * Flag that indicates whether the hierarchy cache should be initialized
@@ -509,7 +508,7 @@ public class SearchIndex extends Abstrac
             }
         }
 
-        scs = new SharedFieldSortComparator(
+        scs = new SharedFieldComparatorSource(
                 FieldNames.PROPERTIES, context.getItemStateManager(),
                 context.getHierarchyManager(), nsMappings);
         indexingConfig = createIndexingConfiguration(nsMappings);
@@ -1099,9 +1098,9 @@ public class SearchIndex extends Abstrac
     }
 
     /**
-     * @return the sort comparator source for this index.
+     * @return the field comparator source for this index.
      */
-    protected SortComparatorSource getSortComparatorSource() {
+    protected SharedFieldComparatorSource getSortComparatorSource() {
         return scs;
     }
 

Modified: jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java?rev=1063730&r1=1063729&r2=1063730&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java (original)
+++ jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java Wed Jan 26 14:15:53 2011
@@ -18,18 +18,17 @@ package org.apache.jackrabbit.core.query
 
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
+import org.apache.lucene.index.TermDocs;
 import org.apache.lucene.index.TermEnum;
 import org.apache.lucene.index.TermPositions;
-import org.apache.lucene.index.TermDocs;
-import org.apache.lucene.search.SortComparatorSource;
+import org.apache.lucene.search.FieldComparator;
 
+import javax.jcr.PropertyType;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.WeakHashMap;
 
-import javax.jcr.PropertyType;
-
 /**
  * Implements a variant of the lucene class <code>org.apache.lucene.search.FieldCacheImpl</code>.
  * The lucene FieldCache class has some sort of support for custom comparators
@@ -139,7 +138,7 @@ public class SharedFieldCache {
      * @param reader     the <code>IndexReader</code>.
      * @param field      name of the shared field.
      * @param prefix     the property name, will be used as term prefix.
-     * @param comparator the sort comparator instance.
+     * @param comparator the field comparator instance.
      * @return a ValueIndex that contains the field values and order
      *         information.
      * @throws IOException if an error occurs while reading from the index.
@@ -147,7 +146,7 @@ public class SharedFieldCache {
     public ValueIndex getValueIndex(IndexReader reader,
                                     String field,
                                     String prefix,
-                                    SortComparatorSource comparator)
+                                    FieldComparator comparator)
             throws IOException {
 
         if (reader instanceof ReadOnlyIndexReader) {
@@ -225,7 +224,7 @@ public class SharedFieldCache {
      * See if a <code>ValueIndex</code> object is in the cache.
      */
     ValueIndex lookup(IndexReader reader, String field,
-                      String prefix, SortComparatorSource comparer) {
+                      String prefix, FieldComparator comparer) {
         Key key = new Key(field, prefix, comparer);
         synchronized (this) {
             Map<Key, ValueIndex> readerCache = cache.get(reader);
@@ -240,7 +239,7 @@ public class SharedFieldCache {
      * Put a <code>ValueIndex</code> <code>value</code> to cache.
      */
     ValueIndex store(IndexReader reader, String field, String prefix,
-                 SortComparatorSource comparer, ValueIndex value) {
+                 FieldComparator comparer, ValueIndex value) {
         Key key = new Key(field, prefix, comparer);
         synchronized (this) {
             Map<Key, ValueIndex> readerCache = cache.get(reader);
@@ -285,12 +284,12 @@ public class SharedFieldCache {
 
         private final String field;
         private final String prefix;
-        private final SortComparatorSource comparator;
+        private final Object comparator;
 
         /**
          * Creates <code>Key</code> for ValueIndex lookup.
          */
-        Key(String field, String prefix, SortComparatorSource comparator) {
+        Key(String field, String prefix, FieldComparator comparator) { 
             this.field = field.intern();
             this.prefix = prefix.intern();
             this.comparator = comparator;

Added: jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldComparatorSource.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldComparatorSource.java?rev=1063730&view=auto
==============================================================================
--- jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldComparatorSource.java (added)
+++ jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldComparatorSource.java Wed Jan 26 14:15:53 2011
@@ -0,0 +1,378 @@
+/*
+ * 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.jackrabbit.core.query.lucene;
+
+import org.apache.jackrabbit.core.HierarchyManager;
+import org.apache.jackrabbit.core.id.NodeId;
+import org.apache.jackrabbit.core.id.PropertyId;
+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.Path;
+import org.apache.jackrabbit.spi.PathFactory;
+import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
+import org.apache.jackrabbit.spi.commons.name.PathBuilder;
+import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.FieldComparatorSource;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Implements a <code>FieldComparatorSource</code> for <code>FieldComparator</code>s which
+ * know how to sort on a lucene field that contains values for multiple properties.
+ */
+public class SharedFieldComparatorSource extends FieldComparatorSource {
+
+    /**
+     * The name of the shared field in the lucene index.
+     */
+    private final String field;
+
+    /**
+     * The item state manager.
+     */
+    private final ItemStateManager ism;
+
+    /**
+     * The hierarchy manager on top of {@link #ism}.
+     */
+    private final HierarchyManager hmgr;
+
+    /**
+     * The index internal namespace mappings.
+     */
+    private final NamespaceMappings nsMappings;
+
+    /**
+     * Create a new <code>SharedFieldComparatorSource</code> for a given shared field.
+     *
+     * @param fieldname the shared field.
+     * @param ism       the item state manager of this workspace.
+     * @param hmgr      the hierarchy manager of this workspace.
+     * @param nsMappings the index internal namespace mappings.
+     */
+    public SharedFieldComparatorSource(String fieldname, ItemStateManager ism,
+                                       HierarchyManager hmgr, NamespaceMappings nsMappings) {
+        this.field = fieldname;
+        this.ism = ism;
+        this.hmgr = hmgr;
+        this.nsMappings = nsMappings;
+    }
+
+    /**
+     * Create a new <code>FieldComparator</code> for an embedded <code>propertyName</code>
+     * and a <code>reader</code>.
+     *
+     * @param propertyName the relative path to the property to sort on as returned
+     *          by {@link org.apache.jackrabbit.spi.Path#getString()}.
+     * @return a <code>FieldComparator</code>
+     * @throws java.io.IOException if an error occurs
+     */
+    @Override
+    public FieldComparator newComparator(String propertyName, int numHits, int sortPos,
+                                         boolean reversed) throws IOException {
+
+        PathFactory factory = PathFactoryImpl.getInstance();
+        Path path = factory.create(propertyName);
+
+        try {
+            SimpleFieldComparator simple = new SimpleFieldComparator(nsMappings.translatePath(path), field, numHits);
+
+            return path.getLength() == 1
+                ? simple
+                : new CompoundScoreFieldComparator(
+                        new FieldComparator[] { simple, new RelPathFieldComparator(path, numHits) }, numHits);
+
+        }
+        catch (IllegalNameException e) {
+            throw Util.createIOException(e);
+        }
+    }
+
+    /**
+     * Abstract base class for <code>FieldComparator</code>s which keep their values
+     * (<code>Comparable</code>s) in an array.
+     */
+    private abstract static class AbstractFieldComparator extends FieldComparatorBase {
+
+        /**
+         * The values for comparing.
+         */
+        private final Comparable[] values;
+
+        /**
+         * The index readers.
+         */
+
+        protected final List<IndexReader> readers = new ArrayList<IndexReader>();
+        /**
+         * The document number starts for the {@link #readers}.
+         */
+        protected int[] starts;
+
+        /**
+         * Create a new instance with the given number of values.
+         *
+         * @param numHits  the number of values
+         */
+        protected AbstractFieldComparator(int numHits) {
+            values = new Comparable[numHits];
+        }
+
+        /**
+         * Returns the reader index for document <code>n</code>.
+         *
+         * @param n document number.
+         * @return the reader index.
+         */
+        protected final int readerIndex(int n) {
+            int lo = 0;
+            int hi = readers.size() - 1;
+
+            while (hi >= lo) {
+                int mid = (lo + hi) >> 1;
+                int midValue = starts[mid];
+                if (n < midValue) {
+                    hi = mid - 1;
+                }
+                else if (n > midValue) {
+                    lo = mid + 1;
+                }
+                else {
+                    while (mid + 1 < readers.size() && starts[mid + 1] == midValue) {
+                        mid++;
+                    }
+                    return mid;
+                }
+            }
+            return hi;
+        }
+
+        /**
+         * Add the given value to the values array
+         *
+         * @param slot   index into values
+         * @param value  value for adding
+         */
+        @Override
+        public void setValue(int slot, Comparable value) {
+            values[slot] = value;
+        }
+
+        /**
+         * Return a value from the values array
+         *
+         * @param slot  index to retrieve
+         * @return  the retrieved value
+         */
+        @Override
+        public Comparable getValue(int slot) {
+            return values[slot];
+        }
+
+        @Override
+        public void setNextReader(IndexReader reader, int docBase) throws IOException {
+            getIndexReaders(readers, reader);
+
+            int maxDoc = 0;
+            starts = new int[readers.size() + 1];
+
+            for (int i = 0; i < readers.size(); i++) {
+                IndexReader r = readers.get(i);
+                starts[i] = maxDoc;
+                maxDoc += r.maxDoc();
+            }
+            starts[readers.size()] = maxDoc;
+        }
+
+        /**
+         * Checks if <code>reader</code> is of type {@link MultiIndexReader} and if
+         * so calls itself recursively for each reader within the
+         * <code>MultiIndexReader</code> or otherwise adds the reader to the list.
+         *
+         * @param readers  list of index readers.
+         * @param reader   reader to decompose
+         */
+        private static void getIndexReaders(List<IndexReader> readers, IndexReader reader) {
+            if (reader instanceof MultiIndexReader) {
+                for (IndexReader r : ((MultiIndexReader) reader).getIndexReaders()) {
+                    getIndexReaders(readers, r);
+                }
+            }
+            else {
+                readers.add(reader);
+            }
+        }
+    }
+
+    /**
+     * A <code>FieldComparator</code> which works for order by clauses with properties
+     * directly on the result nodes.
+     */
+    static final class SimpleFieldComparator extends AbstractFieldComparator {
+
+        /**
+         * The term look ups of the index segments.
+         */
+        protected SharedFieldCache.ValueIndex[] indexes;
+
+        /**
+         * The name of the property
+         */
+        private final String propertyName;
+
+        /**
+         * The name of the field in the index
+         */
+        private final String fieldName;
+
+        /**
+         * Create a new instance of the <code>FieldComparator</code>.
+         *
+         * @param propertyName  the name of the property
+         * @param fieldName     the name of the field in the index
+         * @param numHits       the number of values 
+         */
+        public SimpleFieldComparator(String propertyName, String fieldName, int numHits) {
+            super(numHits);
+            this.propertyName = propertyName;
+            this.fieldName = fieldName;
+        }
+
+        @Override
+        public void setNextReader(IndexReader reader, int docBase) throws IOException {
+            super.setNextReader(reader, docBase);
+
+            indexes = new SharedFieldCache.ValueIndex[readers.size()];
+
+            String namedValue = FieldNames.createNamedValue(propertyName, "");
+            for (int i = 0; i < readers.size(); i++) {
+                IndexReader r = readers.get(i);
+                indexes[i] = SharedFieldCache.INSTANCE.getValueIndex(r, fieldName, namedValue, this);
+            }
+        }
+
+        @Override
+        protected Comparable sortValue(int doc) {
+            int idx = readerIndex(doc);
+            return indexes[idx].getValue(doc - starts[idx]);
+        }
+
+    }
+
+    /**
+     * A <code>FieldComparator</code> which works with order by clauses that use a
+     * relative path to a property to sort on.
+     */
+    private final class RelPathFieldComparator extends AbstractFieldComparator {
+
+        /**
+         * Relative path to the property
+         */
+        private final Path propertyName;
+
+        /**
+         * Create a new instance of the <code>FieldComparator</code>.
+         *
+         * @param propertyName  relative path of the property
+         * @param numHits       the number of values
+         */
+        public RelPathFieldComparator(Path propertyName, int numHits) {
+            super(numHits);
+            this.propertyName = propertyName;
+        }
+
+        @Override
+        protected Comparable sortValue(int doc) {
+            try {
+                int idx = readerIndex(doc);
+                IndexReader reader = readers.get(idx);
+                Document document = reader.document(doc - starts[idx], FieldSelectors.UUID);
+                String uuid = document.get(FieldNames.UUID);
+                Path path = hmgr.getPath(new NodeId(uuid));
+                PathBuilder builder = new PathBuilder(path);
+                builder.addAll(propertyName.getElements());
+                PropertyId id = hmgr.resolvePropertyPath(builder.getPath());
+
+                if (id == null) {
+                    return null;
+                }
+
+                PropertyState state = (PropertyState) ism.getItemState(id);
+                if (state == null) {
+                    return null;
+                }
+
+                InternalValue[] values = state.getValues();
+                if (values.length > 0) {
+                    return Util.getComparable(values[0]);
+                }
+            }
+            catch (Exception ignore) { }
+
+            return null;
+        }
+
+    }
+
+    /**
+     * Implements a compound <code>FieldComparator</code> which delegates to several
+     * other comparators. The comparators are asked for a sort value in the
+     * sequence they are passed to the constructor.
+     */
+    private static final class CompoundScoreFieldComparator extends AbstractFieldComparator {
+        private final FieldComparator[] fieldComparators;
+
+        /**
+         * Create a new instance of the <code>FieldComparator</code>.
+         *
+         * @param fieldComparators  delegatees
+         * @param numHits           the number of values
+         */
+        public CompoundScoreFieldComparator(FieldComparator[] fieldComparators, int numHits) {
+            super(numHits);
+            this.fieldComparators = fieldComparators;
+        }
+
+        @Override
+        public Comparable sortValue(int doc) {
+            for (FieldComparator fieldComparator : fieldComparators) {
+                if (fieldComparator instanceof FieldComparatorBase) {
+                    Comparable c = ((FieldComparatorBase) fieldComparator).sortValue(doc);
+
+                    if (c != null) {
+                        return c;
+                    }
+                }
+            }
+            return null;
+        }
+
+        @Override
+        public void setNextReader(IndexReader reader, int docBase) throws IOException {
+            for (FieldComparator fieldComparator : fieldComparators) {
+                fieldComparator.setNextReader(reader, docBase);
+            }
+        }
+    }
+    
+}

Modified: jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SortedLuceneQueryHits.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SortedLuceneQueryHits.java?rev=1063730&r1=1063729&r2=1063730&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SortedLuceneQueryHits.java (original)
+++ jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SortedLuceneQueryHits.java Wed Jan 26 14:15:53 2011
@@ -16,19 +16,20 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.Sort;
-import org.apache.lucene.search.TopFieldDocCollector;
+import org.apache.lucene.search.TopFieldCollector;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
 /**
  * Wraps a lucene query result and adds a close method that allows to release
  * resources after a query has been executed and the results have been read
@@ -155,15 +156,14 @@ public final class SortedLuceneQueryHits
     //-------------------------------< internal >-------------------------------
 
     private void getHits() throws IOException {
-        TopFieldDocCollector collector = new TopFieldDocCollector(reader, sort, numHits);
+        TopFieldCollector collector = TopFieldCollector.create(sort, numHits, false, true, false, false);
         searcher.search(query, collector);
-        this.size = collector.getTotalHits();
+        size = collector.getTotalHits();
         ScoreDoc[] docs = collector.topDocs().scoreDocs;
-        for (int i = scoreDocs.size(); i < docs.length; i++) {
-            scoreDocs.add(docs[i]);
-        }
+        scoreDocs.addAll(Arrays.asList(docs).subList(scoreDocs.size(), docs.length));
         log.debug("getHits() {}/{}", scoreDocs.size(), numHits);
         // double hits for next round
         numHits *= 2;
     }
+
 }

Modified: jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SortedMultiColumnQueryHits.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SortedMultiColumnQueryHits.java?rev=1063730&r1=1063729&r2=1063730&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SortedMultiColumnQueryHits.java (original)
+++ jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SortedMultiColumnQueryHits.java Wed Jan 26 14:15:53 2011
@@ -16,19 +16,19 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
+import org.apache.jackrabbit.spi.Name;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.SortField;
+
 import java.io.IOException;
-import java.util.List;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.Arrays;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
-
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.SortField;
-import org.apache.lucene.search.ScoreDocComparator;
-import org.apache.lucene.search.ScoreDoc;
-import org.apache.jackrabbit.spi.Name;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
 
 /**
  * <code>SortedMultiColumnQueryHits</code> implements sorting of query hits
@@ -61,7 +61,7 @@ public class SortedMultiColumnQueryHits 
         }
         try {
             Collections.sort(sortedHits, new ScoreNodeComparator(
-                    reader, orderings, hits.getSelectorNames()));
+                    reader, orderings, hits.getSelectorNames(), sortedHits.size()));
         } catch (RuntimeException e) {
             // might be thrown by ScoreNodeComparator#compare
             throw Util.createIOException(e);
@@ -142,7 +142,8 @@ public class SortedMultiColumnQueryHits 
          */
         private ScoreNodeComparator(IndexReader reader,
                                     Ordering[] orderings,
-                                    Name[] selectorNames)
+                                    Name[] selectorNames,
+                                    int numHits)
                 throws IOException {
             this.reader = reader;
             this.orderings = orderings;
@@ -153,8 +154,11 @@ public class SortedMultiColumnQueryHits 
             for (int i = 0; i < orderings.length; i++) {
                 idx[i] = names.indexOf(orderings[i].getSelectorName());
                 SortField sf = orderings[i].getSortField();
-                if (sf.getFactory() != null) {
-                    comparators[i] = sf.getFactory().newComparator(reader, sf.getField());
+                if (sf.getComparatorSource() != null) {
+                    FieldComparator c = sf.getComparatorSource().newComparator(sf.getField(), numHits, 0, false);
+                    assert c instanceof FieldComparatorBase;
+                    comparators[i] = new ScoreDocComparator((FieldComparatorBase) c);
+                    comparators[i].setNextReader(reader, 0);
                 }
                 isReverse[i] = sf.getReverse();
             }
@@ -184,7 +188,7 @@ public class SortedMultiColumnQueryHits 
                     } catch (IOException e) {
                         throw new RuntimeException(e.getMessage(), e);
                     }
-                    c = comparators[i].compare(doc1, doc2);
+                    c = comparators[i].compareDocs(doc1.doc, doc2.doc);
                 } else {
                     // compare score
                     c = new Float(n1.getScore()).compareTo(n2.getScore());
@@ -198,5 +202,19 @@ public class SortedMultiColumnQueryHits 
             }
             return 0;
         }
+
     }
+
+    private static final class ScoreDocComparator extends FieldComparatorDecorator {
+
+        public ScoreDocComparator(FieldComparatorBase base) {
+            super(base);
+        }
+
+        public int compareDocs(int doc1, int doc2) {
+            return compare(sortValue(doc1), sortValue(doc2));
+        }
+
+    }
+
 }

Modified: jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/UpperCaseSortComparator.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/UpperCaseSortComparator.java?rev=1063730&r1=1063729&r2=1063730&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/UpperCaseSortComparator.java (original)
+++ jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/UpperCaseSortComparator.java Wed Jan 26 14:15:53 2011
@@ -16,71 +16,43 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import java.io.IOException;
+import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.FieldComparatorSource;
 
-import org.apache.lucene.search.ScoreDocComparator;
-import org.apache.lucene.search.ScoreDoc;
-import org.apache.lucene.search.SortField;
-import org.apache.lucene.search.SortComparatorSource;
-import org.apache.lucene.index.IndexReader;
+import java.io.IOException;
 
 /**
- * <code>UpperCaseSortComparator</code> implements a sort comparator that
+ * <code>UpperCaseSortComparator</code> implements a <code>FieldComparator</code> which
  * compares the upper-cased string values of a base sort comparator.
  */
-public class UpperCaseSortComparator implements SortComparatorSource {
-
-    private static final long serialVersionUID = 2562371983498948119L;
+public class UpperCaseSortComparator extends FieldComparatorSource {
     
     /**
      * The base sort comparator.
      */
-    private final SortComparatorSource base;
+    private final FieldComparatorSource base;
 
     /**
      * Creates a new upper case sort comparator.
      *
      * @param base the base sort comparator source.
      */
-    public UpperCaseSortComparator(SortComparatorSource base) {
+    public UpperCaseSortComparator(FieldComparatorSource base) {
         this.base = base;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public ScoreDocComparator newComparator(IndexReader reader,
-                                            String fieldname)
-            throws IOException {
-        return new Comparator(base.newComparator(reader, fieldname));
-    }
-
-    private static final class Comparator implements ScoreDocComparator {
-
-        private ScoreDocComparator base;
-
-        private Comparator(ScoreDocComparator base) {
-            this.base = base;
-        }
-
-        /**
-         * @see Util#compare(Comparable, Comparable)
-         */
-        public int compare(ScoreDoc i, ScoreDoc j) {
-            return Util.compare(sortValue(i), sortValue(j));
-        }
-
-        public Comparable sortValue(ScoreDoc i) {
-            Comparable c = base.sortValue(i);
-            if (c != null) {
-                return c.toString().toUpperCase();
-            } else {
-                return null;
+    @Override
+    public FieldComparator newComparator(String fieldname, int numHits, int sortPos, boolean reversed) throws IOException {
+        FieldComparator comparator = base.newComparator(fieldname, numHits, sortPos, reversed);
+        assert comparator instanceof FieldComparatorBase;
+
+        return new FieldComparatorDecorator((FieldComparatorBase) comparator) {
+            @Override
+            protected Comparable sortValue(int doc) {
+                Comparable c = super.sortValue(doc);
+                return c == null ? null : c.toString().toUpperCase();
             }
-        }
-
-        public int sortType() {
-            return SortField.CUSTOM;
-        }
+        };
     }
-}
\ No newline at end of file
+
+}

Modified: jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java?rev=1063730&r1=1063729&r2=1063730&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java (original)
+++ jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/WildcardQuery.java Wed Jan 26 14:15:53 2011
@@ -28,6 +28,7 @@ import org.apache.lucene.search.Searcher
 import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.Explanation;
 import org.apache.lucene.search.Similarity;
+import org.apache.lucene.util.ToStringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -140,11 +141,22 @@ public class WildcardQuery extends Query
      * @return the rewritten query.
      * @throws IOException if an error occurs while reading from the index.
      */
+    @Override
     public Query rewrite(IndexReader reader) throws IOException {
         Query stdWildcardQuery = new MultiTermQuery() {
             protected FilteredTermEnum getEnum(IndexReader reader) throws IOException {
                 return new WildcardTermEnum(reader, field, tvf, pattern, transform);
             }
+
+            /** Prints a user-readable version of this query. */
+            @Override
+            public String toString(String field) {
+                StringBuffer buffer = new StringBuffer();
+                buffer.append(field);
+                buffer.append(':');
+                buffer.append(ToStringUtils.boost(getBoost()));
+                return buffer.toString();
+            }
         };
         try {
             multiTermQuery = stdWildcardQuery.rewrite(reader);
@@ -162,6 +174,7 @@ public class WildcardQuery extends Query
      * @param searcher the searcher to use for the <code>Weight</code>.
      * @return the <code>Weigth</code> for this query.
      */
+    @Override
     public Weight createWeight(Searcher searcher) {
         return new WildcardQueryWeight(searcher, cache);
     }
@@ -172,13 +185,12 @@ public class WildcardQuery extends Query
      * @param field the field name for which to create a string representation.
      * @return a string representation of this query.
      */
+    @Override
     public String toString(String field) {
         return field + ":" + tvf.createValue(pattern);
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    @Override
     public void extractTerms(Set terms) {
         if (multiTermQuery != null) {
             multiTermQuery.extractTerms(terms);
@@ -219,33 +231,26 @@ public class WildcardQuery extends Query
          *
          * @return this <code>WildcardQuery</code>.
          */
+        @Override
         public Query getQuery() {
             return WildcardQuery.this;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        @Override
         public float getValue() {
             return 1.0f;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        @Override
         public float sumOfSquaredWeights() throws IOException {
             return 1.0f;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        @Override
         public void normalize(float norm) {
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        @Override
         public Explanation explain(IndexReader reader, int doc) throws IOException {
             return new Explanation();
         }

Modified: jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java?rev=1063730&r1=1063729&r2=1063730&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java (original)
+++ jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/directory/FSDirectoryManager.java Wed Jan 26 14:15:53 2011
@@ -16,10 +16,6 @@
  */
 package org.apache.jackrabbit.core.query.lucene.directory;
 
-import java.io.File;
-import java.io.FileFilter;
-import java.io.IOException;
-
 import org.apache.jackrabbit.core.query.lucene.IOCounters;
 import org.apache.jackrabbit.core.query.lucene.SearchIndex;
 import org.apache.lucene.store.Directory;
@@ -30,6 +26,10 @@ import org.apache.lucene.store.Lock;
 import org.apache.lucene.store.LockFactory;
 import org.apache.lucene.store.NativeFSLockFactory;
 
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+
 /**
  * <code>FSDirectoryManager</code> implements a directory manager for
  * {@link FSDirectory} instances.
@@ -150,7 +150,8 @@ public class FSDirectoryManager implemen
                     new NativeFSLockFactory(dir));
         }
 
-        public String[] list() throws IOException {
+        @Override
+        public String[] listAll() throws IOException {
             File[] files = directory.getFile().listFiles(FILTER);
             if (files == null) {
                 return null;
@@ -162,71 +163,81 @@ public class FSDirectoryManager implemen
             return names;
         }
 
+        @Override
         public boolean fileExists(String name) throws IOException {
             return directory.fileExists(name);
         }
 
+        @Override
         public long fileModified(String name) throws IOException {
             return directory.fileModified(name);
         }
 
+        @Override
         public void touchFile(String name) throws IOException {
             directory.touchFile(name);
         }
 
+        @Override
         public void deleteFile(String name) throws IOException {
             directory.deleteFile(name);
         }
 
-        public void renameFile(String from, String to) throws IOException {
-            throw new UnsupportedOperationException("Not available in Lucene 3.0.x");
-        }
-
+        @Override
         public long fileLength(String name) throws IOException {
             return directory.fileLength(name);
         }
 
+        @Override
         public IndexOutput createOutput(String name) throws IOException {
             return directory.createOutput(name);
         }
 
+        @Override
         public IndexInput openInput(String name) throws IOException {
             IndexInput in = directory.openInput(name);
             return new IndexInputLogWrapper(in);
         }
 
+        @Override
         public void close() throws IOException {
             directory.close();
         }
 
+        @Override
         public IndexInput openInput(String name, int bufferSize)
                 throws IOException {
             IndexInput in = directory.openInput(name, bufferSize);
             return new IndexInputLogWrapper(in);
         }
 
+        @Override
         public Lock makeLock(String name) {
             return directory.makeLock(name);
         }
 
+        @Override
         public void clearLock(String name) throws IOException {
             directory.clearLock(name);
         }
 
+        @Override
         public void setLockFactory(LockFactory lockFactory) {
             directory.setLockFactory(lockFactory);
         }
 
+        @Override
         public LockFactory getLockFactory() {
             return directory.getLockFactory();
         }
 
+        @Override
         public String getLockID() {
             return directory.getLockID();
         }
 
         public String toString() {
-            return this.getClass().getName() + "@" + directory;
+            return getClass().getName() + '@' + directory;
         }
     }
 
@@ -242,27 +253,33 @@ public class FSDirectoryManager implemen
             this.in = in;
         }
 
+        @Override
         public byte readByte() throws IOException {
             return in.readByte();
         }
 
+        @Override
         public void readBytes(byte[] b, int offset, int len) throws IOException {
             IOCounters.incrRead();
             in.readBytes(b, offset, len);
         }
 
+        @Override
         public void close() throws IOException {
             in.close();
         }
 
+        @Override
         public long getFilePointer() {
             return in.getFilePointer();
         }
 
+        @Override
         public void seek(long pos) throws IOException {
             in.seek(pos);
         }
 
+        @Override
         public long length() {
             return in.length();
         }

Modified: jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-parent/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-parent/pom.xml?rev=1063730&r1=1063729&r2=1063730&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-parent/pom.xml (original)
+++ jackrabbit/sandbox/JCR-2415-lucene-3.0/jackrabbit-parent/pom.xml Wed Jan 26 14:15:53 2011
@@ -257,7 +257,7 @@
       <dependency>
         <groupId>org.apache.lucene</groupId>
         <artifactId>lucene-core</artifactId>
-        <version>2.9.4</version>
+        <version>3.0.3</version>
       </dependency>
       <dependency>
         <groupId>org.apache.tika</groupId>



Mime
View raw message