| 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 org.apache.lucene.analysis.Analyzer; |
| 20 |
|
import org.apache.lucene.analysis.Token; |
| 21 |
|
import org.apache.lucene.analysis.TokenStream; |
| 22 |
|
import org.apache.lucene.index.TermFreqVector; |
| 23 |
|
|
| 24 |
|
import java.io.IOException; |
| 25 |
|
import java.io.StringReader; |
| 26 |
|
import java.util.*; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
|
|
|
| 59.3% |
Uncovered Elements: 33 (81) |
Complexity: 21 |
Complexity Density: 0.43 |
|
| 32 |
|
public class QueryTermVector implements TermFreqVector { |
| 33 |
|
private String [] terms = new String[0]; |
| 34 |
|
private int [] termFreqs = new int[0]; |
| 35 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 36 |
0
|
public String getField() { return null; }... |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
@param |
| 41 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 42 |
2
|
public QueryTermVector(String [] queryTerms) {... |
| 43 |
|
|
| 44 |
2
|
processTerms(queryTerms); |
| 45 |
|
} |
| 46 |
|
|
|
|
|
| 73.3% |
Uncovered Elements: 4 (15) |
Complexity: 5 |
Complexity Density: 0.56 |
|
| 47 |
1
|
public QueryTermVector(String queryString, Analyzer analyzer) { ... |
| 48 |
1
|
if (analyzer != null) |
| 49 |
|
{ |
| 50 |
1
|
TokenStream stream = analyzer.tokenStream("", new StringReader(queryString)); |
| 51 |
1
|
if (stream != null) |
| 52 |
|
{ |
| 53 |
1
|
Token next = null; |
| 54 |
1
|
List terms = new ArrayList(); |
| 55 |
1
|
try { |
| 56 |
?
|
while ((next = stream.next()) != null) |
| 57 |
|
{ |
| 58 |
9
|
terms.add(next.termText()); |
| 59 |
|
} |
| 60 |
1
|
processTerms((String[])terms.toArray(new String[terms.size()])); |
| 61 |
|
} catch (IOException e) { |
| 62 |
|
} |
| 63 |
|
} |
| 64 |
|
} |
| 65 |
|
} |
| 66 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 5 |
Complexity Density: 0.24 |
|
| 67 |
3
|
private void processTerms(String[] queryTerms) {... |
| 68 |
3
|
if (queryTerms != null) { |
| 69 |
2
|
Arrays.sort(queryTerms); |
| 70 |
2
|
Map tmpSet = new HashMap(queryTerms.length); |
| 71 |
|
|
| 72 |
2
|
List tmpList = new ArrayList(queryTerms.length); |
| 73 |
2
|
List tmpFreqs = new ArrayList(queryTerms.length); |
| 74 |
2
|
int j = 0; |
| 75 |
20
|
for (int i = 0; i < queryTerms.length; i++) { |
| 76 |
18
|
String term = queryTerms[i]; |
| 77 |
18
|
Integer position = (Integer)tmpSet.get(term); |
| 78 |
18
|
if (position == null) { |
| 79 |
8
|
tmpSet.put(term, new Integer(j++)); |
| 80 |
8
|
tmpList.add(term); |
| 81 |
8
|
tmpFreqs.add(new Integer(1)); |
| 82 |
|
} |
| 83 |
|
else { |
| 84 |
10
|
Integer integer = (Integer)tmpFreqs.get(position.intValue()); |
| 85 |
10
|
tmpFreqs.set(position.intValue(), new Integer(integer.intValue() + 1)); |
| 86 |
|
} |
| 87 |
|
} |
| 88 |
2
|
terms = (String[])tmpList.toArray(terms); |
| 89 |
|
|
| 90 |
2
|
termFreqs = new int[tmpFreqs.size()]; |
| 91 |
2
|
int i = 0; |
| 92 |
10
|
for (Iterator iter = tmpFreqs.iterator(); iter.hasNext();) { |
| 93 |
8
|
Integer integer = (Integer) iter.next(); |
| 94 |
8
|
termFreqs[i++] = integer.intValue(); |
| 95 |
|
} |
| 96 |
|
} |
| 97 |
|
} |
| 98 |
|
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 99 |
0
|
public final String toString() {... |
| 100 |
0
|
StringBuffer sb = new StringBuffer(); |
| 101 |
0
|
sb.append('{'); |
| 102 |
0
|
for (int i=0; i<terms.length; i++) { |
| 103 |
0
|
if (i>0) sb.append(", "); |
| 104 |
0
|
sb.append(terms[i]).append('/').append(termFreqs[i]); |
| 105 |
|
} |
| 106 |
0
|
sb.append('}'); |
| 107 |
0
|
return sb.toString(); |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 111 |
0
|
public int size() {... |
| 112 |
0
|
return terms.length; |
| 113 |
|
} |
| 114 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 115 |
3
|
public String[] getTerms() {... |
| 116 |
3
|
return terms; |
| 117 |
|
} |
| 118 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 119 |
2
|
public int[] getTermFrequencies() {... |
| 120 |
2
|
return termFreqs; |
| 121 |
|
} |
| 122 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 123 |
0
|
public int indexOf(String term) {... |
| 124 |
0
|
int res = Arrays.binarySearch(terms, term); |
| 125 |
0
|
return res >= 0 ? res : -1; |
| 126 |
|
} |
| 127 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 128 |
0
|
public int[] indexesOf(String[] terms, int start, int len) {... |
| 129 |
0
|
int res[] = new int[len]; |
| 130 |
|
|
| 131 |
0
|
for (int i=0; i < len; i++) { |
| 132 |
0
|
res[i] = indexOf(terms[i]); |
| 133 |
|
} |
| 134 |
0
|
return res; |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
} |