| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.apache.lucene.search; |
| 17 |
|
|
| 18 |
|
import java.io.IOException; |
| 19 |
|
|
| 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.index.Term; |
| 25 |
|
import org.apache.lucene.store.RAMDirectory; |
| 26 |
|
|
| 27 |
|
import junit.framework.TestCase; |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
@author |
| 33 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (34) |
Complexity: 3 |
Complexity Density: 0.1 |
|
| 34 |
|
public class TestMatchAllDocsQuery extends TestCase { |
| 35 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 1 |
Complexity Density: 0.04 |
1
PASS
|
|
| 36 |
1
|
public void testQuery() throws IOException {... |
| 37 |
1
|
RAMDirectory dir = new RAMDirectory(); |
| 38 |
1
|
IndexWriter iw = new IndexWriter(dir, new StandardAnalyzer(), true); |
| 39 |
1
|
addDoc("one", iw); |
| 40 |
1
|
addDoc("two", iw); |
| 41 |
1
|
addDoc("three four", iw); |
| 42 |
1
|
iw.close(); |
| 43 |
|
|
| 44 |
1
|
IndexSearcher is = new IndexSearcher(dir); |
| 45 |
1
|
Hits hits = is.search(new MatchAllDocsQuery()); |
| 46 |
1
|
assertEquals(3, hits.length()); |
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
1
|
BooleanQuery bq = new BooleanQuery(); |
| 51 |
1
|
bq.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST); |
| 52 |
1
|
bq.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST); |
| 53 |
1
|
hits = is.search(bq); |
| 54 |
1
|
assertEquals(3, hits.length()); |
| 55 |
|
|
| 56 |
1
|
bq = new BooleanQuery(); |
| 57 |
1
|
bq.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST); |
| 58 |
1
|
bq.add(new TermQuery(new Term("key", "three")), BooleanClause.Occur.MUST); |
| 59 |
1
|
hits = is.search(bq); |
| 60 |
1
|
assertEquals(1, hits.length()); |
| 61 |
|
|
| 62 |
|
|
| 63 |
1
|
is.getIndexReader().deleteDocument(0); |
| 64 |
1
|
hits = is.search(new MatchAllDocsQuery()); |
| 65 |
1
|
assertEquals(2, hits.length()); |
| 66 |
|
|
| 67 |
1
|
is.close(); |
| 68 |
|
} |
| 69 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1
PASS
|
|
| 70 |
1
|
public void testEquals() {... |
| 71 |
1
|
Query q1 = new MatchAllDocsQuery(); |
| 72 |
1
|
Query q2 = new MatchAllDocsQuery(); |
| 73 |
1
|
assertTrue(q1.equals(q2)); |
| 74 |
1
|
q1.setBoost(1.5f); |
| 75 |
1
|
assertFalse(q1.equals(q2)); |
| 76 |
|
} |
| 77 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 78 |
3
|
private void addDoc(String text, IndexWriter iw) throws IOException {... |
| 79 |
3
|
Document doc = new Document(); |
| 80 |
3
|
doc.add(new Field("key", text, Field.Store.YES, Field.Index.TOKENIZED)); |
| 81 |
3
|
iw.addDocument(doc); |
| 82 |
|
} |
| 83 |
|
|
| 84 |
|
} |