jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1064058 [2/3] - in /jackrabbit/trunk: ./ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/...
Date Thu, 27 Jan 2011 09:33:15 GMT
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllScorer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllScorer.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllScorer.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllScorer.java Thu Jan 27 09:33:13 2011
@@ -20,15 +20,14 @@ import org.apache.lucene.index.IndexRead
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermDocs;
 import org.apache.lucene.index.TermEnum;
-import org.apache.lucene.search.Explanation;
-import org.apache.lucene.search.HitCollector;
+import org.apache.lucene.search.Collector;
 import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.Similarity;
 
 import java.io.IOException;
 import java.util.BitSet;
-import java.util.Map;
 import java.util.HashMap;
+import java.util.Map;
 
 /**
  * The MatchAllScorer implements a Scorer that scores / collects all
@@ -57,11 +56,6 @@ class MatchAllScorer extends Scorer {
     private BitSet docFilter;
 
     /**
-     * Explanation object. the same for all docs
-     */
-    private final Explanation matchExpl;
-
-    /**
      * Creates a new MatchAllScorer.
      *
      * @param reader the IndexReader
@@ -74,57 +68,49 @@ class MatchAllScorer extends Scorer {
         super(Similarity.getDefault());
         this.reader = reader;
         this.field = field;
-        matchExpl
-                = new Explanation(Similarity.getDefault().idf(reader.maxDoc(),
-                        reader.maxDoc()),
-                        "matchAll");
         calculateDocFilter(cache);
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public void score(HitCollector hc) throws IOException {
-        while (next()) {
-            hc.collect(doc(), score());
+    @Override
+    public void score(Collector collector) throws IOException {
+        collector.setScorer(this);
+
+        while (nextDoc() != NO_MORE_DOCS) {
+            collector.collect(docID());
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public boolean next() throws IOException {
+    @Override
+    public int nextDoc() throws IOException {
+        if (nextDoc == NO_MORE_DOCS) {
+            return nextDoc;
+        }
+
         nextDoc = docFilter.nextSetBit(nextDoc + 1);
-        return nextDoc > -1;
+        if (nextDoc < 0) {
+            nextDoc = NO_MORE_DOCS;
+        }
+        return nextDoc;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public int doc() {
+    @Override
+    public int docID() {
         return nextDoc;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    @Override
     public float score() throws IOException {
         return 1.0f;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public boolean skipTo(int target) throws IOException {
-        nextDoc = target - 1;
-        return next();
-    }
+    @Override
+    public int advance(int target) throws IOException {
+        if (nextDoc == NO_MORE_DOCS) {
+            return nextDoc;
+        }
 
-    /**
-     * {@inheritDoc}
-     */
-    public Explanation explain(int doc) {
-        return matchExpl;
+        nextDoc = target - 1;
+        return nextDoc();
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllWeight.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllWeight.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllWeight.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MatchAllWeight.java Thu Jan 27 09:33:13 2011
@@ -28,6 +28,7 @@ import java.io.IOException;
 /**
  * This class implements the Weight calculation for the MatchAllQuery.
  */
+@SuppressWarnings("serial")
 class MatchAllWeight extends AbstractWeight {
 
     /**
@@ -76,7 +77,8 @@ class MatchAllWeight extends AbstractWei
      * @param reader index reader
      * @return a {@link MatchAllScorer} instance
      */
-    protected Scorer createScorer(IndexReader reader) throws IOException {
+    protected Scorer createScorer(IndexReader reader, boolean scoreDocsInOrder,
+            boolean topScorer) throws IOException {
         return new MatchAllScorer(reader, field, cache);
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MoreLikeThis.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MoreLikeThis.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MoreLikeThis.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MoreLikeThis.java Thu Jan 27 09:33:13 2011
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.core.query.lucene;
 
 import org.apache.lucene.util.PriorityQueue;
+import org.apache.lucene.util.Version;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermFreqVector;
@@ -27,11 +28,12 @@ import org.apache.lucene.search.TermQuer
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.Token;
 import org.apache.lucene.analysis.TokenStream;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.analysis.tokenattributes.TermAttribute;
 import org.apache.lucene.document.Document;
 
+import java.util.List;
 import java.util.Set;
 import java.util.HashMap;
 import java.util.Map;
@@ -152,7 +154,7 @@ public final class MoreLikeThis {
      * Default analyzer to parse source doc with.
      * @see #getAnalyzer
      */
-    public static final Analyzer DEFAULT_ANALYZER = new StandardAnalyzer();
+    public static final Analyzer DEFAULT_ANALYZER = new StandardAnalyzer(Version.LUCENE_24);
 
     /**
      * Ignore terms with less than this frequency in the source doc.
@@ -202,12 +204,12 @@ public final class MoreLikeThis {
      * @see #setStopWords
      * @see #getStopWords
      */
-    public static final Set DEFAULT_STOP_WORDS = null;
+    public static final Set<String> DEFAULT_STOP_WORDS = null;
 
     /**
      * Current set of stop words.
      */
-    private Set stopWords = DEFAULT_STOP_WORDS;
+    private Set<String> stopWords = DEFAULT_STOP_WORDS;
 
     /**
      * Return a Query with no more than this many terms.
@@ -448,7 +450,7 @@ public final class MoreLikeThis {
      * @see org.apache.lucene.analysis.StopFilter#makeStopSet StopFilter.makeStopSet()
      * @see #getStopWords
      */
-    public void setStopWords(Set stopWords) {
+    public void setStopWords(Set<String> stopWords) {
         this.stopWords = stopWords;
     }
 
@@ -456,7 +458,7 @@ public final class MoreLikeThis {
      * Get the current stop words being used.
      * @see #setStopWords
      */
-    public Set getStopWords() {
+    public Set<String> getStopWords() {
         return stopWords;
     }
 
@@ -504,8 +506,9 @@ public final class MoreLikeThis {
     public Query like(int docNum) throws IOException {
         if (fieldNames == null) {
             // gather list of valid fields from lucene
-            Collection fields = ir.getFieldNames( IndexReader.FieldOption.INDEXED);
-            fieldNames = (String[]) fields.toArray(new String[fields.size()]);
+            @SuppressWarnings("unchecked")
+            Collection<String> fields = ir.getFieldNames(IndexReader.FieldOption.INDEXED);
+            fieldNames = fields.toArray(new String[fields.size()]);
         }
 
         return createQuery(retrieveTerms(docNum));
@@ -519,8 +522,9 @@ public final class MoreLikeThis {
     public Query like(File f) throws IOException {
         if (fieldNames == null) {
             // gather list of valid fields from lucene
-            Collection fields = ir.getFieldNames( IndexReader.FieldOption.INDEXED);
-            fieldNames = (String[]) fields.toArray(new String[fields.size()]);
+            @SuppressWarnings("unchecked")
+            Collection<String> fields = ir.getFieldNames(IndexReader.FieldOption.INDEXED);
+            fieldNames = fields.toArray(new String[fields.size()]);
         }
 
         return like(new FileReader(f));
@@ -596,14 +600,14 @@ public final class MoreLikeThis {
      *
      * @param words a map of words keyed on the word(String) with Int objects as the values.
      */
-    private PriorityQueue createQueue(Map words) throws IOException {
+    private PriorityQueue createQueue(Map<String, Int> words) throws IOException {
         // have collected all words in doc and their freqs
         int numDocs = ir.numDocs();
         FreqQ res = new FreqQ(words.size()); // will order words by score
 
-        Iterator it = words.keySet().iterator();
+        Iterator<String> it = words.keySet().iterator();
         while (it.hasNext()) { // for every word
-            String word = (String) it.next();
+            String word = it.next();
 
             int tf = ((Int) words.get(word)).x; // term freq in the source doc
             if (minTermFreq > 0 && tf < minTermFreq) {
@@ -631,7 +635,7 @@ public final class MoreLikeThis {
             float score = tf * idf;
 
             // only really need 1st 3 entries, other ones are for troubleshooting
-            res.insert(new Object[]{word,                   // the word
+            res.insertWithOverflow(new Object[]{word,                   // the word
                                     topField,               // the top field
                                     new Float(score),       // overall score
                                     new Float(idf),         // idf
@@ -670,7 +674,7 @@ public final class MoreLikeThis {
      * @param docNum the id of the lucene document from which to find terms
      */
     public PriorityQueue retrieveTerms(int docNum) throws IOException {
-        Map termFreqMap = new HashMap();
+        Map<String, Int> termFreqMap = new HashMap<String, Int>();
         for (int i = 0; i < fieldNames.length; i++) {
             String fieldName = fieldNames[i];
             TermFreqVector vector = ir.getTermFreqVector(docNum, fieldName);
@@ -699,7 +703,7 @@ public final class MoreLikeThis {
      * @param termFreqMap a Map of terms and their frequencies
      * @param vector List of terms and their frequencies for a doc/field
      */
-    private void addTermFrequencies(Map termFreqMap, TermFreqVector vector) {
+    private void addTermFrequencies(Map<String, Int> termFreqMap, TermFreqVector vector) {
         String[] terms = vector.getTerms();
         int[] freqs = vector.getTermFrequencies();
         for (int j = 0; j < terms.length; j++) {
@@ -727,14 +731,14 @@ public final class MoreLikeThis {
      * @param termFreqMap a Map of terms and their frequencies
      * @param fieldName Used by analyzer for any special per-field analysis
      */
-    private void addTermFrequencies(Reader r, Map termFreqMap, String fieldName)
+    private void addTermFrequencies(Reader r, Map<String, Int> termFreqMap, String fieldName)
             throws IOException {
         TokenStream ts = analyzer.tokenStream(fieldName, r);
         int tokenCount = 0;
         // for every token
-        final Token reusableToken = new Token();
-        for (Token nextToken = ts.next(reusableToken); nextToken != null; nextToken = ts.next(reusableToken)) {
-            String word = nextToken.term();
+        while (ts.incrementToken()) {
+            TermAttribute term = ts.getAttribute(TermAttribute.class);
+            String word =  term.term();
             tokenCount++;
             if (tokenCount > maxNumTokensParsed) {
                 break;
@@ -744,13 +748,15 @@ public final class MoreLikeThis {
             }
 
             // increment frequency
-            Int cnt = (Int) termFreqMap.get(word);
+            Int cnt = termFreqMap.get(word);
             if (cnt == null) {
                 termFreqMap.put(word, new Int());
             } else {
                 cnt.x++;
             }
         }
+        ts.end();
+        ts.close();
     }
 
     /** determines if the passed term is likely to be of interest in "more like" comparisons
@@ -796,7 +802,7 @@ public final class MoreLikeThis {
      * @see #retrieveInterestingTerms
      */
     public PriorityQueue retrieveTerms(Reader r) throws IOException {
-        Map words = new HashMap();
+        Map<String, Int> words = new HashMap<String, Int>();
         for (int i = 0; i < fieldNames.length; i++) {
             String fieldName = fieldNames[i];
             addTermFrequencies(r, words, fieldName);
@@ -808,17 +814,16 @@ public final class MoreLikeThis {
      * @see #retrieveInterestingTerms(java.io.Reader)
      */
     public String[] retrieveInterestingTerms(int docNum) throws IOException {
-        ArrayList al = new ArrayList(maxQueryTerms);
+        List<String> al = new ArrayList<String>(maxQueryTerms);
         PriorityQueue pq = retrieveTerms(docNum);
         Object cur;
         int lim = maxQueryTerms; // have to be careful, retrieveTerms returns all words but that's probably not useful to our caller...
         // we just want to return the top words
         while (((cur = pq.pop()) != null) && lim-- > 0) {
             Object[] ar = (Object[]) cur;
-            al.add(ar[0]); // the 1st entry is the interesting word
+            al.add((String) ar[0]); // the 1st entry is the interesting word
         }
-        String[] res = new String[al.size()];
-        return (String[]) al.toArray(res);
+        return al.toArray(new String[al.size()]);
     }
 
     /**
@@ -831,17 +836,16 @@ public final class MoreLikeThis {
      * @see #setMaxQueryTerms
      */
     public String[] retrieveInterestingTerms(Reader r) throws IOException {
-        ArrayList al = new ArrayList(maxQueryTerms);
+        List<String> al = new ArrayList<String>(maxQueryTerms);
         PriorityQueue pq = retrieveTerms(r);
         Object cur;
         int lim = maxQueryTerms; // have to be careful, retrieveTerms returns all words but that's probably not useful to our caller...
         // we just want to return the top words
         while (((cur = pq.pop()) != null) && lim-- > 0) {
             Object[] ar = (Object[]) cur;
-            al.add(ar[0]); // the 1st entry is the interesting word
+            al.add((String) ar[0]); // the 1st entry is the interesting word
         }
-        String[] res = new String[al.size()];
-        return (String[]) al.toArray(res);
+        return al.toArray(new String[al.size()]);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiScorer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiScorer.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiScorer.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiScorer.java Thu Jan 27 09:33:13 2011
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.core.query.lucene;
 
 import org.apache.lucene.search.Scorer;
-import org.apache.lucene.search.Explanation;
 import org.apache.lucene.search.Similarity;
 
 import java.io.IOException;
@@ -42,12 +41,12 @@ class MultiScorer extends Scorer {
     /**
      * Index of the current scorer.
      */
-    private int current = 0;
+    private int currentScorer;
 
     /**
-     * Indicates if there are more documents.
+     * The next document id to be returned
      */
-    private boolean hasNext = true;
+    private int currentDoc = -1;
 
     /**
      * Creates a new <code>MultiScorer</code> that spans multiple
@@ -63,64 +62,56 @@ class MultiScorer extends Scorer {
         this.starts = starts;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public boolean next() throws IOException {
-        while (hasNext) {
-            if (scorers[current].next()) {
-                return true;
-            } else if (++current < scorers.length) {
+    @Override
+    public int nextDoc() throws IOException {
+        while (currentDoc != NO_MORE_DOCS) {
+            if (scorers[currentScorer].nextDoc() != NO_MORE_DOCS) {
+                currentDoc = scorers[currentScorer].docID() + starts[currentScorer];
+                return currentDoc;
+            } else if (++currentScorer < scorers.length) {
                 // advance to next scorer
             } else {
                 // no more scorers
-                hasNext = false;
+                currentDoc = NO_MORE_DOCS;
             }
         }
-        return hasNext;
+
+        return currentDoc;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public int doc() {
-        return scorers[current].doc() + starts[current];
+    @Override
+    public int docID() {
+        return currentDoc;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    @Override
     public float score() throws IOException {
-        return scorers[current].score();
+        return scorers[currentScorer].score();
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public boolean skipTo(int target) throws IOException {
-        current = scorerIndex(target);
-        if (scorers[current].skipTo(target - starts[current])) {
-            return true;
+    @Override
+    public int advance(int target) throws IOException {
+        if (currentDoc == NO_MORE_DOCS) {
+            return currentDoc;
+        }
+
+        currentScorer = scorerIndex(target);
+        if (scorers[currentScorer].advance(target - starts[currentScorer]) != NO_MORE_DOCS) {
+            currentDoc = scorers[currentScorer].docID() + starts[currentScorer];
+            return currentDoc;
         } else {
-            if (++current < scorers.length) {
+            if (++currentScorer < scorers.length) {
                 // simply move to the next if there is any
-                return next();
+                currentDoc = nextDoc();
+                return currentDoc;
             } else {
                 // no more document
-                hasNext = false;
-                return hasNext;
+                currentDoc = NO_MORE_DOCS;
+                return currentDoc;
             }
         }
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public Explanation explain(int doc) throws IOException {
-        int scorerIndex = scorerIndex(doc);
-        return scorers[scorerIndex].explain(doc - starts[scorerIndex]);
-    }
-
     //--------------------------< internal >------------------------------------
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameQuery.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameQuery.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameQuery.java Thu Jan 27 09:33:13 2011
@@ -30,6 +30,7 @@ import java.util.Set;
 /**
  * <code>NameQuery</code> implements a query for the name of a node.
  */
+@SuppressWarnings("serial")
 public class NameQuery extends Query {
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameRangeQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameRangeQuery.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameRangeQuery.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NameRangeQuery.java Thu Jan 27 09:33:13 2011
@@ -30,6 +30,7 @@ import java.io.IOException;
 /**
  * <code>NameRangeQuery</code>...
  */
+@SuppressWarnings("serial")
 public class NameRangeQuery extends Query {
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeIndexer.java Thu Jan 27 09:33:13 2011
@@ -16,19 +16,6 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import java.math.BigDecimal;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.Executor;
-
-import javax.jcr.NamespaceException;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.id.PropertyId;
 import org.apache.jackrabbit.core.state.ChildNodeEntry;
@@ -50,6 +37,18 @@ import org.apache.tika.parser.Parser;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.jcr.NamespaceException;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.Executor;
+
 /**
  * Creates a lucene <code>Document</code> object from a {@link javax.jcr.Node}.
  */
@@ -369,7 +368,7 @@ public class NodeIndexer {
                     // never fulltext index jcr:uuid String
                     if (name.equals(NameConstants.JCR_UUID)) {
                         addStringValue(doc, fieldName, value.getString(),
-                                false, false, DEFAULT_BOOST);
+                                false, false, DEFAULT_BOOST, true);
                     } else {
                         addStringValue(doc, fieldName, value.getString(),
                                 true, isIncludedInNodeIndex(name),
@@ -666,7 +665,7 @@ public class NodeIndexer {
      *             addStringValue(Document, String, Object, boolean)} instead.
      */
     protected void addStringValue(Document doc, String fieldName, Object internalValue) {
-        addStringValue(doc, fieldName, internalValue, true, true, DEFAULT_BOOST);
+        addStringValue(doc, fieldName, internalValue, true, true, DEFAULT_BOOST, true);
     }
 
     /**
@@ -682,7 +681,7 @@ public class NodeIndexer {
      */
     protected void addStringValue(Document doc, String fieldName,
                                   Object internalValue, boolean tokenized) {
-        addStringValue(doc, fieldName, internalValue, tokenized, true, DEFAULT_BOOST);
+        addStringValue(doc, fieldName, internalValue, tokenized, true, DEFAULT_BOOST, true);
     }
 
     /**
@@ -814,14 +813,10 @@ public class NodeIndexer {
             tv = Field.TermVector.NO;
         }
         if (store) {
-            // store field compressed if greater than 16k
-            Field.Store stored;
-            if (value.length() > 0x4000) {
-                stored = Field.Store.COMPRESS;
-            } else {
-                stored = Field.Store.YES;
-            }
-            return new Field(FieldNames.FULLTEXT, value, stored,
+            // We would be able to store the field compressed or not depending
+            // on a criterion but then we could not determine later is this field
+            // has been compressed or not, so we choose to store it uncompressed
+            return new Field(FieldNames.FULLTEXT, value, Field.Store.YES,
                     Field.Index.ANALYZED, tv);
         } else {
             return new Field(FieldNames.FULLTEXT, value,

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeTraversingQueryHits.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeTraversingQueryHits.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeTraversingQueryHits.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NodeTraversingQueryHits.java Thu Jan 27 09:33:13 2011
@@ -37,7 +37,7 @@ public class NodeTraversingQueryHits ext
     /**
      * The nodes to traverse.
      */
-    private final Iterator nodes;
+    private final Iterator<Node> nodes;
 
     /**
      * Creates query hits that consist of the nodes that are traversed from a

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NotQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NotQuery.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NotQuery.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/NotQuery.java Thu Jan 27 09:33:13 2011
@@ -33,6 +33,7 @@ import java.util.Set;
  * Documents that did not match the context query will be selected by this
  * <code>NotQuery</code>.
  */
+@SuppressWarnings("serial")
 class NotQuery extends Query {
 
     /**
@@ -56,7 +57,7 @@ class NotQuery extends Query {
     /**
      * {@inheritDoc}
      */
-    protected Weight createWeight(Searcher searcher) {
+    public Weight createWeight(Searcher searcher) {
         return new NotQueryWeight(searcher);
     }
 
@@ -89,7 +90,7 @@ class NotQuery extends Query {
     /**
      * Implements a weight for this <code>NotQuery</code>.
      */
-    private class NotQueryWeight implements Weight {
+    private class NotQueryWeight extends Weight {
 
         /**
          * The searcher to access the index.
@@ -134,8 +135,9 @@ class NotQuery extends Query {
         /**
          * @inheritDoc
          */
-        public Scorer scorer(IndexReader reader) throws IOException {
-            contextScorer = context.weight(searcher).scorer(reader);
+        public Scorer scorer(IndexReader reader, boolean scoreDocsInOrder,
+                boolean topScorer) throws IOException {
+            contextScorer = context.weight(searcher).scorer(reader, scoreDocsInOrder, topScorer);
             return new NotQueryScorer(reader);
         }
 
@@ -177,14 +179,17 @@ class NotQuery extends Query {
             this.reader = reader;
         }
 
-        /**
-         * {@inheritDoc}
-         */
-        public boolean next() throws IOException {
+        @Override
+        public int nextDoc() throws IOException {
+            if (docNo == NO_MORE_DOCS) {
+                return docNo;
+            }
+
             if (docNo == -1) {
                 // get first doc of context scorer
-                if (contextScorer.next()) {
-                    contextNo = contextScorer.doc();
+                int docId = contextScorer.nextDoc();
+                if (docId != NO_MORE_DOCS) {
+                    contextNo = docId;
                 }
             }
             // move to next candidate
@@ -195,49 +200,38 @@ class NotQuery extends Query {
             // check with contextScorer
             while (contextNo != -1 && contextNo == docNo) {
                 docNo++;
-                if (contextScorer.next()) {
-                    contextNo = contextScorer.doc();
-                } else {
-                    contextNo = -1;
-                }
+                int docId = contextScorer.nextDoc();
+                contextNo = docId == NO_MORE_DOCS ? -1 : docId;
+            }
+            if (docNo >= reader.maxDoc()) {
+                docNo = NO_MORE_DOCS;
             }
-            return docNo < reader.maxDoc();
+            return docNo;
         }
 
-        /**
-         * {@inheritDoc}
-         */
-        public int doc() {
+        @Override
+        public int docID() {
             return docNo;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        @Override
         public float score() throws IOException {
             return 1.0f;
         }
 
-        /**
-         * {@inheritDoc}
-         */
-        public boolean skipTo(int target) throws IOException {
+        @Override
+        public int advance(int target) throws IOException {
+            if (docNo == NO_MORE_DOCS) {
+                return docNo;
+            }
+
             if (contextNo != -1 && contextNo < target) {
-                if (contextScorer.skipTo(target)) {
-                    contextNo = contextScorer.doc();
-                } else {
-                    contextNo = -1;
-                }
+                int docId = contextScorer.advance(target);
+                contextNo = docId == NO_MORE_DOCS ? -1 : docId;
             }
             docNo = target - 1;
-            return next();
+            return nextDoc();
         }
 
-        /**
-         * @throws UnsupportedOperationException always
-         */
-        public Explanation explain(int doc) throws IOException {
-            throw new UnsupportedOperationException();
-        }
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/OffsetCharSequence.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/OffsetCharSequence.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/OffsetCharSequence.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/OffsetCharSequence.java Thu Jan 27 09:33:13 2011
@@ -20,7 +20,7 @@ package org.apache.jackrabbit.core.query
  * CharSequence that applies an offset to a base CharSequence. The base
  * CharSequence can be replaced without creating a new CharSequence.
  */
-final class OffsetCharSequence implements CharSequence, Comparable, TransformConstants {
+final class OffsetCharSequence implements CharSequence, Comparable<OffsetCharSequence>, TransformConstants {
 
     /**
      * Indicates how the underlying char sequence is exposed / tranformed.
@@ -128,8 +128,7 @@ final class OffsetCharSequence implement
      * @return as defined in {@link String#compareTo(Object)} but also takes
      *         {@link #transform} into account.
      */
-    public int compareTo(Object o) {
-        OffsetCharSequence other = (OffsetCharSequence) o;
+    public int compareTo(OffsetCharSequence other) {
         int len1 = length();
         int len2 = other.length();
         int lim = Math.min(len1, len2);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Ordering.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Ordering.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Ordering.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Ordering.java Thu Jan 27 09:33:13 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/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ParentAxisQuery.java Thu Jan 27 09:33:13 2011
@@ -16,27 +16,28 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import java.io.IOException;
-import java.util.BitSet;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
+import org.apache.jackrabbit.core.query.lucene.hits.AbstractHitCollector;
 import org.apache.jackrabbit.core.query.lucene.hits.Hits;
 import org.apache.jackrabbit.core.query.lucene.hits.ScorerHits;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.search.Explanation;
-import org.apache.lucene.search.HitCollector;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.Searcher;
 import org.apache.lucene.search.Similarity;
 import org.apache.lucene.search.Weight;
 
+import java.io.IOException;
+import java.util.BitSet;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
 /**
  * <code>ParentAxisQuery</code> selects the parent nodes of a context query.
  */
+@SuppressWarnings("serial")
 class ParentAxisQuery extends Query {
 
     /**
@@ -89,7 +90,7 @@ class ParentAxisQuery extends Query {
      * @param searcher the <code>Searcher</code> instance to use.
      * @return a <code>ParentAxisWeight</code>.
      */
-    protected Weight createWeight(Searcher searcher) {
+    public Weight createWeight(Searcher searcher) {
         return new ParentAxisWeight(searcher);
     }
 
@@ -133,7 +134,7 @@ class ParentAxisQuery extends Query {
     /**
      * The <code>Weight</code> implementation for this <code>ParentAxisQuery</code>.
      */
-    private class ParentAxisWeight implements Weight {
+    private class ParentAxisWeight extends Weight {
 
         /**
          * The searcher in use
@@ -186,8 +187,9 @@ class ParentAxisQuery extends Query {
          * @return a <code>ParentAxisScorer</code>.
          * @throws IOException if an error occurs while reading from the index.
          */
-        public Scorer scorer(IndexReader reader) throws IOException {
-            contextScorer = contextQuery.weight(searcher).scorer(reader);
+        public Scorer scorer(IndexReader reader, boolean scoreDocsInOrder,
+                boolean topScorer) throws IOException {
+            contextScorer = contextQuery.weight(searcher).scorer(reader, scoreDocsInOrder, topScorer);
             HierarchyResolver resolver = (HierarchyResolver) reader;
             return new ParentAxisScorer(searcher.getSimilarity(),
                     reader, searcher, resolver);
@@ -266,25 +268,26 @@ class ParentAxisQuery extends Query {
             this.hResolver = resolver;
         }
 
-        /**
-         * {@inheritDoc}
-         */
-        public boolean next() throws IOException {
+        @Override
+        public int nextDoc() throws IOException {
+            if (nextDoc == NO_MORE_DOCS) {
+                return nextDoc;
+            }
+
             calculateParent();
             nextDoc = hits.nextSetBit(nextDoc + 1);
-            return nextDoc > -1;
+            if (nextDoc < 0) {
+                nextDoc = NO_MORE_DOCS;
+            }
+            return nextDoc;
         }
 
-        /**
-         * {@inheritDoc}
-         */
-        public int doc() {
+        @Override
+        public int docID() {
             return nextDoc;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        @Override
         public float score() throws IOException {
             Float score = scores.get(nextDoc);
             if (score == null) {
@@ -293,23 +296,18 @@ class ParentAxisQuery extends Query {
             return score;
         }
 
-        /**
-         * {@inheritDoc}
-         */
-        public boolean skipTo(int target) throws IOException {
+        @Override
+        public int advance(int target) throws IOException {
+            if (nextDoc == NO_MORE_DOCS) {
+                return nextDoc;
+            }
+
             calculateParent();
             nextDoc = hits.nextSetBit(target);
-            return nextDoc > -1;
-        }
-
-        /**
-         * {@inheritDoc}
-         *
-         * @throws UnsupportedOperationException this implementation always
-         *                                       throws an <code>UnsupportedOperationException</code>.
-         */
-        public Explanation explain(int doc) throws IOException {
-            throw new UnsupportedOperationException();
+            if (nextDoc < 0) {
+                nextDoc = NO_MORE_DOCS;
+            }
+            return nextDoc;
         }
 
         private void calculateParent() throws IOException {
@@ -317,36 +315,38 @@ class ParentAxisQuery extends Query {
                 hits = new BitSet(reader.maxDoc());
 
                 final IOException[] ex = new IOException[1];
-                contextScorer.score(new HitCollector() {
-
-                    private int[] docs = new int[1];
-
-                    public void collect(int doc, float score) {
-                        try {
-                            docs = hResolver.getParents(doc, docs);
-                            if (docs.length == 1) {
-                                // optimize single value
-                                hits.set(docs[0]);
-                                if (firstScore == null) {
-                                    firstScore = score;
-                                } else if (firstScore != score) {
-                                    scores.put(doc, score);
-                                }
-                            } else {
-                                for (int docNum : docs) {
-                                    hits.set(docNum);
+                if (contextScorer != null) {
+                    contextScorer.score(new AbstractHitCollector() {
+                        private int[] docs = new int[1];
+
+                        @Override
+                        protected void collect(int doc, float score) {
+                            try {
+                                docs = hResolver.getParents(doc, docs);
+                                if (docs.length == 1) {
+                                    // optimize single value
+                                    hits.set(docs[0]);
                                     if (firstScore == null) {
                                         firstScore = score;
                                     } else if (firstScore != score) {
                                         scores.put(doc, score);
                                     }
+                                } else {
+                                    for (int docNum : docs) {
+                                        hits.set(docNum);
+                                        if (firstScore == null) {
+                                            firstScore = score;
+                                        } else if (firstScore != score) {
+                                            scores.put(doc, score);
+                                        }
+                                    }
                                 }
+                            } catch (IOException e) {
+                                ex[0] = e;
                             }
-                        } catch (IOException e) {
-                            ex[0] = e;
                         }
-                    }
-                });
+                    });
+                }
 
                 if (ex[0] != null) {
                     throw ex[0];
@@ -355,7 +355,7 @@ class ParentAxisQuery extends Query {
                 // filter out documents that do not match the name test
                 if (nameTest != null) {
                     Query nameQuery = new NameQuery(nameTest, version, nsMappings);
-                    Hits nameHits = new ScorerHits(nameQuery.weight(searcher).scorer(reader));
+                    Hits nameHits = new ScorerHits(nameQuery.weight(searcher).scorer(reader, true, false));
                     for (int i = hits.nextSetBit(0); i >= 0; i = hits.nextSetBit(i + 1)) {
                         int doc = nameHits.skipTo(i);
                         if (doc == -1) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PersistentIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PersistentIndex.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PersistentIndex.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PersistentIndex.java Thu Jan 27 09:33:13 2011
@@ -130,7 +130,7 @@ class PersistentIndex extends AbstractIn
         byte[] buffer = new byte[1024];
         Directory dir = index.getDirectory();
         Directory dest = getDirectory();
-        String[] files = dir.list();
+        String[] files = dir.listAll();
         for (String file : files) {
             IndexInput in = dir.openInput(file);
             try {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PredicateDerefQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PredicateDerefQuery.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PredicateDerefQuery.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PredicateDerefQuery.java Thu Jan 27 09:33:13 2011
@@ -16,28 +16,27 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.BitSet;
-import java.util.List;
-import java.util.Set;
-
+import org.apache.jackrabbit.core.query.lucene.hits.AbstractHitCollector;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermDocs;
 import org.apache.lucene.search.Explanation;
-import org.apache.lucene.search.HitCollector;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.Searcher;
 import org.apache.lucene.search.Similarity;
 import org.apache.lucene.search.Weight;
 
+import java.io.IOException;
+import java.util.BitSet;
+import java.util.Set;
+
 /**
  * Implements a Lucene <code>Query</code> which returns the nodes which have a 
  * reference property which matches the nodes of the subquery.
  */
+@SuppressWarnings("serial")
 public class PredicateDerefQuery extends Query {
 
     /**
@@ -101,7 +100,7 @@ public class PredicateDerefQuery extends
      * @param searcher the <code>Searcher</code> instance to use.
      * @return a <code>DerefWeight</code>.
      */
-    protected Weight createWeight(Searcher searcher) {
+    public Weight createWeight(Searcher searcher) {
         return new DerefWeight(searcher);
     }
 
@@ -148,7 +147,7 @@ public class PredicateDerefQuery extends
     /**
      * The <code>Weight</code> implementation for this <code>DerefQuery</code>.
      */
-    private class DerefWeight implements Weight {
+    private class DerefWeight extends Weight {
 
         /**
          * The searcher in use
@@ -201,10 +200,11 @@ public class PredicateDerefQuery extends
          * @return a <code>DerefScorer</code>.
          * @throws IOException if an error occurs while reading from the index.
          */
-        public Scorer scorer(IndexReader reader) throws IOException {
-            subQueryScorer = subQuery.weight(searcher).scorer(reader);
+        public Scorer scorer(IndexReader reader, boolean scoreDocsInOrder,
+                boolean topScorer) throws IOException {
+            subQueryScorer = subQuery.weight(searcher).scorer(reader, scoreDocsInOrder, topScorer);
             if (nameTest != null) {
-                nameTestScorer = new NameQuery(nameTest, version, nsMappings).weight(searcher).scorer(reader);
+                nameTestScorer = new NameQuery(nameTest, version, nsMappings).weight(searcher).scorer(reader, scoreDocsInOrder, topScorer);
             }
             return new DerefScorer(searcher.getSimilarity(), reader);
         }
@@ -233,18 +233,13 @@ public class PredicateDerefQuery extends
          * BitSet storing the id's of selected documents
          */
         private final BitSet subQueryHits;
-        
+
         /**
          * BitSet storing the id's of selected documents
          */
         private final BitSet hits;
 
-        /**
-         * List of UUIDs of selected nodes
-         */
-        private List uuids = null;
 
-        
         /**
          * The next document id to return
          */
@@ -263,49 +258,44 @@ public class PredicateDerefQuery extends
             this.subQueryHits = new BitSet(reader.maxDoc());
         }
 
-        /**
-         * {@inheritDoc}
-         */
-        public boolean next() throws IOException {
+        @Override
+        public int nextDoc() throws IOException {
+            if (nextDoc == NO_MORE_DOCS) {
+                return nextDoc;
+            }
+
             calculateChildren();
             nextDoc = hits.nextSetBit(nextDoc + 1);
-            return nextDoc > -1;
+            if (nextDoc < 0) {
+                nextDoc = NO_MORE_DOCS;
+            }
+            return nextDoc;
         }
 
-        /**
-         * {@inheritDoc}
-         */
-        public int doc() {
+        @Override
+        public int docID() {
             return nextDoc;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        @Override
         public float score() throws IOException {
             return 1.0f;
         }
 
-        /**
-         * {@inheritDoc}
-         */
-        public boolean skipTo(int target) throws IOException {
+        @Override
+        public int advance(int target) throws IOException {
+            if (nextDoc == NO_MORE_DOCS) {
+                return nextDoc;
+            }
+
             calculateChildren();
             nextDoc = hits.nextSetBit(target);
-            return nextDoc > -1;
-        }
-
-        /**
-         * {@inheritDoc}
-         *
-         * @throws UnsupportedOperationException this implementation always
-         *                                       throws an <code>UnsupportedOperationException</code>.
-         */
-        public Explanation explain(int doc) throws IOException {
-            throw new UnsupportedOperationException();
+            if (nextDoc < 0) {
+                nextDoc = NO_MORE_DOCS;
+            }
+            return nextDoc;
         }
 
-
         /**
          * Perform the sub query
          * For each reference property UUID
@@ -315,59 +305,58 @@ public class PredicateDerefQuery extends
          * @throws IOException
          */
         private void calculateChildren() throws IOException {
-            if (uuids == null) {
-                uuids = new ArrayList();
 //                subQueryHits.clear();
 //                hits.clear();
-                subQueryScorer.score(new HitCollector() {
-                    public void collect(int doc, float score) {
-                        subQueryHits.set(doc);
-                    }
-                });
+            subQueryScorer.score(new AbstractHitCollector() {
+                @Override
+                protected void collect(int doc, float score) {
+                    subQueryHits.set(doc);
+                }
+            });
 
-                TermDocs termDocs = reader.termDocs(new Term(FieldNames.PROPERTIES_SET, refProperty));
-                String prefix = FieldNames.createNamedValue(refProperty, "");
-                while (termDocs.next()) {
-                    int doc = termDocs.doc();
-                     
-                    String[] values = reader.document(doc).getValues(FieldNames.PROPERTIES);
-                    if (values == null) {
-                        // no reference properties at all on this node
-                        continue;
-                    }
-                    for (int v = 0; v < values.length; v++) {
-                        if (values[v].startsWith(prefix)) {
-                            String uuid = values[v].substring(prefix.length());
-                            
-                            TermDocs node = reader.termDocs(TermFactory.createUUIDTerm(uuid));
-                            try {
-                                while (node.next()) {
-                                    if (subQueryHits.get(node.doc())) {
-                                        hits.set(doc);
-                                    }
+            TermDocs termDocs = reader.termDocs(new Term(FieldNames.PROPERTIES_SET, refProperty));
+            String prefix = FieldNames.createNamedValue(refProperty, "");
+            while (termDocs.next()) {
+                int doc = termDocs.doc();
+
+                String[] values = reader.document(doc).getValues(FieldNames.PROPERTIES);
+                if (values == null) {
+                    // no reference properties at all on this node
+                    continue;
+                }
+                for (int v = 0; v < values.length; v++) {
+                    if (values[v].startsWith(prefix)) {
+                        String uuid = values[v].substring(prefix.length());
+
+                        TermDocs node = reader.termDocs(TermFactory.createUUIDTerm(uuid));
+                        try {
+                            while (node.next()) {
+                                if (subQueryHits.get(node.doc())) {
+                                    hits.set(doc);
                                 }
-                            } finally {
-                                node.close();
                             }
+                        } finally {
+                            node.close();
                         }
                     }
                 }
-                
-                // collect nameTest hits
-                final BitSet nameTestHits = new BitSet();
-                if (nameTestScorer != null) {
-                    nameTestScorer.score(new HitCollector() {
-                        public void collect(int doc, float score) {
-                            nameTestHits.set(doc);
-                        }
-                    });
-                }
+            }
 
-                // filter out the target nodes that do not match the name test
-                // if there is any name test at all.
-                if (nameTestScorer != null) {
-                    hits.and(nameTestHits);
-                }
+            // collect nameTest hits
+            final BitSet nameTestHits = new BitSet();
+            if (nameTestScorer != null) {
+                nameTestScorer.score(new AbstractHitCollector() {
+                    @Override
+                    protected void collect(int doc, float score) {
+                        nameTestHits.set(doc);
+                    }
+                });
+            }
+
+            // filter out the target nodes that do not match the name test
+            // if there is any name test at all.
+            if (nameTestScorer != null) {
+                hits.and(nameTestHits);
             }
         }
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryHitsQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryHitsQuery.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryHitsQuery.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryHitsQuery.java Thu Jan 27 09:33:13 2011
@@ -39,6 +39,7 @@ import java.util.TreeSet;
  * <code>QueryHitsQuery</code> exposes a {@link QueryHits} implementation again
  * as a Lucene Query.
  */
+@SuppressWarnings("serial")
 public class QueryHitsQuery extends Query implements JackrabbitQuery{
 
     /**
@@ -58,7 +59,7 @@ public class QueryHitsQuery extends Quer
     /**
      * {@inheritDoc}
      */
-    protected Weight createWeight(Searcher searcher) throws IOException {
+    public Weight createWeight(Searcher searcher) throws IOException {
         return new QueryHitsQueryWeight(searcher.getSimilarity());
     }
 
@@ -96,7 +97,7 @@ public class QueryHitsQuery extends Quer
     /**
      * The Weight implementation for this query.
      */
-    public class QueryHitsQueryWeight implements Weight {
+    public class QueryHitsQueryWeight extends Weight {
 
         /**
          * The similarity.
@@ -142,7 +143,8 @@ public class QueryHitsQuery extends Quer
         /**
          * {@inheritDoc}
          */
-        public Scorer scorer(IndexReader reader) throws IOException {
+        public Scorer scorer(IndexReader reader, boolean scoreDocsInOrder,
+                boolean topScorer) throws IOException {
             return new QueryHitsQueryScorer(reader, similarity);
         }
 
@@ -165,7 +167,7 @@ public class QueryHitsQuery extends Quer
          * Iterator over <code>Integer</code> instances identifying the
          * lucene documents. Document numbers are iterated in ascending order.
          */
-        private final Iterator docs;
+        private final Iterator<Integer> docs;
 
         /**
          * Maps <code>Integer</code> document numbers to <code>Float</code>
@@ -212,48 +214,39 @@ public class QueryHitsQuery extends Quer
             docs = sortedDocs.iterator();
         }
 
-        /**
-         * {@inheritDoc}
-         */
-        public boolean next() throws IOException {
-            if (docs.hasNext()) {
-                currentDoc = (Integer) docs.next();
-                return true;
+        @Override
+        public int nextDoc() throws IOException {
+            if (currentDoc == NO_MORE_DOCS) {
+                return currentDoc;
             }
-            return false;
-        }
 
-        /**
-         * {@inheritDoc}
-         */
-        public int doc() {
+            currentDoc = docs.hasNext() ? docs.next() : NO_MORE_DOCS;
             return currentDoc;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        @Override
+        public int docID() {
+            return currentDoc == null ? -1 : currentDoc;
+        }
+
+        @Override
         public float score() throws IOException {
             return scores.get(currentDoc);
         }
 
-        /**
-         * {@inheritDoc}
-         */
-        public boolean skipTo(int target) throws IOException {
+        @Override
+        public int advance(int target) throws IOException {
+            if (currentDoc == NO_MORE_DOCS) {
+                return currentDoc;
+            }
+
             do {
-                if (!next()) {
-                    return false;
+                if (nextDoc() == NO_MORE_DOCS) {
+                    return NO_MORE_DOCS;
                 }
-            } while (target > doc());
-            return true;
+            } while (target > docID());
+            return docID();
         }
 
-        /**
-         * {@inheritDoc}
-         */
-        public Explanation explain(int doc) throws IOException {
-            return new Explanation();
-        }
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RangeQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RangeQuery.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RangeQuery.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RangeQuery.java Thu Jan 27 09:33:13 2011
@@ -16,14 +16,6 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.BitSet;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermDocs;
@@ -34,16 +26,26 @@ import org.apache.lucene.search.Query;
 import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.Searcher;
 import org.apache.lucene.search.Similarity;
+import org.apache.lucene.search.TermRangeQuery;
 import org.apache.lucene.search.Weight;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 /**
  * Implements a variant of the lucene class {@link org.apache.lucene.search.RangeQuery}.
  * This class does not rewrite to basic {@link org.apache.lucene.search.TermQuery}
  * but will calculate the matching documents itself. That way a
  * <code>TooManyClauses</code> can be avoided.
  */
+@SuppressWarnings("serial")
 public class RangeQuery extends Query implements Transformable {
 
     /**
@@ -147,7 +149,7 @@ public class RangeQuery extends Query im
     public Query rewrite(IndexReader reader) throws IOException {
         if (transform == TRANSFORM_NONE) {
             Query stdRangeQueryImpl
-                    = new org.apache.lucene.search.RangeQuery(lowerTerm, upperTerm, inclusive);
+                    = new TermRangeQuery(lowerTerm.field(), lowerTerm.text(), upperTerm.text(), inclusive, inclusive);
             try {
                 stdRangeQuery = stdRangeQueryImpl.rewrite(reader);
                 return stdRangeQuery;
@@ -169,7 +171,7 @@ public class RangeQuery extends Query im
      * @param searcher the searcher to use for the <code>Weight</code>.
      * @return the <code>Weigth</code> for this query.
      */
-    protected Weight createWeight(Searcher searcher) {
+    public Weight createWeight(Searcher searcher) {
         return new RangeQueryWeight(searcher, cache);
     }
 
@@ -238,7 +240,8 @@ public class RangeQuery extends Query im
          * @param reader index reader
          * @return a {@link RangeQueryScorer} instance
          */
-        protected Scorer createScorer(IndexReader reader) {
+        protected Scorer createScorer(IndexReader reader, boolean scoreDocsInOrder,
+                boolean topScorer) {
             return new RangeQueryScorer(searcher.getSimilarity(), reader, cache);
         }
 
@@ -355,44 +358,42 @@ public class RangeQuery extends Query im
             hits = result;
         }
 
-        /**
-         * {@inheritDoc}
-         */
-        public boolean next() throws IOException {
+        @Override
+        public int nextDoc() throws IOException {
+            if (nextDoc == NO_MORE_DOCS) {
+                return nextDoc;
+            }
+
             calculateHits();
             nextDoc = hits.nextSetBit(nextDoc + 1);
-            return nextDoc > -1;
+            if (nextDoc < 0) {
+                nextDoc = NO_MORE_DOCS;
+            }
+            return nextDoc;
         }
 
-        /**
-         * {@inheritDoc}
-         */
-        public int doc() {
+        @Override
+        public int docID() {
             return nextDoc;
         }
 
-        /**
-         * {@inheritDoc}
-         */
+        @Override
         public float score() {
             return 1.0f;
         }
 
-        /**
-         * {@inheritDoc}
-         */
-        public boolean skipTo(int target) throws IOException {
+        @Override
+        public int advance(int target) throws IOException {
+            if (nextDoc == NO_MORE_DOCS) {
+                return nextDoc;
+            }
+
             calculateHits();
             nextDoc = hits.nextSetBit(target);
-            return nextDoc > -1;
-        }
-
-        /**
-         * Returns an empty Explanation object.
-         * @return an empty Explanation object.
-         */
-        public Explanation explain(int doc) {
-            return new Explanation();
+            if (nextDoc < 0) {
+                nextDoc = NO_MORE_DOCS;
+            }
+            return nextDoc;
         }
 
         /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ReadOnlyIndexReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ReadOnlyIndexReader.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ReadOnlyIndexReader.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ReadOnlyIndexReader.java Thu Jan 27 09:33:13 2011
@@ -16,13 +16,14 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import java.io.IOException;
-import java.util.BitSet;
-
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermDocs;
 import org.apache.lucene.index.TermPositions;
 
+import java.io.IOException;
+import java.util.BitSet;
+import java.util.Map;
+
 /**
  * Overwrites the methods that would modify the index and throws an
  * {@link UnsupportedOperationException} in each of those methods. A
@@ -175,7 +176,8 @@ class ReadOnlyIndexReader extends RefCou
     /**
      * @exception UnsupportedOperationException always
      */
-    protected final void doCommit() {
+    @Override
+    protected void doCommit(Map commitUserData) throws IOException { 
         throw new UnsupportedOperationException("IndexReader is read-only");
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RefCountingIndexReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RefCountingIndexReader.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RefCountingIndexReader.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/RefCountingIndexReader.java Thu Jan 27 09:33:13 2011
@@ -48,7 +48,7 @@ public class RefCountingIndexReader
     /**
      * @return the current reference count value.
      */
-    synchronized int getRefCount() {
+    public synchronized int getRefCount() {
         return refCount;
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ScoreNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ScoreNode.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ScoreNode.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ScoreNode.java Thu Jan 27 09:33:13 2011
@@ -20,7 +20,6 @@ import java.io.IOException;
 
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermDocs;
 
 /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java Thu Jan 27 09:33:13 2011
@@ -16,27 +16,6 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.query.InvalidQueryException;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
 import org.apache.jackrabbit.core.HierarchyManager;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.fs.FileSystem;
@@ -50,6 +29,7 @@ import org.apache.jackrabbit.core.query.
 import org.apache.jackrabbit.core.query.QueryHandlerContext;
 import org.apache.jackrabbit.core.query.lucene.directory.DirectoryManager;
 import org.apache.jackrabbit.core.query.lucene.directory.FSDirectoryManager;
+import org.apache.jackrabbit.core.query.lucene.hits.AbstractHitCollector;
 import org.apache.jackrabbit.core.session.SessionContext;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.ItemStateManager;
@@ -63,20 +43,21 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.query.DefaultQueryNodeFactory;
 import org.apache.jackrabbit.spi.commons.query.qom.OrderingImpl;
 import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.Token;
+import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.tokenattributes.PayloadAttribute;
+import org.apache.lucene.analysis.tokenattributes.TermAttribute;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.Fieldable;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.MultiReader;
+import org.apache.lucene.index.Payload;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermDocs;
-import org.apache.lucene.search.HitCollector;
 import org.apache.lucene.search.IndexSearcher;
 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;
@@ -85,6 +66,26 @@ import org.slf4j.LoggerFactory;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
+import javax.jcr.RepositoryException;
+import javax.jcr.query.InvalidQueryException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 /**
  * Implements a {@link org.apache.jackrabbit.core.query.QueryHandler} using
  * Lucene.
@@ -440,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
@@ -507,7 +508,7 @@ public class SearchIndex extends Abstrac
             }
         }
 
-        scs = new SharedFieldSortComparator(
+        scs = new SharedFieldComparatorSource(
                 FieldNames.PROPERTIES, context.getItemStateManager(),
                 context.getHierarchyManager(), nsMappings);
         indexingConfig = createIndexingConfiguration(nsMappings);
@@ -691,7 +692,8 @@ public class SearchIndex extends Abstrac
             try {
                 Query q = new TermQuery(new Term(
                         FieldNames.WEAK_REFS, id.toString()));
-                searcher.search(q, new HitCollector() {
+                searcher.search(q, new AbstractHitCollector() {
+                    @Override
                     public void collect(int doc, float score) {
                         docs.add(doc);
                     }
@@ -1096,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;
     }
 
@@ -1376,11 +1378,17 @@ public class SearchIndex extends Abstrac
                             try {
                                 // find the right fields to transfer
                                 Fieldable[] fields = aDoc.getFieldables(FieldNames.PROPERTIES);
-                                Token t = new Token();
                                 for (Fieldable field : fields) {
+
                                     // assume properties fields use SingleTokenStream
-                                    t = field.tokenStreamValue().next(t);
-                                    String value = new String(t.termBuffer(), 0, t.termLength());
+                                    TokenStream tokenStream = field.tokenStreamValue();
+                                    TermAttribute termAttribute = tokenStream.addAttribute(TermAttribute.class);
+                                    PayloadAttribute payloadAttribute = tokenStream.addAttribute(PayloadAttribute.class);
+                                    tokenStream.incrementToken();
+                                    tokenStream.end();
+                                    tokenStream.close();
+
+                                    String value = new String(termAttribute.termBuffer(), 0, termAttribute.termLength());
                                     if (value.startsWith(namePrefix)) {
                                         // extract value
                                         value = value.substring(namePrefix.length());
@@ -1388,9 +1396,11 @@ public class SearchIndex extends Abstrac
                                         Path p = getRelativePath(state, propState);
                                         String path = getNamespaceMappings().translatePath(p);
                                         value = FieldNames.createNamedValue(path, value);
-                                        t.setTermBuffer(value);
-                                        doc.add(new Field(field.name(), new SingletonTokenStream(t)));
-                                        doc.add(new Field(FieldNames.AGGREGATED_NODE_UUID, parent.getNodeId().toString(), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
+                                        termAttribute.setTermBuffer(value);
+                                        doc.add(new Field(field.name(),
+                                                new SingletonTokenStream(value, (Payload) payloadAttribute.getPayload().clone())));
+                                        doc.add(new Field(FieldNames.AGGREGATED_NODE_UUID,
+                                                parent.getNodeId().toString(), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
                                     }
                                 }
                             } finally {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SharedFieldCache.java Thu Jan 27 09:33:13 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;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SimilarityQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SimilarityQuery.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SimilarityQuery.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SimilarityQuery.java Thu Jan 27 09:33:13 2011
@@ -16,19 +16,19 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.BooleanQuery;
+import java.io.IOException;
+
+import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.Term;
 import org.apache.lucene.index.TermDocs;
-import org.apache.lucene.analysis.Analyzer;
-
-import java.io.IOException;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.Query;
 
 /**
  * <code>SimilarityQuery</code> implements a query that returns similar nodes
  * for a given node UUID.
  */
+@SuppressWarnings("serial")
 public class SimilarityQuery extends Query {
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SimpleExcerptProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SimpleExcerptProvider.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SimpleExcerptProvider.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SimpleExcerptProvider.java Thu Jan 27 09:33:13 2011
@@ -60,9 +60,9 @@ public class SimpleExcerptProvider imple
         try {
             NodeState nodeState = (NodeState) ism.getItemState(id);
             String separator = "";
-            Iterator it = nodeState.getPropertyNames().iterator();
+            Iterator<Name> it = nodeState.getPropertyNames().iterator();
             while (it.hasNext() && text.length() < maxFragmentSize) {
-                PropertyId propId = new PropertyId(id, (Name) it.next());
+                PropertyId propId = new PropertyId(id, it.next());
                 PropertyState propState = (PropertyState) ism.getItemState(propId);
                 if (propState.getType() == PropertyType.STRING) {
                     text.append(separator);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SingletonTokenStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SingletonTokenStream.java?rev=1064058&r1=1064057&r2=1064058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SingletonTokenStream.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SingletonTokenStream.java Thu Jan 27 09:33:13 2011
@@ -16,12 +16,13 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import java.io.IOException;
-
-import org.apache.lucene.analysis.Token;
 import org.apache.lucene.analysis.TokenStream;
+import org.apache.lucene.analysis.tokenattributes.PayloadAttribute;
+import org.apache.lucene.analysis.tokenattributes.TermAttribute;
 import org.apache.lucene.index.Payload;
 
+import java.io.IOException;
+
 /**
  * <code>SingletonTokenStream</code> implements a token stream that wraps a
  * single value with a given property type. The property type is stored as a
@@ -40,40 +41,50 @@ public final class SingletonTokenStream 
     private final Payload payload;
 
     /**
-     * Creates a new SingleTokenStream with the given value and a property
-     * <code>type</code>.
+     * The term attribute of the current token
+     */
+    private TermAttribute termAttribute;
+
+    /**
+     * The payload attribute of the current token
+     */
+    private PayloadAttribute payloadAttribute;
+
+    /**
+     * Creates a new SingleTokenStream with the given value and payload.
      *
      * @param value the string value that will be returned with the token.
-     * @param type the JCR property type.
+     * @param payload the payload that will be attached to this token
      */
-    public SingletonTokenStream(String value, int type) {
+    public SingletonTokenStream(String value, Payload payload) {
         this.value = value;
-        this.payload = new Payload(new PropertyMetaData(type).toByteArray());
+        this.payload = payload;
+        termAttribute = (TermAttribute) addAttribute(TermAttribute.class);
+        payloadAttribute = (PayloadAttribute) addAttribute(PayloadAttribute.class);
     }
 
     /**
-     * Creates a new SingleTokenStream with the given token.
+     * Creates a new SingleTokenStream with the given value and a property
+     * <code>type</code>.
      *
-     * @param t the token.
+     * @param value the string value that will be returned with the token.
+     * @param type the JCR property type.
      */
-    public SingletonTokenStream(Token t) {
-        this.value = t.term();
-        this.payload = t.getPayload();
+    public SingletonTokenStream(String value, int type) {
+        this(value, new Payload(new PropertyMetaData(type).toByteArray()));
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public Token next(Token reusableToken) throws IOException {
+    @Override
+    public boolean incrementToken() throws IOException {
         if (value == null) {
-            return null;
+            return false;
         }
-        reusableToken.clear();
-        reusableToken.setTermBuffer(value);
-        reusableToken.setPayload(payload);
-        reusableToken.setStartOffset(0);
-        reusableToken.setEndOffset(value.length());
+
+        clearAttributes();
+        termAttribute.setTermBuffer(value);
+        payloadAttribute.setPayload(payload);
+
         value = null;
-        return reusableToken;
+        return true;
     }
 }



Mime
View raw message