| 1 |
|
package org.apache.lucene.index; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
import junit.framework.TestCase; |
| 21 |
|
import org.apache.lucene.store.Directory; |
| 22 |
|
import org.apache.lucene.store.RAMDirectory; |
| 23 |
|
import org.apache.lucene.analysis.Analyzer; |
| 24 |
|
import org.apache.lucene.analysis.TokenStream; |
| 25 |
|
import org.apache.lucene.analysis.Token; |
| 26 |
|
import org.apache.lucene.document.Document; |
| 27 |
|
import org.apache.lucene.document.Field; |
| 28 |
|
|
| 29 |
|
import java.io.Reader; |
| 30 |
|
import java.io.IOException; |
| 31 |
|
import java.util.Random; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
@author |
| 35 |
|
@version |
| 36 |
|
|
| 37 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 1 |
|
| 38 |
|
class RepeatingTokenStream extends TokenStream { |
| 39 |
|
public int num; |
| 40 |
|
Token t; |
| 41 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 42 |
0
|
public RepeatingTokenStream(String val) {... |
| 43 |
0
|
t = new Token(val,0,val.length()); |
| 44 |
|
} |
| 45 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 1 |
|
| 46 |
0
|
public Token next() throws IOException {... |
| 47 |
0
|
return --num<0 ? null : t; |
| 48 |
|
} |
| 49 |
|
} |
| 50 |
|
|
| 51 |
|
|
|
|
|
| 2.2% |
Uncovered Elements: 44 (45) |
Complexity: 8 |
Complexity Density: 0.24 |
|
| 52 |
|
public class TestTermdocPerf extends TestCase { |
| 53 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 2 |
Complexity Density: 0.17 |
|
| 54 |
0
|
void addDocs(Directory dir, final int ndocs, String field, final String val, final int maxTF, final float percentDocs) throws IOException {... |
| 55 |
0
|
final Random random = new Random(0); |
| 56 |
0
|
final RepeatingTokenStream ts = new RepeatingTokenStream(val); |
| 57 |
|
|
| 58 |
0
|
Analyzer analyzer = new Analyzer() { |
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 59 |
0
|
public TokenStream tokenStream(String fieldName, Reader reader) {... |
| 60 |
0
|
if (random.nextFloat() < percentDocs) ts.num = random.nextInt(maxTF)+1; |
| 61 |
0
|
else ts.num=0; |
| 62 |
0
|
return ts; |
| 63 |
|
} |
| 64 |
|
}; |
| 65 |
|
|
| 66 |
0
|
Document doc = new Document(); |
| 67 |
0
|
doc.add(new Field(field,val, Field.Store.NO, Field.Index.NO_NORMS)); |
| 68 |
0
|
IndexWriter writer = new IndexWriter(dir, analyzer, true); |
| 69 |
0
|
writer.setMaxBufferedDocs(100); |
| 70 |
0
|
writer.setMergeFactor(100); |
| 71 |
|
|
| 72 |
0
|
for (int i=0; i<ndocs; i++) { |
| 73 |
0
|
writer.addDocument(doc); |
| 74 |
|
} |
| 75 |
|
|
| 76 |
0
|
writer.optimize(); |
| 77 |
0
|
writer.close(); |
| 78 |
|
} |
| 79 |
|
|
| 80 |
|
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 3 |
Complexity Density: 0.18 |
|
| 81 |
0
|
public int doTest(int iter, int ndocs, int maxTF, float percentDocs) throws IOException {... |
| 82 |
0
|
Directory dir = new RAMDirectory(); |
| 83 |
|
|
| 84 |
0
|
long start = System.currentTimeMillis(); |
| 85 |
0
|
addDocs(dir, ndocs, "foo", "val", maxTF, percentDocs); |
| 86 |
0
|
long end = System.currentTimeMillis(); |
| 87 |
0
|
System.out.println("milliseconds for creation of " + ndocs + " docs = " + (end-start)); |
| 88 |
|
|
| 89 |
0
|
IndexReader reader = IndexReader.open(dir); |
| 90 |
0
|
TermEnum tenum = reader.terms(new Term("foo","val")); |
| 91 |
0
|
TermDocs tdocs = reader.termDocs(); |
| 92 |
|
|
| 93 |
0
|
start = System.currentTimeMillis(); |
| 94 |
|
|
| 95 |
0
|
int ret=0; |
| 96 |
0
|
for (int i=0; i<iter; i++) { |
| 97 |
0
|
tdocs.seek(tenum); |
| 98 |
0
|
while (tdocs.next()) { |
| 99 |
0
|
ret += tdocs.doc(); |
| 100 |
|
} |
| 101 |
|
} |
| 102 |
|
|
| 103 |
0
|
end = System.currentTimeMillis(); |
| 104 |
0
|
System.out.println("milliseconds for " + iter + " TermDocs iteration: " + (end-start)); |
| 105 |
|
|
| 106 |
0
|
return ret; |
| 107 |
|
} |
| 108 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
1
PASS
|
|
| 109 |
1
|
public void testTermDocPerf() throws IOException {... |
| 110 |
|
|
| 111 |
|
|
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
|
| 115 |
|
} |