| 1 |
|
package org.apache.lucene.search; |
| 2 |
|
|
| 3 |
|
import junit.framework.TestCase; |
| 4 |
|
|
| 5 |
|
import java.util.Random; |
| 6 |
|
import java.util.BitSet; |
| 7 |
|
import java.util.Set; |
| 8 |
|
import java.io.IOException; |
| 9 |
|
|
| 10 |
|
import org.apache.lucene.index.IndexReader; |
| 11 |
|
import org.apache.lucene.index.IndexWriter; |
| 12 |
|
import org.apache.lucene.index.Term; |
| 13 |
|
import org.apache.lucene.store.RAMDirectory; |
| 14 |
|
import org.apache.lucene.store.Directory; |
| 15 |
|
import org.apache.lucene.analysis.WhitespaceAnalyzer; |
| 16 |
|
import org.apache.lucene.document.Document; |
| 17 |
|
import org.apache.lucene.document.Field; |
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
@author |
| 37 |
|
@version |
| 38 |
|
|
|
|
|
| 47.2% |
Uncovered Elements: 94 (178) |
Complexity: 35 |
Complexity Density: 0.3 |
|
| 39 |
|
public class TestScorerPerf extends TestCase { |
| 40 |
|
Random r = new Random(0); |
| 41 |
|
boolean validate = true; |
| 42 |
|
|
| 43 |
|
BitSet[] sets; |
| 44 |
|
IndexSearcher s; |
| 45 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 46 |
1
|
public void createDummySearcher() throws Exception {... |
| 47 |
|
|
| 48 |
|
|
| 49 |
1
|
RAMDirectory rd = new RAMDirectory(); |
| 50 |
1
|
IndexWriter iw = new IndexWriter(rd,new WhitespaceAnalyzer(), true); |
| 51 |
1
|
iw.close(); |
| 52 |
1
|
s = new IndexSearcher(rd); |
| 53 |
|
} |
| 54 |
|
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 5 |
Complexity Density: 0.38 |
|
| 55 |
0
|
public void createRandomTerms(int nDocs, int nTerms, double power, Directory dir) throws Exception {... |
| 56 |
0
|
int[] freq = new int[nTerms]; |
| 57 |
0
|
for (int i=0; i<nTerms; i++) { |
| 58 |
0
|
int f = (nTerms+1)-i; |
| 59 |
0
|
freq[i] = (int)Math.ceil(Math.pow(f,power)); |
| 60 |
|
} |
| 61 |
|
|
| 62 |
0
|
IndexWriter iw = new IndexWriter(dir,new WhitespaceAnalyzer(), true); |
| 63 |
0
|
iw.setMaxBufferedDocs(123); |
| 64 |
0
|
for (int i=0; i<nDocs; i++) { |
| 65 |
0
|
Document d = new Document(); |
| 66 |
0
|
for (int j=0; j<nTerms; j++) { |
| 67 |
0
|
if (r.nextInt(freq[j]) == 0) { |
| 68 |
0
|
d.add(new Field("f", Character.toString((char)j), Field.Store.NO, Field.Index.UN_TOKENIZED)); |
| 69 |
|
} |
| 70 |
|
} |
| 71 |
0
|
iw.addDocument(d); |
| 72 |
|
} |
| 73 |
0
|
iw.close(); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 77 |
1000
|
public BitSet randBitSet(int sz, int numBitsToSet) {... |
| 78 |
1000
|
BitSet set = new BitSet(sz); |
| 79 |
5614
|
for (int i=0; i<numBitsToSet; i++) { |
| 80 |
4614
|
set.set(r.nextInt(sz)); |
| 81 |
|
} |
| 82 |
1000
|
return set; |
| 83 |
|
} |
| 84 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 85 |
1
|
public BitSet[] randBitSets(int numSets, int setSize) {... |
| 86 |
1
|
BitSet[] sets = new BitSet[numSets]; |
| 87 |
1001
|
for (int i=0; i<sets.length; i++) { |
| 88 |
1000
|
sets[i] = randBitSet(setSize, r.nextInt(setSize)); |
| 89 |
|
} |
| 90 |
1
|
return sets; |
| 91 |
|
} |
| 92 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 93 |
|
public static class BitSetFilter extends Filter { |
| 94 |
|
public BitSet set; |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 95 |
97500
|
public BitSetFilter(BitSet set) {... |
| 96 |
97500
|
this.set = set; |
| 97 |
|
} |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 98 |
97500
|
public BitSet bits(IndexReader reader) throws IOException {... |
| 99 |
97500
|
return set; |
| 100 |
|
} |
| 101 |
|
} |
| 102 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 103 |
|
public static class CountingHitCollector extends HitCollector { |
| 104 |
|
int count=0; |
| 105 |
|
int sum=0; |
| 106 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 107 |
5276
|
public void collect(int doc, float score) {... |
| 108 |
5276
|
count++; |
| 109 |
5276
|
sum += doc; |
| 110 |
|
} |
| 111 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 112 |
20000
|
public int getCount() { return count; }... |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 113 |
20000
|
public int getSum() { return sum; }... |
| 114 |
|
} |
| 115 |
|
|
| 116 |
|
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 117 |
|
public static class MatchingHitCollector extends CountingHitCollector { |
| 118 |
|
BitSet answer; |
| 119 |
|
int pos=-1; |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 120 |
20000
|
public MatchingHitCollector(BitSet answer) {... |
| 121 |
20000
|
this.answer = answer; |
| 122 |
|
} |
| 123 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 124 |
|