| 1 |
|
package org.apache.lucene.search; |
| 2 |
|
|
| 3 |
|
import org.apache.lucene.search.Filter; |
| 4 |
|
import org.apache.lucene.index.Term; |
| 5 |
|
import org.apache.lucene.index.IndexReader; |
| 6 |
|
import org.apache.lucene.index.TermEnum; |
| 7 |
|
import org.apache.lucene.index.TermDocs; |
| 8 |
|
|
| 9 |
|
import java.util.BitSet; |
| 10 |
|
import java.io.IOException; |
| 11 |
|
|
| 12 |
|
|
| 13 |
|
@author |
| 14 |
|
@version |
| 15 |
|
|
|
|
|
| 50% |
Uncovered Elements: 8 (16) |
Complexity: 5 |
Complexity Density: 0.45 |
|
| 16 |
|
public class PrefixFilter extends Filter { |
| 17 |
|
protected final Term prefix; |
| 18 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 19 |
9
|
public PrefixFilter(Term prefix) {... |
| 20 |
9
|
this.prefix = prefix; |
| 21 |
|
} |
| 22 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 23 |
0
|
public Term getPrefix() { return prefix; }... |
| 24 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 25 |
9
|
public BitSet bits(IndexReader reader) throws IOException {... |
| 26 |
9
|
final BitSet bitSet = new BitSet(reader.maxDoc()); |
| 27 |
9
|
new PrefixGenerator(prefix) { |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 28 |
12
|
public void handleDoc(int doc) {... |
| 29 |
12
|
bitSet.set(doc); |
| 30 |
|
} |
| 31 |
|
}.generate(reader); |
| 32 |
9
|
return bitSet; |
| 33 |
|
} |
| 34 |
|
|
| 35 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 36 |
0
|
public String toString () {... |
| 37 |
0
|
StringBuffer buffer = new StringBuffer(); |
| 38 |
0
|
buffer.append("PrefixFilter("); |
| 39 |
0
|
buffer.append(prefix.toString()); |
| 40 |
0
|
buffer.append(")"); |
| 41 |
0
|
return buffer.toString(); |
| 42 |
|
} |
| 43 |
|
} |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
| 48 |
|
interface IdGenerator { |
| 49 |
|
public void generate(IndexReader reader) throws IOException; |
| 50 |
|
public void handleDoc(int doc); |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 7 |
Complexity Density: 0.47 |
|
| 54 |
|
abstract class PrefixGenerator implements IdGenerator { |
| 55 |
|
protected final Term prefix; |
| 56 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 57 |
9
|
PrefixGenerator(Term prefix) {... |
| 58 |
9
|
this.prefix = prefix; |
| 59 |
|
} |
| 60 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 6 |
Complexity Density: 0.43 |
|
| 61 |
9
|
public void generate(IndexReader reader) throws IOException {... |
| 62 |
9
|
TermEnum enumerator = reader.terms(prefix); |
| 63 |
9
|
TermDocs termDocs = reader.termDocs(); |
| 64 |
|
|
| 65 |
9
|
try { |
| 66 |
|
|
| 67 |
9
|
String prefixText = prefix.text(); |
| 68 |
9
|
String prefixField = prefix.field(); |
| 69 |
9
|
do { |
| 70 |
18
|
Term term = enumerator.term(); |
| 71 |
18
|
if (term != null && |
| 72 |
|
term.text().startsWith(prefixText) && |
| 73 |
|
term.field() == prefixField) |
| 74 |
|
{ |
| 75 |
12
|
termDocs.seek(term); |
| 76 |
24
|
while (termDocs.next()) { |
| 77 |
12
|
handleDoc(termDocs.doc()); |
| 78 |
|
} |
| 79 |
|
} else { |
| 80 |
6
|
break; |
| 81 |
|
} |
| 82 |
12
|
} while (enumerator.next()); |
| 83 |
|
} finally { |
| 84 |
9
|
termDocs.close(); |
| 85 |
9
|
enumerator.close(); |
| 86 |
|
} |
| 87 |
|
} |
| 88 |
|
} |
| 89 |
|
|