| 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 java.io.IOException; |
| 20 |
|
import java.io.Serializable; |
| 21 |
|
import java.util.Calendar; |
| 22 |
|
import java.util.GregorianCalendar; |
| 23 |
|
import java.util.Map; |
| 24 |
|
import java.util.Random; |
| 25 |
|
import java.util.TreeMap; |
| 26 |
|
|
| 27 |
|
import junit.framework.Test; |
| 28 |
|
import junit.framework.TestCase; |
| 29 |
|
import junit.framework.TestSuite; |
| 30 |
|
import junit.textui.TestRunner; |
| 31 |
|
|
| 32 |
|
import org.apache.lucene.analysis.standard.StandardAnalyzer; |
| 33 |
|
import org.apache.lucene.document.DateTools; |
| 34 |
|
import org.apache.lucene.document.Document; |
| 35 |
|
import org.apache.lucene.document.Field; |
| 36 |
|
import org.apache.lucene.index.IndexReader; |
| 37 |
|
import org.apache.lucene.index.IndexWriter; |
| 38 |
|
import org.apache.lucene.index.Term; |
| 39 |
|
import org.apache.lucene.store.Directory; |
| 40 |
|
import org.apache.lucene.store.RAMDirectory; |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
@author |
| 46 |
|
|
| 47 |
|
|
|
|
|
| 75% |
Uncovered Elements: 25 (100) |
Complexity: 22 |
Complexity Density: 0.32 |
|
| 48 |
|
public class TestCustomSearcherSort |
| 49 |
|
extends TestCase |
| 50 |
|
implements Serializable { |
| 51 |
|
|
| 52 |
|
private Directory index = null; |
| 53 |
|
private Query query = null; |
| 54 |
|
|
| 55 |
|
private final static int INDEX_SIZE = 2000; |
| 56 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 57 |
3
|
public TestCustomSearcherSort (String name) {... |
| 58 |
3
|
super (name); |
| 59 |
|
} |
| 60 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 61 |
0
|
public static void main (String[] argv) {... |
| 62 |
0
|
TestRunner.run (suite()); |
| 63 |
|
} |
| 64 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 65 |
1
|
public static Test suite() {... |
| 66 |
1
|
return new TestSuite (TestCustomSearcherSort.class); |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 4 |
Complexity Density: 0.29 |
|
| 71 |
3
|
private Directory getIndex()... |
| 72 |
|
throws IOException { |
| 73 |
3
|
RAMDirectory indexStore = new RAMDirectory (); |
| 74 |
3
|
IndexWriter writer = new IndexWriter (indexStore, new StandardAnalyzer(), true); |
| 75 |
3
|
RandomGen random = new RandomGen(); |
| 76 |
6003
|
for (int i=0; i<INDEX_SIZE; ++i) { |
| 77 |
6000
|
Document doc = new Document(); |
| 78 |
6000
|
if((i%5)!=0) { |
| 79 |
4800
|
doc.add (new Field("publicationDate_", random.getLuceneDate(), Field.Store.YES, Field.Index.UN_TOKENIZED)); |
| 80 |
|
} |
| 81 |
6000
|
if((i%7)==0) { |
| 82 |
858
|
doc.add (new Field("content", "test", Field.Store.YES, Field.Index.TOKENIZED)); |
| 83 |
|
} |
| 84 |
|
|
| 85 |
6000
|
doc.add(new Field("mandant", Integer.toString(i%3), Field.Store.YES, Field.Index.UN_TOKENIZED)); |
| 86 |
6000
|
writer.addDocument (doc); |
| 87 |
|
} |
| 88 |
3
|
writer.optimize (); |
| 89 |
3
|
writer.close (); |
| 90 |
3
|
return indexStore; |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 96 |
3
|
public void setUp() throws Exception {... |
| 97 |
3
|
index = getIndex(); |
| 98 |
3
|
query = new TermQuery( new Term("content", "test")); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 104 |
1
|
public void testFieldSortCustomSearcher() throws Exception {... |
| 105 |
|
|
| 106 |
|
|
| 107 |
1
|
Sort custSort = new Sort(new SortField[] { |
| 108 |
|
new SortField("publicationDate_"), |
| 109 |
|
SortField.FIELD_SCORE |
| 110 |
|
}); |
| 111 |
1
|
Searcher searcher = new CustomSearcher (index, 2); |
| 112 |
|
|
| 113 |
1
|
matchHits(searcher, custSort); |
| 114 |
|
} |
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 118 |
1
|
public void testFieldSortSingleSearcher() throws Exception {... |
| 119 |
|
|
| 120 |
|
|
| 121 |
1
|
Sort custSort = new Sort(new SortField[] { |
| 122 |
|
new SortField("publicationDate_"), |
| 123 |
|
SortField.FIELD_SCORE |
| 124 |
|
}); |
| 125 |
1
|
Searcher searcher = |
| 126 |
|
new MultiSearcher(new Searchable[] { |
| 127 |
|
new CustomSearcher (index, 2)}); |
| 128 |
|
|
| 129 |
1
|
matchHits(searcher, custSort); |
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 134 |
1
|
public void testFieldSortMultiCustomSearcher() throws Exception {... |
| 135 |
|
|
| 136 |
|
|
| 137 |
1
|
Sort custSort = new Sort(new SortField[] { |
| 138 |
|
new SortField("publicationDate_"), |
| 139 |
|
SortField.FIELD_SCORE |
| 140 |
|
}); |
| 141 |
1
|
Searcher searcher = |
| 142 |
|
new MultiSearcher(new Searchable[] { |
| 143 |
|
new CustomSearcher (index, 0), |
| 144 |
|
new CustomSearcher (index, 2)}); |
|