Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
133   369   57   4.93
54   222   0.43   27
27     2.11  
1    
 
  FieldSortedHitQueue       Line # 41 133 57 95.3% 0.95327103
 
  (24)
 
1    package org.apache.lucene.search;
2   
3    /**
4    * Copyright 2004 The Apache Software Foundation
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing, software
13    * distributed under the License is distributed on an "AS IS" BASIS,
14    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    * See the License for the specific language governing permissions and
16    * limitations under the License.
17    */
18   
19    import org.apache.lucene.index.IndexReader;
20    import org.apache.lucene.util.PriorityQueue;
21   
22    import java.io.IOException;
23    import java.util.WeakHashMap;
24    import java.util.HashMap;
25    import java.util.Map;
26    import java.util.Locale;
27    import java.text.Collator;
28   
29    /**
30    * Expert: A hit queue for sorting by hits by terms in more than one field.
31    * Uses <code>FieldCache.DEFAULT</code> for maintaining internal term lookup tables.
32    *
33    * <p>Created: Dec 8, 2003 12:56:03 PM
34    *
35    * @author Tim Jones (Nacimiento Software)
36    * @since lucene 1.4
37    * @version $Id: FieldSortedHitQueue.java 433049 2006-08-20 21:17:59Z hossman $
38    * @see Searcher#search(Query,Filter,int,Sort)
39    * @see FieldCache
40    */
 
41    public class FieldSortedHitQueue
42    extends PriorityQueue {
43   
44    /**
45    * Creates a hit queue sorted by the given list of fields.
46    * @param reader Index to use.
47    * @param fields Fieldable names, in priority order (highest priority first). Cannot be <code>null</code> or empty.
48    * @param size The number of hits to retain. Must be greater than zero.
49    * @throws IOException
50    */
 
51  2281 toggle public FieldSortedHitQueue (IndexReader reader, SortField[] fields, int size)
52    throws IOException {
53  2281 final int n = fields.length;
54  2281 comparators = new ScoreDocComparator[n];
55  2281 this.fields = new SortField[n];
56  4790 for (int i=0; i<n; ++i) {
57  2509 String fieldname = fields[i].getField();
58  2509 comparators[i] = getCachedComparator (reader, fieldname, fields[i].getType(), fields[i].getLocale(), fields[i].getFactory());
59   
60  2509 if (comparators[i].sortType() == SortField.STRING) {
61  92 this.fields[i] = new SortField (fieldname, fields[i].getLocale(), fields[i].getReverse());
62    } else {
63  2417 this.fields[i] = new SortField (fieldname, comparators[i].sortType(), fields[i].getReverse());
64    }
65    }
66  2281 initialize (size);
67    }
68   
69   
70    /** Stores a comparator corresponding to each field being sorted by */
71    protected ScoreDocComparator[] comparators;
72   
73    /** Stores the sort criteria being used. */
74    protected SortField[] fields;
75   
76    /** Stores the maximum score value encountered, needed for normalizing. */
77    protected float maxscore = Float.NEGATIVE_INFINITY;
78   
79    /** returns the maximum score encountered by elements inserted via insert()
80    */