| 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 java.io.IOException; |
| 20 |
|
|
| 21 |
|
import org.apache.lucene.index.Term; |
| 22 |
|
import org.apache.lucene.util.PriorityQueue; |
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
@link |
| 27 |
|
@link |
| 28 |
|
|
|
|
|
| 80% |
Uncovered Elements: 15 (75) |
Complexity: 18 |
Complexity Density: 0.38 |
|
| 29 |
|
public class ParallelMultiSearcher extends MultiSearcher { |
| 30 |
|
|
| 31 |
|
private Searchable[] searchables; |
| 32 |
|
private int[] starts; |
| 33 |
|
|
| 34 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 35 |
6
|
public ParallelMultiSearcher(Searchable[] searchables) throws IOException {... |
| 36 |
6
|
super(searchables); |
| 37 |
6
|
this.searchables=searchables; |
| 38 |
6
|
this.starts=getStarts(); |
| 39 |
|
} |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 44 |
26
|
public int docFreq(Term term) throws IOException {... |
| 45 |
26
|
return super.docFreq(term); |
| 46 |
|
} |
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
|
|
|
| 86.2% |
Uncovered Elements: 4 (29) |
Complexity: 6 |
Complexity Density: 0.32 |
|
| 53 |
4
|
public TopDocs search(Weight weight, Filter filter, int nDocs)... |
| 54 |
|
throws IOException { |
| 55 |
4
|
HitQueue hq = new HitQueue(nDocs); |
| 56 |
4
|
int totalHits = 0; |
| 57 |
4
|
MultiSearcherThread[] msta = |
| 58 |
|
new MultiSearcherThread[searchables.length]; |
| 59 |
12
|
for (int i = 0; i < searchables.length; i++) { |
| 60 |
|
|
| 61 |
8
|
msta[i] = |
| 62 |
|
new MultiSearcherThread( |
| 63 |
|
searchables[i], |
| 64 |
|
weight, |
| 65 |
|
filter, |
| 66 |
|
nDocs, |
| 67 |
|
hq, |
| 68 |
|
i, |
| 69 |
|
starts, |
| 70 |
|
"MultiSearcher thread #" + (i + 1)); |
| 71 |
8
|
msta[i].start(); |
| 72 |
|
} |
| 73 |
|
|
| 74 |
12
|
for (int i = 0; i < searchables.length; i++) { |
| 75 |
8
|
try { |
| 76 |
8
|
msta[i].join(); |
| 77 |
|
} catch (InterruptedException ie) { |
| 78 |
0
|
; |
| 79 |
|
} |
| 80 |
8
|
IOException ioe = msta[i].getIOException(); |
| 81 |
8
|
if (ioe == null) { |
| 82 |
8
|
totalHits += msta[i].hits(); |
| 83 |
|
} else { |
| 84 |
|
|
| 85 |
0
|
throw ioe; |
| 86 |
|
} |
| 87 |
|
} |
| 88 |
|
|
| 89 |
4
|
ScoreDoc[] scoreDocs = new ScoreDoc[hq.size()]; |
| 90 |
16
|
for (int i = hq.size() - 1; i >= 0; i--) |
| 91 |
12
|
scoreDocs[i] = (ScoreDoc) hq.pop(); |
| 92 |
|
|
| 93 |
4
|
float maxScore = (totalHits==0) ? Float.NEGATIVE_INFINITY : scoreDocs[0].score; |
| 94 |
|
|
| 95 |
4
|
return new TopDocs(totalHits, scoreDocs, maxScore); |
| 96 |
|
} |
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
|
|
|
| 89.3% |
Uncovered Elements: 3 (28) |
Complexity: 6 |
Complexity Density: 0.3 |
|
| 103 |
22
|
public TopFieldDocs search(Weight weight, Filter filter, int nDocs, Sort sort)... |
| 104 |
|
throws IOException { |
| 105 |
|
|
| 106 |
22
|
FieldDocSortedHitQueue hq = new FieldDocSortedHitQueue (null, nDocs); |
| 107 |
22
|
int totalHits = 0; |
| 108 |
22
|
MultiSearcherThread[] msta = new MultiSearcherThread[searchables.length]; |
| 109 |
64
|
for (int i = 0; i < searchables.length; i++) { |
| 110 |
|
|
| 111 |
42
|
msta[i] = |
| 112 |
|
new MultiSearcherThread( |
| 113 |
|
searchables[i], |
| 114 |
|
weight, |
| 115 |
|
filter, |
| 116 |
|
nDocs, |
| 117 |
|
hq, |
| 118 |
|
sort, |
| 119 |
|
i, |
| 120 |
|
starts, |
| 121 |
|
"MultiSearcher thread #" + (i + 1)); |
| 122 |
42
|
msta[i].start(); |
| 123 |
|
} |
| 124 |
|
|
| 125 |
22
|
float maxScore=Float.NEGATIVE_INFINITY; |
| 126 |
|
|
| 127 |
64
|
for (int i = 0; i < searchables.length; i++) { |
| 128 |
42
|
try { |
| 129 |
42
|
msta[i].join(); |
| 130 |
|
} catch (InterruptedException ie) { |
| 131 |
0
|
; |
| 132 |
|
} |
| 133 |
42
|
IOException ioe = msta[i].getIOException(); |
| 134 |
42
|
if (ioe == null) { |
| 135 |
42
|
totalHits += msta[i].hits(); |
| 136 |
42
|
maxScore=Math.max(maxScore, msta[i].getMaxScore()); |
| 137 |
|
} else { |
| 138 |
|
|
| 139 |
0
|
throw ioe; |
| 140 |
|
} |
| 141 |
|
} |
| 142 |
|
|
| 143 |
22
|
ScoreDoc[] scoreDocs = new ScoreDoc[hq.size()]; |
| 144 |
187
|
for (int i = hq.size() - 1; i >= 0; i--) |
| 145 |
165
|
scoreDocs[i] = (ScoreDoc) hq.pop(); |
| 146 |
|
|
| 147 |
22
|
return new TopFieldDocs(totalHits, scoreDocs, hq.getFields(), maxScore); |
| 148 |
|
} |
| 149 |
|
|
| 150 |
|
|
| 151 |
|
|
| 152 |
|
@link |
| 153 |
|
|
| 154 |
|
|
| 155 |
|
|
| 156 |
|
@link |
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
|
@param |
| 161 |
|
@param |
| 162 |
|
@param |
| 163 |
|
|
| 164 |
|
|
| 165 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 166 |
0
|
![Method Statistics]() |