| 1 |
|
package org.apache.lucene.search; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
import org.apache.lucene.index.IndexReader; |
| 20 |
|
|
| 21 |
|
import java.io.IOException; |
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
@author |
| 34 |
|
@version |
| 35 |
|
|
| 36 |
|
|
|
|
|
| 52.3% |
Uncovered Elements: 51 (107) |
Complexity: 23 |
Complexity Density: 0.45 |
|
| 37 |
|
public class ConstantScoreRangeQuery extends Query |
| 38 |
|
{ |
| 39 |
|
private final String fieldName; |
| 40 |
|
private final String lowerVal; |
| 41 |
|
private final String upperVal; |
| 42 |
|
private final boolean includeLower; |
| 43 |
|
private final boolean includeUpper; |
| 44 |
|
|
| 45 |
|
|
|
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 5 |
Complexity Density: 0.45 |
|
| 46 |
45
|
public ConstantScoreRangeQuery(String fieldName, String lowerVal, String upperVal, boolean includeLower, boolean includeUpper)... |
| 47 |
|
{ |
| 48 |
|
|
| 49 |
|
|
| 50 |
45
|
if (lowerVal==null) { |
| 51 |
6
|
includeLower=true; |
| 52 |
39
|
} else if (includeLower && lowerVal.equals("")) { |
| 53 |
0
|
lowerVal=null; |
| 54 |
|
} |
| 55 |
45
|
if (upperVal==null) { |
| 56 |
6
|
includeUpper=true; |
| 57 |
|
} |
| 58 |
|
|
| 59 |
|
|
| 60 |
45
|
this.fieldName = fieldName.intern(); |
| 61 |
45
|
this.lowerVal = lowerVal; |
| 62 |
45
|
this.upperVal = upperVal; |
| 63 |
45
|
this.includeLower = includeLower; |
| 64 |
45
|
this.includeUpper = includeUpper; |
| 65 |
|
} |
| 66 |
|
|
| 67 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 68 |
0
|
public String getField() { return fieldName; }... |
| 69 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 70 |
0
|
public String getLowerVal() { return lowerVal; }... |
| 71 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 72 |
0
|
public String getUpperVal() { return upperVal; }... |
| 73 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 74 |
0
|
public boolean includesLower() { return includeLower; }... |
| 75 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 76 |
0
|
public boolean includesUpper() { return includeUpper; }... |
| 77 |
|
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 78 |
41
|
public Query rewrite(IndexReader reader) throws IOException {... |
| 79 |
|
|
| 80 |
41
|
RangeFilter rangeFilt = new RangeFilter(fieldName, |
| 81 |
41
|
lowerVal!=null?lowerVal:"", |
| 82 |
41
|
upperVal, lowerVal==""?false:includeLower, upperVal==null?false:includeUpper); |
| 83 |
41
|
Query q = new ConstantScoreQuery(rangeFilt); |
| 84 |
41
|
q.setBoost(getBoost()); |
| 85 |
41
|
return q; |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 3 |
Complexity Density: 0.23 |
|
| 89 |
0
|
public String toString(String field)... |
| 90 |
|
{ |
| 91 |
0
|
StringBuffer buffer = new StringBuffer(); |
| 92 |
0
|
if (!getField().equals(field)) |
| 93 |
|
{ |
| 94 |
0
|
buffer.append(getField()); |
| 95 |
0
|
buffer.append(":"); |
| 96 |
|
} |
| 97 |
0
|
buffer.append(includeLower ? '[' : '{'); |
| 98 |
0
|
buffer.append(lowerVal != null ? lowerVal : "*"); |
| 99 |
0
|
buffer.append(" TO "); |
| 100 |
0
|
buffer.append(upperVal != null ? upperVal : "*"); |
| 101 |
0
|
buffer.append(includeUpper ? ']' : '}'); |
| 102 |
0
|
if (getBoost() != 1.0f) |
| 103 |
|
{ |
| 104 |
0
|
buffer.append("^"); |
| 105 |
0
|
buffer.append(Float.toString(getBoost())); |
| 106 |
|
} |
| 107 |
0
|
return buffer.toString(); |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
|
|
|
|
| 69.2% |
Uncovered Elements: 8 (26) |
Complexity: 8 |
Complexity Density: 0.67 |
|
| 111 |
10
|
public boolean equals(Object o) {... |
| 112 |
0
|
if (this == o) return true; |
| 113 |
10
|
if (!(o instanceof ConstantScoreRangeQuery)) return false; |
| 114 |
8
|
ConstantScoreRangeQuery other = (ConstantScoreRangeQuery) o; |
| 115 |
|
|
| 116 |
8
|
if (this.fieldName != other.fieldName |
| 117 |
|
|| this.includeLower != other.includeLower |
| 118 |
|
|| this.includeUpper != other.includeUpper |
| 119 |
0
|
) { return false; } |
| 120 |
8
|
if (this.lowerVal != null ? !this.lowerVal.equals(other.lowerVal) : other.lowerVal != null) return false; |
| 121 |
0
|
if (this.upperVal != null ? !this.upperVal.equals(other.upperVal) : other.upperVal != null) return false; |
| 122 |
6
|
return this.getBoost() == other.getBoost(); |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
|
|
|
|
| 71.4% |
Uncovered Elements: 4 (14) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 126 |
12
|
public int hashCode() {... |
| 127 |
12
|
int h = Float.floatToIntBits(getBoost()) ^ fieldName.hashCode(); |
| 128 |
|
|
| 129 |
12
|
h ^= lowerVal != null ? lowerVal.hashCode() : 0x965a965a; |
| 130 |
|
|
| 131 |
|
|
| 132 |
12
|
h ^= (h << 17) | (h >>> 16); |
| 133 |
12
|
h ^= (upperVal != null ? (upperVal.hashCode()) : 0x5a695a69); |
| 134 |
12
|
h ^= (includeLower ? 0x665599aa : 0) |
| 135 |
12
|
^ (includeUpper ? 0x99aa5566 : 0); |
| 136 |
12
|
return h; |
| 137 |
|
} |
| 138 |
|
} |