| 1 |
|
package org.apache.lucene.search; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
import java.io.IOException; |
| 18 |
|
|
| 19 |
|
import junit.framework.TestCase; |
| 20 |
|
|
| 21 |
|
import org.apache.lucene.analysis.standard.StandardAnalyzer; |
| 22 |
|
import org.apache.lucene.document.Document; |
| 23 |
|
import org.apache.lucene.document.Field; |
| 24 |
|
import org.apache.lucene.index.IndexWriter; |
| 25 |
|
import org.apache.lucene.index.Term; |
| 26 |
|
import org.apache.lucene.search.BooleanClause; |
| 27 |
|
import org.apache.lucene.search.BooleanQuery; |
| 28 |
|
import org.apache.lucene.search.IndexSearcher; |
| 29 |
|
import org.apache.lucene.search.Query; |
| 30 |
|
import org.apache.lucene.search.TermQuery; |
| 31 |
|
import org.apache.lucene.store.RAMDirectory; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
@author |
| 37 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (58) |
Complexity: 7 |
Complexity Density: 0.14 |
|
| 38 |
|
public class TestBooleanOr extends TestCase { |
| 39 |
|
|
| 40 |
|
private static String FIELD_T = "T"; |
| 41 |
|
private static String FIELD_C = "C"; |
| 42 |
|
|
| 43 |
|
private TermQuery t1 = new TermQuery(new Term(FIELD_T, "files")); |
| 44 |
|
private TermQuery t2 = new TermQuery(new Term(FIELD_T, "deleting")); |
| 45 |
|
private TermQuery c1 = new TermQuery(new Term(FIELD_C, "production")); |
| 46 |
|
private TermQuery c2 = new TermQuery(new Term(FIELD_C, "optimize")); |
| 47 |
|
|
| 48 |
|
private IndexSearcher searcher = null; |
| 49 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 50 |
8
|
private int search(Query q) throws IOException {... |
| 51 |
8
|
QueryUtils.check(q,searcher); |
| 52 |
8
|
return searcher.search(q).length(); |
| 53 |
|
} |
| 54 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1
PASS
|
|
| 55 |
1
|
public void testElements() throws IOException {... |
| 56 |
1
|
assertEquals(1, search(t1)); |
| 57 |
1
|
assertEquals(1, search(t2)); |
| 58 |
1
|
assertEquals(1, search(c1)); |
| 59 |
1
|
assertEquals(1, search(c2)); |
| 60 |
|
} |
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
@throws |
| 67 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1
PASS
|
|
| 68 |
1
|
public void testFlat() throws IOException {... |
| 69 |
1
|
BooleanQuery q = new BooleanQuery(); |
| 70 |
1
|
q.add(new BooleanClause(t1, BooleanClause.Occur.SHOULD)); |
| 71 |
1
|
q.add(new BooleanClause(t2, BooleanClause.Occur.SHOULD)); |
| 72 |
1
|
q.add(new BooleanClause(c1, BooleanClause.Occur.SHOULD)); |
| 73 |
1
|
q.add(new BooleanClause(c2, BooleanClause.Occur.SHOULD)); |
| 74 |
1
|
assertEquals(1, search(q)); |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
@throws |
| 82 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1
PASS
|
|
| 83 |
1
|
public void testParenthesisMust() throws IOException {... |
| 84 |
1
|
BooleanQuery q3 = new BooleanQuery(); |
| 85 |
1
|
q3.add(new BooleanClause(t1, BooleanClause.Occur.SHOULD)); |
| 86 |
1
|
q3.add(new BooleanClause(t2, BooleanClause.Occur.SHOULD)); |
| 87 |
1
|
BooleanQuery q4 = new BooleanQuery(); |
| 88 |
1
|
q4.add(new BooleanClause(c1, BooleanClause.Occur.MUST)); |
| 89 |
1
|
q4.add(new BooleanClause(c2, BooleanClause.Occur.MUST)); |
| 90 |
1
|
BooleanQuery q2 = new BooleanQuery(); |
| 91 |
1
|
q2.add(q3, BooleanClause.Occur.SHOULD); |
| 92 |
1
|
q2.add(q4, BooleanClause.Occur.SHOULD); |
| 93 |
1
|
assertEquals(1, search(q2)); |
| 94 |
|
} |
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
@throws |
| 101 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1
PASS
|
|
| 102 |
1
|
public void testParenthesisMust2() throws IOException {... |
| 103 |
1
|
BooleanQuery q3 = new BooleanQuery(); |
| 104 |
1
|
q3.add(new BooleanClause(t1, BooleanClause.Occur.SHOULD)); |
| 105 |
1
|
q3.add(new BooleanClause(t2, BooleanClause.Occur.SHOULD)); |
| 106 |
1
|
BooleanQuery q4 = new BooleanQuery(); |
| 107 |
1
|
q4.add(new BooleanClause(c1, BooleanClause.Occur.SHOULD)); |
| 108 |
1
|
q4.add(new BooleanClause(c2, BooleanClause.Occur.SHOULD)); |
| 109 |
1
|
BooleanQuery q2 = new BooleanQuery(); |
| 110 |
1
|
q2.add(q3, BooleanClause.Occur.SHOULD); |
| 111 |
1
|
q2.add(q4, BooleanClause.Occur.MUST); |
| 112 |
1
|
assertEquals(1, search(q2)); |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
@throws |
| 120 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1
PASS
|
|
| 121 |
1
|
public void testParenthesisShould() throws IOException {... |
| 122 |
1
|
BooleanQuery q3 = new BooleanQuery(); |
| 123 |
1
|
q3.add(new BooleanClause(t1, BooleanClause.Occur.SHOULD)); |
| 124 |
1
|
q3.add(new BooleanClause(t2, BooleanClause.Occur.SHOULD)); |
| 125 |
1
|
BooleanQuery q4 = new BooleanQuery(); |
| 126 |
1
|
q4.add(new BooleanClause(c1, BooleanClause.Occur.SHOULD)); |
| 127 |
1
|
q4.add(new BooleanClause(c2, BooleanClause.Occur.SHOULD)); |
| 128 |
1
|
BooleanQuery q2 = new BooleanQuery(); |
| 129 |
1
|
q2.add(q3, BooleanClause.Occur.SHOULD); |
| 130 |
1
|
q2.add(q4, BooleanClause.Occur.SHOULD); |
| 131 |
1
|
assertEquals(1, search(q2)); |
| 132 |
|
} |
| 133 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
| 134 |
5
|
protected void setUp() throws Exception {... |
| 135 |
5
|
super.setUp(); |
| 136 |
|
|
| 137 |
|
|
| 138 |
5
|
RAMDirectory rd = new RAMDirectory(); |
| 139 |
|
|
| 140 |
|
|
| 141 |
5
|
IndexWriter writer = new IndexWriter(rd, new StandardAnalyzer(), true); |
| 142 |
|
|
| 143 |
|
|
| 144 |
5
|
Document d = new Document(); |
| 145 |
5
|
d.add(new Field( |
| 146 |
|
FIELD_T, |
| 147 |
|
"Optimize not deleting all files", |
| 148 |
|
Field.Store.YES, |
| 149 |
|
Field.Index.TOKENIZED)); |
| 150 |
5
|
d.add(new Field( |
| 151 |
|
FIELD_C, |
| 152 |
|
"Deleted When I run an optimize in our production environment.", |
| 153 |
|
Field.Store.YES, |
| 154 |
|
Field.Index.TOKENIZED)); |
| 155 |
|
|
| 156 |
|
|
| 157 |
5
|
writer.addDocument(d); |
| 158 |
5
|
writer.close(); |
| 159 |
|
|
| 160 |
|
|
| 161 |
5
|
searcher = new IndexSearcher(rd); |
| 162 |
|
} |
| 163 |
|
} |