| 1 |
|
package org.apache.lucene.search.spans; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
import java.io.IOException; |
| 20 |
|
|
| 21 |
|
import org.apache.lucene.analysis.standard.StandardAnalyzer; |
| 22 |
|
import org.apache.lucene.index.IndexReader; |
| 23 |
|
import org.apache.lucene.index.IndexWriter; |
| 24 |
|
import org.apache.lucene.index.Term; |
| 25 |
|
import org.apache.lucene.search.*; |
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
@author |
| 32 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 5 |
Complexity Density: 0.21 |
|
| 33 |
|
public class TestSpansAdvanced2 extends TestSpansAdvanced { |
| 34 |
|
IndexSearcher searcher2; |
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 38 |
4
|
protected void setUp() throws Exception {... |
| 39 |
4
|
super.setUp(); |
| 40 |
|
|
| 41 |
|
|
| 42 |
4
|
final IndexWriter writer = new IndexWriter(mDirectory, new StandardAnalyzer(), false); |
| 43 |
4
|
addDocument(writer, "A", "Should we, could we, would we?"); |
| 44 |
4
|
addDocument(writer, "B", "It should. Should it?"); |
| 45 |
4
|
addDocument(writer, "C", "It shouldn't."); |
| 46 |
4
|
addDocument(writer, "D", "Should we, should we, should we."); |
| 47 |
4
|
writer.close(); |
| 48 |
|
|
| 49 |
|
|
| 50 |
4
|
searcher2 = new IndexSearcher(mDirectory); |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
@throws |
| 57 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 58 |
1
|
public void testVerifyIndex() throws Exception {... |
| 59 |
1
|
final IndexReader reader = IndexReader.open(mDirectory); |
| 60 |
1
|
assertEquals(8, reader.numDocs()); |
| 61 |
1
|
reader.close(); |
| 62 |
|
} |
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
@throws |
| 68 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1
PASS
|
|
| 69 |
1
|
public void testSingleSpanQuery() throws IOException {... |
| 70 |
|
|
| 71 |
1
|
final Query spanQuery = new SpanTermQuery(new Term(FIELD_TEXT, "should")); |
| 72 |
1
|
final String[] expectedIds = new String[] { "B", "D", "1", "2", "3", "4", "A" }; |
| 73 |
1
|
final float[] expectedScores = new float[] { 0.625f, 0.45927936f, 0.35355338f, 0.35355338f, 0.35355338f, |
| 74 |
|
0.35355338f, 0.26516503f, }; |
| 75 |
1
|
assertHits(searcher2, spanQuery, "single span query", expectedIds, expectedScores); |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
@throws |
| 82 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1
PASS
|
|
| 83 |
1
|
public void testMultipleDifferentSpanQueries() throws IOException {... |
| 84 |
|
|
| 85 |
1
|
final Query spanQuery1 = new SpanTermQuery(new Term(FIELD_TEXT, "should")); |
| 86 |
1
|
final Query spanQuery2 = new SpanTermQuery(new Term(FIELD_TEXT, "we")); |
| 87 |
1
|
final BooleanQuery query = new BooleanQuery(); |
| 88 |
1
|
query.add(spanQuery1, BooleanClause.Occur.MUST); |
| 89 |
1
|
query.add(spanQuery2, BooleanClause.Occur.MUST); |
| 90 |
1
|
final String[] expectedIds = new String[] { "D", "A" }; |
| 91 |
|
|
| 92 |
|
|
| 93 |
1
|
final float[] expectedScores = new float[] { 1.0191123f, 0.93163157f }; |
| 94 |
1
|
assertHits(searcher2, query, "multiple different span queries", expectedIds, expectedScores); |
| 95 |
|
} |
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
@throws |
| 101 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1
PASS
|
|
| 102 |
1
|
public void testBooleanQueryWithSpanQueries() throws IOException {... |
| 103 |
|
|
| 104 |
1
|
doTestBooleanQueryWithSpanQueries(searcher2, 0.73500174f); |
| 105 |
|
} |
| 106 |
|
} |