|
19 | 19 |
|
20 | 20 | package org.elasticsearch.common.lucene.docset;
|
21 | 21 |
|
22 |
| -import org.apache.lucene.search.DocIdSetIterator; |
23 |
| - |
24 | 22 | import java.io.IOException;
|
25 | 23 |
|
26 | 24 | /**
|
27 | 25 | * @author kimchy (shay.banon)
|
28 | 26 | */
|
29 |
| -public class NotDocSet extends DocSet { |
| 27 | +public class NotDocSet extends GetDocSet { |
30 | 28 |
|
31 | 29 | private final DocSet set;
|
32 | 30 |
|
33 |
| - private final int max; |
34 |
| - |
35 | 31 | public NotDocSet(DocSet set, int max) {
|
| 32 | + super(max); |
36 | 33 | this.set = set;
|
37 |
| - this.max = max; |
38 | 34 | }
|
39 | 35 |
|
40 | 36 | @Override public boolean isCacheable() {
|
41 |
| - return set.isCacheable(); |
| 37 | + // if it is cached, create a new doc set for it so it will be fast for advance in iterator |
| 38 | + return false; |
42 | 39 | }
|
43 | 40 |
|
44 | 41 | @Override public boolean get(int doc) throws IOException {
|
45 | 42 | return !set.get(doc);
|
46 | 43 | }
|
47 |
| - |
48 |
| - @Override public DocIdSetIterator iterator() throws IOException { |
49 |
| - return new NotDocIdSetIterator(); |
50 |
| - } |
51 |
| - |
52 |
| - class NotDocIdSetIterator extends DocIdSetIterator { |
53 |
| - int lastReturn = -1; |
54 |
| - private DocIdSetIterator it1 = null; |
55 |
| - private int innerDocid = -1; |
56 |
| - |
57 |
| - NotDocIdSetIterator() throws IOException { |
58 |
| - initialize(); |
59 |
| - } |
60 |
| - |
61 |
| - private void initialize() throws IOException { |
62 |
| - it1 = set.iterator(); |
63 |
| - |
64 |
| - try { |
65 |
| - if ((innerDocid = it1.nextDoc()) == DocIdSetIterator.NO_MORE_DOCS) it1 = null; |
66 |
| - } catch (IOException e) { |
67 |
| - e.printStackTrace(); |
68 |
| - } |
69 |
| - } |
70 |
| - |
71 |
| - @Override |
72 |
| - public int docID() { |
73 |
| - return lastReturn; |
74 |
| - } |
75 |
| - |
76 |
| - @Override |
77 |
| - public int nextDoc() throws IOException { |
78 |
| - return advance(0); |
79 |
| - } |
80 |
| - |
81 |
| - @Override |
82 |
| - public int advance(int target) throws IOException { |
83 |
| - |
84 |
| - if (lastReturn == DocIdSetIterator.NO_MORE_DOCS) { |
85 |
| - return DocIdSetIterator.NO_MORE_DOCS; |
86 |
| - } |
87 |
| - |
88 |
| - if (target <= lastReturn) target = lastReturn + 1; |
89 |
| - |
90 |
| - if (it1 != null && innerDocid < target) { |
91 |
| - if ((innerDocid = it1.advance(target)) == DocIdSetIterator.NO_MORE_DOCS) { |
92 |
| - it1 = null; |
93 |
| - } |
94 |
| - } |
95 |
| - |
96 |
| - while (it1 != null && innerDocid == target) { |
97 |
| - target++; |
98 |
| - if (target >= max) { |
99 |
| - return (lastReturn = DocIdSetIterator.NO_MORE_DOCS); |
100 |
| - } |
101 |
| - if ((innerDocid = it1.advance(target)) == DocIdSetIterator.NO_MORE_DOCS) { |
102 |
| - it1 = null; |
103 |
| - } |
104 |
| - } |
105 |
| - return (lastReturn = target); |
106 |
| - } |
107 |
| - } |
108 | 44 | }
|
0 commit comments