Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../../img/srcFileCovDistChart8.png 55% of files have more coverage
91   257   41   4.79
46   150   0.45   9.5
19     2.16  
2    
 
  DisjunctionMaxQuery       Line # 42 55 26 66.3% 0.6631579
  DisjunctionMaxQuery.DisjunctionMaxWeight       Line # 90 36 15 86.9% 0.86885244
 
  (32)
 
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   
21    import java.io.IOException;
22    import java.util.ArrayList;
23    import java.util.Iterator;
24    import java.util.Collection;
25    import java.util.Set;
26   
27    /**
28    * A query that generates the union of documents produced by its subqueries, and that scores each document with the maximum
29    * score for that document as produced by any subquery, plus a tie breaking increment for any additional matching subqueries.
30    * This is useful when searching for a word in multiple fields with different boost factors (so that the fields cannot be
31    * combined equivalently into a single search field). We want the primary score to be the one associated with the highest boost,
32    * not the sum of the field scores (as BooleanQuery would give).
33    * If the query is "albino elephant" this ensures that "albino" matching one field and "elephant" matching
34    * another gets a higher score than "albino" matching both fields.
35    * To get this result, use both BooleanQuery and DisjunctionMaxQuery: for each term a DisjunctionMaxQuery searches for it in
36    * each field, while the set of these DisjunctionMaxQuery's is combined into a BooleanQuery.
37    * The tie breaker capability allows results that include the same term in multiple fields to be judged better than results that
38    * include this term in only the best of those multiple fields, without confusing this with the better case of two different terms
39    * in the multiple fields.
40    * @author Chuck Williams
41    */
 
42    public class DisjunctionMaxQuery extends Query {
43   
44    /* The subqueries */
45    private ArrayList disjuncts = new ArrayList();
46   
47    /* Multiple of the non-max disjunct scores added into our final score. Non-zero values support tie-breaking. */
48    private float tieBreakerMultiplier = 0.0f;
49   
50    /** Creates a new empty DisjunctionMaxQuery. Use add() to add the subqueries.
51    * @param tieBreakerMultiplier this score of each non-maximum disjunct for a document is multiplied by this weight
52    * and added into the final score. If non-zero, the value should be small, on the order of 0.1, which says that
53    * 10 occurrences of word in a lower-scored field that is also in a higher scored field is just as good as a unique
54    * word in the lower scored field (i.e., one that is not in any higher scored field.
55    */
 
56  40 toggle public DisjunctionMaxQuery(float tieBreakerMultiplier) {
57  40 this.tieBreakerMultiplier = tieBreakerMultiplier;
58    }
59   
60    /**
61    * Creates a new DisjunctionMaxQuery
62    * @param disjuncts a Collection<Query> of all the disjuncts to add
63    * @param tieBreakerMultiplier the weight to give to each matching non-maximum disjunct
64    */
 
65  0 toggle public DisjunctionMaxQuery(Collection disjuncts, float tieBreakerMultiplier) {
66  0 this.tieBreakerMultiplier = tieBreakerMultiplier;
67  0 add(disjuncts);
68    }
69   
70    /** Add a subquery to this disjunction
71    * @param query the disjunct added
72    */