| 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 junit.framework.TestCase; |
| 20 |
|
import org.apache.lucene.analysis.standard.StandardAnalyzer; |
| 21 |
|
import org.apache.lucene.document.Document; |
| 22 |
|
import org.apache.lucene.document.Field; |
| 23 |
|
import org.apache.lucene.index.IndexWriter; |
| 24 |
|
import org.apache.lucene.queryParser.ParseException; |
| 25 |
|
import org.apache.lucene.queryParser.QueryParser; |
| 26 |
|
import org.apache.lucene.store.Directory; |
| 27 |
|
import org.apache.lucene.store.RAMDirectory; |
| 28 |
|
|
| 29 |
|
import java.io.IOException; |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
@link |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
@version |
| 36 |
|
|
|
|
|
| 90.1% |
Uncovered Elements: 8 (81) |
Complexity: 17 |
Complexity Density: 0.29 |
|
| 37 |
|
public class TestMultiSearcherRanking extends TestCase { |
| 38 |
|
|
| 39 |
|
private final boolean verbose = false; |
| 40 |
|
private final String FIELD_NAME = "body"; |
| 41 |
|
private Searcher multiSearcher; |
| 42 |
|
private Searcher singleSearcher; |
| 43 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
| 44 |
1
|
public void testOneTermQuery() throws IOException, ParseException {... |
| 45 |
1
|
checkQuery("three"); |
| 46 |
|
} |
| 47 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
| 48 |
1
|
public void testTwoTermQuery() throws IOException, ParseException {... |
| 49 |
1
|
checkQuery("three foo"); |
| 50 |
|
} |
| 51 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
| 52 |
1
|
public void testPrefixQuery() throws IOException, ParseException {... |
| 53 |
1
|
checkQuery("multi*"); |
| 54 |
|
} |
| 55 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
| 56 |
1
|
public void testFuzzyQuery() throws IOException, ParseException {... |
| 57 |
1
|
checkQuery("multiThree~"); |
| 58 |
|
} |
| 59 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
| 60 |
1
|
public void testRangeQuery() throws IOException, ParseException {... |
| 61 |
1
|
checkQuery("{multiA TO multiP}"); |
| 62 |
|
} |
| 63 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
| 64 |
1
|
public void testMultiPhraseQuery() throws IOException, ParseException {... |
| 65 |
1
|
checkQuery("\"blueberry pi*\""); |
| 66 |
|
} |
| 67 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
| 68 |
1
|
public void testNoMatchQuery() throws IOException, ParseException {... |
| 69 |
1
|
checkQuery("+three +nomatch"); |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
@param |
| 84 |
|
@throws |
| 85 |
|
@throws |
| 86 |
|
|
|
|
|
| 71.4% |
Uncovered Elements: 8 (28) |
Complexity: 6 |
Complexity Density: 0.33 |
|
| 87 |
7
|
private void checkQuery(String queryStr) throws IOException, ParseException {... |
| 88 |
|
|
| 89 |
0
|
if(verbose) System.out.println("Query: " + queryStr); |
| 90 |
7
|
QueryParser queryParser = new QueryParser(FIELD_NAME, new StandardAnalyzer()); |
| 91 |
7
|
Query query = queryParser.parse(queryStr); |
| 92 |
7
|
Hits multiSearcherHits = multiSearcher.search(query); |
| 93 |
7
|
Hits singleSearcherHits = singleSearcher.search(query); |
| 94 |
7
|
assertEquals(multiSearcherHits.length(), singleSearcherHits.length()); |
| 95 |
23
|
for (int i = 0; i < multiSearcherHits.length(); i++) { |
| 96 |
16
|
Document docMulti = multiSearcherHits.doc(i); |
| 97 |
16
|
Document docSingle = singleSearcherHits.doc(i); |
| 98 |
0
|
if(verbose) System.out.println("Multi: " + docMulti.get(FIELD_NAME) + " score=" |
| 99 |
|
+ multiSearcherHits.score(i)); |
| 100 |
0
|
if(verbose) System.out.println("Single: " + docSingle.get(FIELD_NAME) + " score=" |
| 101 |
|
+ singleSearcherHits.score(i)); |
| 102 |
16
|
assertEquals(multiSearcherHits.score(i), singleSearcherHits.score(i), |
| 103 |
|
0.001f); |
| 104 |
16
|
assertEquals(docMulti.get(FIELD_NAME), docSingle.get(FIELD_NAME)); |
| 105 |
|
} |
| 106 |
0
|
if(verbose) System.out.println(); |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
|
| 112 |
7
|
protected void setUp() throws Exception {... |
| 113 |
|
|
| 114 |
7
|
Directory d1 = new RAMDirectory(); |
| 115 |
7
|
IndexWriter iw1 = new IndexWriter(d1, new StandardAnalyzer(), true); |
| 116 |
7
|
addCollection1(iw1); |
| 117 |
7
|
iw1.close(); |
| 118 |
7
|
Directory d2 = new RAMDirectory(); |
| 119 |
7
|
IndexWriter iw2 = new IndexWriter(d2, new StandardAnalyzer(), true); |
| 120 |
7
|
addCollection2(iw2); |
| 121 |
7
|
iw2.close(); |
| 122 |
|
|
| 123 |
7
|
Searchable[] s = new Searchable[2]; |
| 124 |
7
|
s[0] = new IndexSearcher(d1); |
| 125 |
7
|
s[1] = new IndexSearcher(d2); |
| 126 |
7
|
multiSearcher = new MultiSearcher(s); |
| 127 |
|
|
| 128 |
|
|
| 129 |
7
|
Directory d = new RAMDirectory(); |
| 130 |
7
|
IndexWriter iw = new IndexWriter(d, new StandardAnalyzer(), true); |
| 131 |
7
|
addCollection1(iw); |
| 132 |
7
|
addCollection2(iw); |
| 133 |
7
|
iw.close(); |
| 134 |
7
|
singleSearcher = new IndexSearcher(d); |
| 135 |
|
} |
| 136 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 137 |
14
|
private void addCollection1(IndexWriter iw) throws IOException {... |
| 138 |
14
|
add("one blah three", iw); |
| 139 |
14
|
add("one foo three multiOne", iw); |
| 140 |
14
|
add("one foobar three multiThree", iw); |
| 141 |
|