1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| package org.apache.xindice.core.query.ftsearch; |
21 |
| |
22 |
| import org.apache.lucene.index.TermDocs; |
23 |
| import org.apache.lucene.index.Term; |
24 |
| import org.apache.lucene.index.TermEnum; |
25 |
| |
26 |
| import java.util.ArrayList; |
27 |
| import java.util.Iterator; |
28 |
| import java.util.Map; |
29 |
| import java.util.List; |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| public class NodeTermDocs implements TermDocs { |
37 |
| protected int num; |
38 |
| protected ArrayList[] nodes; |
39 |
| protected Map termMap; |
40 |
| protected int[] freqs; |
41 |
| private boolean init; |
42 |
| |
43 |
59
| public NodeTermDocs(NodeReader reader) {
|
44 |
59
| nodes = reader.getNodes();
|
45 |
59
| termMap = reader.getTermMap();
|
46 |
| |
47 |
59
| freqs = new int[nodes.length];
|
48 |
| } |
49 |
| |
50 |
63
| public void seek(Term term) {
|
51 |
63
| List docs = (List) termMap.get(term.text());
|
52 |
63
| if (docs != null) {
|
53 |
41
| for (Iterator i = docs.iterator(); i.hasNext(); ) {
|
54 |
60
| int idx = ((Integer) i.next()).intValue();
|
55 |
60
| freqs[idx]++;
|
56 |
| } |
57 |
| } |
58 |
| |
59 |
63
| num = 0;
|
60 |
| } |
61 |
| |
62 |
0
| public void seek(TermEnum termEnum) {
|
63 |
0
| seek(termEnum.term());
|
64 |
| } |
65 |
| |
66 |
8
| public int doc() {
|
67 |
8
| return num;
|
68 |
| } |
69 |
| |
70 |
8
| public int freq() {
|
71 |
8
| return freqs[num];
|
72 |
| } |
73 |
| |
74 |
8
| public boolean next() {
|
75 |
8
| if (!init) {
|
76 |
4
| init = true;
|
77 |
4
| num = 0;
|
78 |
| } else { |
79 |
4
| num++;
|
80 |
| } |
81 |
| |
82 |
8
| while(num < nodes.length && freqs[num] == 0) {
|
83 |
3
| num++;
|
84 |
| } |
85 |
| |
86 |
8
| return num < nodes.length;
|
87 |
| } |
88 |
| |
89 |
95
| public int read(int[] docs, int[] freqs) {
|
90 |
95
| int count = 0;
|
91 |
95
| for (int i = 0; i < docs.length && num < nodes.length; i++, num++) {
|
92 |
89
| if (this.freqs[num] > 0) {
|
93 |
50
| freqs[count] = this.freqs[num];
|
94 |
50
| docs[count] = num;
|
95 |
50
| count++;
|
96 |
| } |
97 |
| } |
98 |
| |
99 |
95
| return count;
|
100 |
| } |
101 |
| |
102 |
3
| public boolean skipTo(int target) {
|
103 |
3
| num = target;
|
104 |
3
| return num < nodes.length;
|
105 |
| } |
106 |
| |
107 |
| |
108 |
| |
109 |
| |
110 |
56
| public void close() {
|
111 |
| } |
112 |
| } |