| 1 |
|
package org.apache.lucene.search; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
import org.apache.lucene.store.RAMDirectory; |
| 21 |
|
|
| 22 |
|
import org.apache.lucene.index.IndexWriter; |
| 23 |
|
import org.apache.lucene.index.Term; |
| 24 |
|
|
| 25 |
|
import org.apache.lucene.analysis.WhitespaceAnalyzer; |
| 26 |
|
|
| 27 |
|
import org.apache.lucene.document.Document; |
| 28 |
|
import org.apache.lucene.document.Field; |
| 29 |
|
|
| 30 |
|
import org.apache.lucene.queryParser.QueryParser; |
| 31 |
|
import org.apache.lucene.queryParser.ParseException; |
| 32 |
|
|
| 33 |
|
import junit.framework.TestCase; |
| 34 |
|
|
| 35 |
|
import java.util.Random; |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
|
|
|
| 98.4% |
Uncovered Elements: 2 (127) |
Complexity: 26 |
Complexity Density: 0.29 |
|
| 40 |
|
public class TestBoolean2 extends TestCase { |
| 41 |
|
private IndexSearcher searcher; |
| 42 |
|
|
| 43 |
|
public static final String field = "field"; |
| 44 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
| 45 |
11
|
public void setUp() throws Exception {... |
| 46 |
11
|
RAMDirectory directory = new RAMDirectory(); |
| 47 |
11
|
IndexWriter writer= new IndexWriter(directory, new WhitespaceAnalyzer(), true); |
| 48 |
55
|
for (int i = 0; i < docFields.length; i++) { |
| 49 |
44
|
Document doc = new Document(); |
| 50 |
44
|
doc.add(new Field(field, docFields[i], Field.Store.NO, Field.Index.TOKENIZED)); |
| 51 |
44
|
writer.addDocument(doc); |
| 52 |
|
} |
| 53 |
11
|
writer.close(); |
| 54 |
11
|
searcher = new IndexSearcher(directory); |
| 55 |
|
} |
| 56 |
|
|
| 57 |
|
private String[] docFields = { |
| 58 |
|
"w1 w2 w3 w4 w5", |
| 59 |
|
"w1 w3 w2 w3", |
| 60 |
|
"w1 xx w2 yy w3", |
| 61 |
|
"w1 w3 xx w2 yy w3" |
| 62 |
|
}; |
| 63 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 64 |
20
|
public Query makeQuery(String queryText) throws ParseException {... |
| 65 |
20
|
Query q = (new QueryParser(field, new WhitespaceAnalyzer())).parse(queryText); |
| 66 |
20
|
return q; |
| 67 |
|
} |
| 68 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
| 69 |
10
|
public void queriesTest(String queryText, int[] expDocNrs) throws Exception {... |
| 70 |
|
|
| 71 |
|
|
| 72 |
10
|
try { |
| 73 |
10
|
Query query1 = makeQuery(queryText); |
| 74 |
10
|
BooleanQuery.setUseScorer14(true); |
| 75 |
10
|
Hits hits1 = searcher.search(query1); |
| 76 |
|
|
| 77 |
10
|
Query query2 = makeQuery(queryText); |
| 78 |
10
|
BooleanQuery.setUseScorer14(false); |
| 79 |
10
|
Hits hits2 = searcher.search(query2); |
| 80 |
|
|
| 81 |
10
|
CheckHits.checkHitsQuery(query2, hits1, hits2, expDocNrs); |
| 82 |
|
} finally { |
| 83 |
10
|
BooleanQuery.setUseScorer14(false); |
| 84 |
|
} |
| 85 |
|
} |
| 86 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 87 |
1
|
public void testQueries01() throws Exception {... |
| 88 |
1
|
String queryText = "+w3 +xx"; |
| 89 |
1
|
int[] expDocNrs = {2,3}; |
| 90 |
1
|
queriesTest(queryText, expDocNrs); |
| 91 |
|
} |
| 92 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 93 |
1
|
public void testQueries02() throws Exception {... |
| 94 |
1
|
String queryText = "+w3 xx"; |
| 95 |
1
|
int[] expDocNrs = {2,3,1,0}; |
| 96 |
1
|
queriesTest(queryText, expDocNrs); |
| 97 |
|
} |
| 98 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 99 |
1
|
public void testQueries03() throws Exception {... |
| 100 |
1
|
String queryText = "w3 xx"; |
| 101 |
1
|
int[] expDocNrs = {2,3,1,0}; |
| 102 |
1
|
queriesTest(queryText, expDocNrs); |
| 103 |
|
} |
| 104 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 105 |
1
|
public void testQueries04() throws Exception {... |
| 106 |
1
|
String queryText = "w3 -xx"; |
| 107 |
1
|
int[] expDocNrs = {1,0}; |
| 108 |
1
|
queriesTest(queryText, expDocNrs); |
| 109 |
|
} |
| 110 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 111 |
1
|
public void testQueries05() throws Exception {... |
| 112 |
1
|
String queryText = "+w3 -xx"; |
| 113 |
1
|
int[] expDocNrs = {1,0}; |
| 114 |
1
|
queriesTest(queryText, expDocNrs); |
| 115 |
|
} |
| 116 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 117 |
1
|
public void testQueries06() throws Exception { |