| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1 | package de.ids_mannheim.korap.query.spans; |
| 2 | |
| Eliza Margaretha | 2289898 | 2014-11-04 17:10:21 +0000 | [diff] [blame] | 3 | import java.io.IOException; |
| 4 | import java.util.ArrayList; |
| 5 | import java.util.Collection; |
| 6 | import java.util.LinkedList; |
| 7 | import java.util.Map; |
| 8 | |
| Akron | 700c1eb | 2015-09-25 16:57:30 +0200 | [diff] [blame] | 9 | import org.apache.lucene.index.LeafReaderContext; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 10 | import org.apache.lucene.index.Term; |
| 11 | import org.apache.lucene.index.TermContext; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 12 | import org.apache.lucene.search.DocIdSetIterator; |
| Eliza Margaretha | 2289898 | 2014-11-04 17:10:21 +0000 | [diff] [blame] | 13 | import org.apache.lucene.search.spans.Spans; |
| 14 | import org.apache.lucene.util.Bits; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 15 | import org.slf4j.Logger; |
| 16 | import org.slf4j.LoggerFactory; |
| 17 | |
| Eliza Margaretha | 2289898 | 2014-11-04 17:10:21 +0000 | [diff] [blame] | 18 | import de.ids_mannheim.korap.query.SpanWithinQuery; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 19 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * SpanWithinQuery is DEPRECATED and will |
| 23 | * be replaced by SpanPositionQuery in the near future |
| Nils Diewald | cb8afb3 | 2015-02-04 21:12:37 +0000 | [diff] [blame] | 24 | * |
| 25 | * TODO: Support exclusivity |
| 26 | * TODO: Use the term "queue" and implement it similar to SpanOrQuery |
| Akron | a7b936d | 2016-03-04 13:40:54 +0100 | [diff] [blame] | 27 | * TODO: Implement a incrStartPos() method to forward an embedded span |
| 28 | * until the start position is higher than the current start position. |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 29 | */ |
| 30 | |
| Nils Diewald | 82a4b86 | 2014-02-20 21:17:41 +0000 | [diff] [blame] | 31 | /** |
| Nils Diewald | 1455e1e | 2014-08-01 16:12:43 +0000 | [diff] [blame] | 32 | * Compare two spans and check how they relate positionally. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 33 | * |
| Nils Diewald | 44d5fa1 | 2015-01-15 21:31:52 +0000 | [diff] [blame] | 34 | * @author diewald |
| Nils Diewald | 82a4b86 | 2014-02-20 21:17:41 +0000 | [diff] [blame] | 35 | */ |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 36 | public class WithinSpans extends Spans { |
| Nils Diewald | 82a4b86 | 2014-02-20 21:17:41 +0000 | [diff] [blame] | 37 | |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 38 | // Logger |
| 39 | private final Logger log = LoggerFactory.getLogger(WithinSpans.class); |
| Nils Diewald | 1455e1e | 2014-08-01 16:12:43 +0000 | [diff] [blame] | 40 | |
| Nils Diewald | 82a4b86 | 2014-02-20 21:17:41 +0000 | [diff] [blame] | 41 | // This advices the java compiler to ignore all loggings |
| 42 | public static final boolean DEBUG = false; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 43 | |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 44 | private boolean more = false; |
| 45 | |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 46 | // Boolean value indicating if span B |
| 47 | // should be forwarded next (true) |
| 48 | // or span A (false); |
| 49 | boolean nextSpanB = true; |
| Nils Diewald | 82a4b86 | 2014-02-20 21:17:41 +0000 | [diff] [blame] | 50 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 51 | private int wrapStart = -1, wrapEnd = -1, embeddedStart = -1, |
| 52 | embeddedEnd = -1, wrapDoc = -1, embeddedDoc = -1, matchDoc = -1, |
| 53 | matchStart = -1, matchEnd = -1; |
| 54 | |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 55 | private Collection<byte[]> matchPayload; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 56 | private Collection<byte[]> embeddedPayload; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 57 | |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 58 | // Indicates that the wrap and the embedded spans are in the same doc |
| 59 | private boolean inSameDoc = false; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 60 | |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 61 | /* |
| 62 | Supported flags are currently: |
| Nils Diewald | cb8afb3 | 2015-02-04 21:12:37 +0000 | [diff] [blame] | 63 | ov -> 0 | overlap: A & B != empty |
| 64 | rov -> 2 | real overlap: A & B != empty and |
| 65 | ((A | B) != A or |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 66 | (A | B) != B) |
| Nils Diewald | cb8afb3 | 2015-02-04 21:12:37 +0000 | [diff] [blame] | 67 | in -> 4 | within: A | B = A |
| 68 | rin -> 6 | real within: A | B = A and |
| 69 | A & B != A |
| 70 | ew -> 8 | endswith: A | B = A and |
| 71 | A.start = B.start |
| 72 | sw -> 10 | startswith: A | B = A and |
| 73 | A.end = B.end |
| 74 | m -> 12 | A = B |
| 75 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 76 | public static final byte OVERLAP = (byte) 0, REAL_OVERLAP = (byte) 2, |
| 77 | WITHIN = (byte) 4, REAL_WITHIN = (byte) 6, ENDSWITH = (byte) 8, |
| 78 | STARTSWITH = (byte) 10, MATCH = (byte) 12; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 79 | |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 80 | private byte flag; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 81 | |
| Nils Diewald | 1455e1e | 2014-08-01 16:12:43 +0000 | [diff] [blame] | 82 | // Contains the query |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 83 | private SpanWithinQuery query; |
| 84 | |
| Nils Diewald | cb8afb3 | 2015-02-04 21:12:37 +0000 | [diff] [blame] | 85 | // Representing the first operand |
| 86 | private final Spans wrapSpans; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 87 | |
| Nils Diewald | cb8afb3 | 2015-02-04 21:12:37 +0000 | [diff] [blame] | 88 | // Representing the second operand |
| 89 | private final Spans embeddedSpans; |
| 90 | |
| 91 | // Check flag if the current constellation |
| 92 | // was checked yet |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 93 | private boolean tryMatch = true; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 94 | |
| Nils Diewald | 01ff7af | 2015-02-04 22:54:26 +0000 | [diff] [blame] | 95 | // Two buffers for storing candidates |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 96 | private LinkedList<WithinSpan> spanStore1, spanStore2; |
| 97 | |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 98 | |
| Nils Diewald | 01ff7af | 2015-02-04 22:54:26 +0000 | [diff] [blame] | 99 | /** |
| 100 | * Construct a new WithinSpans object. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 101 | * |
| 102 | * @param spanWithinQuery |
| 103 | * The parental {@link SpanWithinQuery}. |
| 104 | * @param context |
| Akron | 700c1eb | 2015-09-25 16:57:30 +0200 | [diff] [blame] | 105 | * The {@link LeafReaderContext}. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 106 | * @param acceptDocs |
| 107 | * Bit vector representing the documents |
| 108 | * to be searched in. |
| 109 | * @param termContexts |
| 110 | * A map managing {@link TermState TermStates}. |
| 111 | * @param flag |
| 112 | * A byte flag indicating the positional condition of |
| 113 | * the sub spans. |
| Nils Diewald | 01ff7af | 2015-02-04 22:54:26 +0000 | [diff] [blame] | 114 | */ |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 115 | public WithinSpans (SpanWithinQuery spanWithinQuery, |
| Akron | 700c1eb | 2015-09-25 16:57:30 +0200 | [diff] [blame] | 116 | LeafReaderContext context, Bits acceptDocs, |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 117 | Map<Term, TermContext> termContexts, byte flag) |
| 118 | throws IOException { |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 119 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 120 | if (DEBUG) |
| 121 | log.trace("Construct WithinSpans"); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 122 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 123 | // Init copies |
| 124 | this.matchPayload = new LinkedList<byte[]>(); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 125 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 126 | // Get spans |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 127 | this.wrapSpans = spanWithinQuery.wrap().getSpans(context, acceptDocs, |
| 128 | termContexts); |
| 129 | this.embeddedSpans = spanWithinQuery.embedded().getSpans(context, |
| 130 | acceptDocs, termContexts); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 131 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 132 | this.flag = flag; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 133 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 134 | // SpanStores for backtracking |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 135 | this.spanStore1 = new LinkedList<WithinSpan>(); |
| 136 | this.spanStore2 = new LinkedList<WithinSpan>(); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 137 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 138 | // kept for toString() only. |
| 139 | this.query = spanWithinQuery; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 140 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 141 | |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 142 | |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 143 | // Move to next match, returning true iff any such exists. |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 144 | @Override |
| 145 | public boolean next () throws IOException { |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 146 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 147 | if (DEBUG) |
| 148 | log.trace("Next with docs {}, {}", wrapDoc, embeddedDoc); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 149 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 150 | // Initialize spans |
| 151 | if (!this.init()) { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 152 | this.more = false; |
| 153 | this.inSameDoc = false; |
| 154 | this.wrapDoc = DocIdSetIterator.NO_MORE_DOCS; |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 155 | this.embeddedDoc = DocIdSetIterator.NO_MORE_DOCS; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 156 | this.matchDoc = DocIdSetIterator.NO_MORE_DOCS; |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 157 | return false; |
| 158 | }; |
| Nils Diewald | 82a4b86 | 2014-02-20 21:17:41 +0000 | [diff] [blame] | 159 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 160 | // There are more spans and they are in the same document |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 161 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 162 | while (this.more && (wrapDoc == embeddedDoc || |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 163 | // this.inSameDoc || |
| 164 | this.toSameDoc())) { |
| Akron | c3a5df8 | 2016-04-29 16:56:53 +0200 | [diff] [blame] | 165 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 166 | if (DEBUG) |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 167 | log.trace("We are in the same doc: {}, {}", wrapDoc, |
| 168 | embeddedDoc); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 169 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 170 | // Both spans match according to the flag |
| 171 | // Silently the next operations are prepared |
| 172 | if (this.tryMatch && this.doesMatch()) { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 173 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 174 | if (this.wrapEnd == -1) |
| 175 | this.wrapEnd = this.wrapSpans.end(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 176 | |
| 177 | this.matchStart = embeddedStart < wrapStart ? embeddedStart |
| 178 | : wrapStart; |
| 179 | this.matchEnd = embeddedEnd > wrapEnd ? embeddedEnd : wrapEnd; |
| 180 | this.matchDoc = embeddedDoc; |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 181 | this.matchPayload.clear(); |
| Nils Diewald | 82a4b86 | 2014-02-20 21:17:41 +0000 | [diff] [blame] | 182 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 183 | if (this.embeddedPayload != null) |
| 184 | matchPayload.addAll(embeddedPayload); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 185 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 186 | if (this.wrapSpans.isPayloadAvailable()) |
| 187 | this.matchPayload.addAll(wrapSpans.getPayload()); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 188 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 189 | if (DEBUG) |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 190 | log.trace(" ---- MATCH ---- {}-{} ({})", matchStart, |
| 191 | matchEnd, matchDoc); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 192 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 193 | this.tryMatch = false; |
| 194 | return true; |
| 195 | } |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 196 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 197 | // Get next embedded |
| 198 | else if (this.nextSpanB) { |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 199 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 200 | // Next time try the match |
| 201 | this.tryMatch = true; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 202 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 203 | if (DEBUG) |
| 204 | log.trace("In the next embedded branch"); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 205 | |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 206 | WithinSpan current = null; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 207 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 208 | // New - fetch until theres a span in the correct doc or bigger |
| 209 | while (!this.spanStore2.isEmpty()) { |
| 210 | current = spanStore2.removeFirst(); |
| 211 | if (current.doc >= this.wrapDoc) |
| 212 | break; |
| 213 | }; |
| 214 | |
| 215 | |
| 216 | // There is nothing in the second store |
| 217 | if (current == null) { |
| 218 | if (DEBUG) |
| 219 | log.trace("SpanStore 2 is empty"); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 220 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 221 | // Forward with embedding |
| 222 | if (!this.embeddedSpans.next()) { |
| Akron | c3a5df8 | 2016-04-29 16:56:53 +0200 | [diff] [blame] | 223 | |
| 224 | // TODO: May need storeEmpdedded |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 225 | this.nextSpanA(); |
| 226 | continue; |
| 227 | } |
| 228 | |
| 229 | else if (DEBUG) { |
| 230 | log.trace("Fetch next embedded span"); |
| 231 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 232 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 233 | this.embeddedStart = this.embeddedSpans.start(); |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 234 | this.embeddedEnd = -1; |
| 235 | this.embeddedPayload = null; |
| 236 | this.embeddedDoc = this.embeddedSpans.doc(); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 237 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 238 | if (this.embeddedDoc != this.wrapDoc) { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 239 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 240 | if (DEBUG) { |
| Akron | c12567c | 2016-06-03 00:40:52 +0200 | [diff] [blame] | 241 | log.trace( |
| 242 | "(A) Embedded span is in a new document {}", |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 243 | _currentEmbedded().toString()); |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 244 | log.trace("Reset current embedded doc"); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 245 | }; |
| 246 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 247 | /* |
| 248 | if (DEBUG) |
| 249 | log.trace("Clear all span stores"); |
| 250 | this.spanStore1.clear(); |
| 251 | this.spanStore2.clear(); |
| 252 | */ |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 253 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 254 | this.storeEmbedded(); |
| 255 | |
| 256 | // That is necessary to backtrack to the last document! |
| 257 | this.inSameDoc = true; |
| 258 | this.embeddedDoc = wrapDoc; |
| 259 | // this.tryMatch = false; // already covered in nextSpanA |
| 260 | |
| 261 | this.nextSpanA(); |
| 262 | continue; |
| 263 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 264 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 265 | if (DEBUG) |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 266 | log.trace(" Forward embedded span to {}", |
| 267 | _currentEmbedded().toString()); |
| 268 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 269 | if (this.embeddedDoc != this.wrapDoc) { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 270 | |
| Akron | c3a5df8 | 2016-04-29 16:56:53 +0200 | [diff] [blame] | 271 | if (DEBUG) { |
| Akron | c12567c | 2016-06-03 00:40:52 +0200 | [diff] [blame] | 272 | log.trace( |
| 273 | "(B) Embedded span is in a new document {}", |
| Akron | c3a5df8 | 2016-04-29 16:56:53 +0200 | [diff] [blame] | 274 | _currentEmbedded().toString()); |
| 275 | log.trace("Reset current embedded doc"); |
| 276 | }; |
| 277 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 278 | // Is this always a good idea? |
| 279 | /* |
| 280 | this.spanStore1.clear(); |
| 281 | this.spanStore2.clear(); |
| 282 | */ |
| 283 | |
| 284 | this.embeddedStart = -1; |
| 285 | this.embeddedEnd = -1; |
| 286 | this.embeddedPayload = null; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 287 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 288 | if (!this.toSameDoc()) { |
| 289 | this.more = false; |
| 290 | this.inSameDoc = false; |
| 291 | return false; |
| 292 | }; |
| 293 | }; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 294 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 295 | this.more = true; |
| 296 | this.inSameDoc = true; |
| 297 | this.tryMatch = true; |
| Akron | 6759b04 | 2016-04-28 01:25:00 +0200 | [diff] [blame] | 298 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 299 | this.nextSpanB(); |
| 300 | continue; |
| 301 | } |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 302 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 303 | // Fetch from second store? |
| 304 | else { |
| Akron | a7b936d | 2016-03-04 13:40:54 +0100 | [diff] [blame] | 305 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 306 | /** TODO: Change this to a single embedded object! */ |
| 307 | this.embeddedStart = current.start; |
| 308 | this.embeddedEnd = current.end; |
| 309 | this.embeddedDoc = current.doc; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 310 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 311 | if (current.payload != null) { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 312 | this.embeddedPayload = new ArrayList<byte[]>( |
| 313 | current.payload.size()); |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 314 | this.embeddedPayload.addAll(current.payload); |
| 315 | } |
| 316 | else { |
| 317 | this.embeddedPayload = null; |
| 318 | }; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 319 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 320 | if (DEBUG) |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 321 | log.trace("Fetch current from SpanStore 2: {}", |
| 322 | current.toString()); |
| 323 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 324 | this.tryMatch = true; |
| 325 | }; |
| 326 | continue; |
| 327 | }; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 328 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 329 | // get next wrap |
| 330 | if (DEBUG) |
| 331 | log.trace("In the next wrap branch"); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 332 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 333 | this.tryMatch = true; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 334 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 335 | if (DEBUG) |
| 336 | log.trace("Try next wrap"); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 337 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 338 | // shift the stored spans |
| 339 | if (!this.spanStore1.isEmpty()) { |
| 340 | if (DEBUG) { |
| 341 | log.trace("Move everything from SpanStore 1 to SpanStore 2:"); |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 342 | for (WithinSpan i : this.spanStore1) { |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 343 | log.trace(" | {}", i.toString()); |
| 344 | }; |
| 345 | }; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 346 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 347 | // Move everything to spanStore2 |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 348 | this.spanStore2.addAll(0, |
| 349 | (LinkedList<WithinSpan>) this.spanStore1.clone()); |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 350 | this.spanStore1.clear(); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 351 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 352 | if (DEBUG) { |
| 353 | log.trace("SpanStore 2 now is:"); |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 354 | for (WithinSpan i : this.spanStore2) { |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 355 | log.trace(" | {}", i.toString()); |
| 356 | }; |
| 357 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 358 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 359 | } |
| 360 | else if (DEBUG) { |
| 361 | log.trace("spanStore 1 is empty"); |
| 362 | }; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 363 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 364 | // Get next wrap |
| 365 | if (this.wrapSpans.next()) { |
| Nils Diewald | 82a4b86 | 2014-02-20 21:17:41 +0000 | [diff] [blame] | 366 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 367 | // Reset wrapping information |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 368 | this.wrapStart = this.wrapSpans.start(); |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 369 | this.wrapEnd = -1; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 370 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 371 | // Retrieve doc information |
| 372 | this.wrapDoc = this.wrapSpans.doc(); |
| Nils Diewald | 20607ab | 2014-03-20 23:28:36 +0000 | [diff] [blame] | 373 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 374 | if (DEBUG) |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 375 | log.trace(" Forward wrap span to {}", _currentWrap() |
| 376 | .toString()); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 377 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 378 | if (this.embeddedDoc != this.wrapDoc) { |
| 379 | if (DEBUG) |
| 380 | log.trace("Delete all span stores"); |
| 381 | this.spanStore1.clear(); |
| 382 | this.spanStore2.clear(); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 383 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 384 | // Reset embedded: |
| 385 | this.embeddedStart = -1; |
| 386 | this.embeddedEnd = -1; |
| 387 | this.embeddedPayload = null; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 388 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 389 | if (!this.toSameDoc()) { |
| 390 | this.inSameDoc = false; |
| 391 | this.more = false; |
| 392 | return false; |
| 393 | }; |
| 394 | } |
| 395 | else { |
| 396 | this.inSameDoc = true; |
| 397 | // Do not match with the current state |
| 398 | this.tryMatch = false; |
| 399 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 400 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 401 | this.nextSpanB(); |
| 402 | continue; |
| 403 | } |
| 404 | this.more = false; |
| 405 | this.inSameDoc = false; |
| 406 | this.spanStore1.clear(); |
| 407 | this.spanStore2.clear(); |
| 408 | return false; |
| 409 | }; |
| Nils Diewald | 82a4b86 | 2014-02-20 21:17:41 +0000 | [diff] [blame] | 410 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 411 | // No more matches |
| 412 | return false; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 413 | }; |
| 414 | |
| 415 | |
| 416 | /** |
| 417 | * Skip to the next document |
| 418 | */ |
| 419 | private boolean toSameDoc () throws IOException { |
| Nils Diewald | 82a4b86 | 2014-02-20 21:17:41 +0000 | [diff] [blame] | 420 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 421 | if (DEBUG) |
| 422 | log.trace("Forward to find same docs"); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 423 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 424 | /* |
| 425 | if (this.embeddedSpans == null) { |
| 426 | this.more = false; |
| 427 | this.matchDoc = DocIdSetIterator.NO_MORE_DOCS; |
| 428 | this.inSameDoc = false; |
| 429 | return false; |
| 430 | }; |
| Akron | 6759b04 | 2016-04-28 01:25:00 +0200 | [diff] [blame] | 431 | */ |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 432 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 433 | this.more = true; |
| 434 | this.inSameDoc = true; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 435 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 436 | this.wrapDoc = this.wrapSpans.doc(); |
| Akron | 40f51ee | 2016-04-22 17:55:14 +0200 | [diff] [blame] | 437 | |
| 438 | // Last doc was reached |
| 439 | if (this.wrapDoc == DocIdSetIterator.NO_MORE_DOCS) { |
| 440 | this.more = false; |
| 441 | this.matchDoc = DocIdSetIterator.NO_MORE_DOCS; |
| 442 | this.inSameDoc = false; |
| 443 | return false; |
| 444 | }; |
| 445 | |
| 446 | // This is just a workaround for an issue that seems to be a bug in Lucene's core code. |
| 447 | try { |
| 448 | this.embeddedDoc = this.embeddedSpans.doc(); |
| 449 | } |
| 450 | catch (NullPointerException e) { |
| 451 | this.more = false; |
| 452 | this.matchDoc = DocIdSetIterator.NO_MORE_DOCS; |
| 453 | this.inSameDoc = false; |
| 454 | return false; |
| 455 | }; |
| Akron | 6759b04 | 2016-04-28 01:25:00 +0200 | [diff] [blame] | 456 | |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 457 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 458 | // Clear all spanStores |
| 459 | if (this.wrapDoc != this.embeddedDoc) { |
| 460 | /* |
| 461 | if (DEBUG) |
| 462 | log.trace("Clear all spanStores when moving forward"); |
| 463 | // Why?? |
| 464 | this.spanStore1.clear(); |
| 465 | this.spanStore2.clear(); |
| 466 | */ |
| 467 | } |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 468 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 469 | else { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 470 | if (DEBUG) { |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 471 | log.trace("Current position already is in the same doc"); |
| 472 | log.trace("Embedded: {}", _currentEmbedded().toString()); |
| 473 | }; |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 474 | this.matchDoc = this.embeddedDoc; |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 475 | return true; |
| 476 | }; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 477 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 478 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 479 | // Forward till match |
| 480 | while (this.wrapDoc != this.embeddedDoc) { |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 481 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 482 | // Forward wrapInfo |
| 483 | if (this.wrapDoc < this.embeddedDoc) { |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 484 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 485 | // Set document information |
| 486 | if (!wrapSpans.skipTo(this.embeddedDoc)) { |
| 487 | this.more = false; |
| 488 | this.inSameDoc = false; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 489 | this.matchDoc = DocIdSetIterator.NO_MORE_DOCS; |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 490 | return false; |
| 491 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 492 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 493 | if (DEBUG) |
| 494 | log.trace("Skip wrap to doc {}", this.embeddedDoc); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 495 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 496 | this.wrapDoc = this.wrapSpans.doc(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 497 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 498 | if (wrapDoc == DocIdSetIterator.NO_MORE_DOCS) { |
| 499 | this.more = false; |
| 500 | this.inSameDoc = false; |
| 501 | this.embeddedDoc = DocIdSetIterator.NO_MORE_DOCS; |
| 502 | this.matchDoc = DocIdSetIterator.NO_MORE_DOCS; |
| 503 | return false; |
| 504 | }; |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 505 | |
| 506 | /* |
| 507 | Remove stored information |
| 508 | */ |
| 509 | if (DEBUG) |
| 510 | log.trace("Delete all span stores"); |
| 511 | |
| 512 | this.spanStore1.clear(); |
| 513 | this.spanStore2.clear(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 514 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 515 | if (wrapDoc == embeddedDoc) { |
| 516 | this.wrapStart = this.wrapSpans.start(); |
| 517 | this.embeddedStart = this.embeddedSpans.start(); |
| 518 | this.matchDoc = this.embeddedDoc; |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 519 | return true; |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 520 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 521 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 522 | this.wrapStart = -1; |
| 523 | this.embeddedStart = -1; |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 524 | } |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 525 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 526 | // Forward embedInfo |
| 527 | else if (this.wrapDoc > this.embeddedDoc) { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 528 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 529 | // Set document information |
| 530 | if (!this.embeddedSpans.skipTo(this.wrapDoc)) { |
| 531 | this.more = false; |
| 532 | this.inSameDoc = false; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 533 | this.matchDoc = DocIdSetIterator.NO_MORE_DOCS; |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 534 | return false; |
| 535 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 536 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 537 | this.embeddedDoc = this.embeddedSpans.doc(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 538 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 539 | if (this.embeddedDoc == DocIdSetIterator.NO_MORE_DOCS) { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 540 | this.more = false; |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 541 | this.inSameDoc = false; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 542 | this.wrapDoc = DocIdSetIterator.NO_MORE_DOCS; |
| 543 | this.matchDoc = DocIdSetIterator.NO_MORE_DOCS; |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 544 | return false; |
| 545 | }; |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 546 | |
| 547 | if (DEBUG) |
| 548 | log.trace("Skip embedded to doc {}", this.embeddedDoc); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 549 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 550 | this.embeddedStart = this.embeddedSpans.start(); |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 551 | this.embeddedEnd = -1; |
| 552 | this.embeddedPayload = null; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 553 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 554 | if (this.wrapDoc == this.embeddedDoc) { |
| 555 | this.matchDoc = this.embeddedDoc; |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 556 | return true; |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 557 | }; |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 558 | } |
| 559 | else { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 560 | this.matchDoc = DocIdSetIterator.NO_MORE_DOCS; |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 561 | return false; |
| 562 | }; |
| 563 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 564 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 565 | this.matchDoc = this.wrapDoc; |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 566 | return true; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 567 | }; |
| 568 | |
| 569 | |
| 570 | // Initialize spans |
| 571 | private boolean init () throws IOException { |
| 572 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 573 | // There is a missing span |
| 574 | if (this.embeddedDoc >= 0) |
| 575 | return true; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 576 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 577 | if (DEBUG) |
| 578 | log.trace("Initialize spans"); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 579 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 580 | // First tick for both spans |
| 581 | if (!(this.embeddedSpans.next() && this.wrapSpans.next())) { |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 582 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 583 | if (DEBUG) |
| 584 | log.trace("No spans initialized"); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 585 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 586 | this.embeddedDoc = -1; |
| 587 | this.more = false; |
| 588 | return false; |
| 589 | }; |
| 590 | this.more = true; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 591 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 592 | // Store current positions for wrapping and embedded spans |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 593 | this.wrapDoc = this.wrapSpans.doc(); |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 594 | this.embeddedDoc = this.embeddedSpans.doc(); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 595 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 596 | // Set inSameDoc to true, if it is true |
| 597 | if (this.embeddedDoc == this.wrapDoc) |
| 598 | this.inSameDoc = true; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 599 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 600 | return true; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 601 | }; |
| 602 | |
| 603 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 604 | /** |
| 605 | * Skips to the first match beyond the current, whose document |
| 606 | * number is |
| 607 | * greater than or equal to <i>target</i>. <p>Returns true iff |
| 608 | * there is such |
| 609 | * a match. <p>Behaves as if written: <pre class="prettyprint"> |
| 610 | * boolean skipTo(int target) { |
| 611 | * do { |
| 612 | * if (!next()) |
| 613 | * return false; |
| 614 | * } while (target > doc()); |
| 615 | * return true; |
| 616 | * } |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 617 | * </pre> |
| 618 | * Most implementations are considerably more efficient than that. |
| 619 | */ |
| 620 | public boolean skipTo (int target) throws IOException { |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 621 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 622 | if (DEBUG) |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 623 | log.trace("skipTo document {}/{} -> {}", this.embeddedDoc, |
| 624 | this.wrapDoc, target); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 625 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 626 | // Initialize spans |
| 627 | if (!this.init()) |
| 628 | return false; |
| Nils Diewald | 82a4b86 | 2014-02-20 21:17:41 +0000 | [diff] [blame] | 629 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 630 | assert target > this.embeddedDoc; |
| Nils Diewald | 82a4b86 | 2014-02-20 21:17:41 +0000 | [diff] [blame] | 631 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 632 | // Only forward embedded spans |
| 633 | if (this.more && (this.embeddedDoc < target)) { |
| 634 | if (this.embeddedSpans.skipTo(target)) { |
| 635 | this.inSameDoc = false; |
| 636 | this.embeddedStart = -1; |
| 637 | this.embeddedEnd = -1; |
| 638 | this.embeddedPayload = null; |
| 639 | this.embeddedDoc = this.embeddedSpans.doc(); |
| 640 | } |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 641 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 642 | // Can't be skipped to target |
| 643 | else { |
| 644 | this.inSameDoc = false; |
| 645 | this.more = false; |
| 646 | return false; |
| 647 | }; |
| 648 | }; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 649 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 650 | // Move to same doc |
| 651 | return this.toSameDoc(); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 652 | }; |
| 653 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 654 | |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 655 | private void nextSpanA () { |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 656 | if (DEBUG) |
| 657 | log.trace("Try wrap next time"); |
| 658 | this.tryMatch = false; |
| 659 | this.nextSpanB = false; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 660 | }; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 661 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 662 | |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 663 | private void nextSpanB () { |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 664 | if (DEBUG) |
| 665 | log.trace("Try embedded next time"); |
| 666 | this.nextSpanB = true; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 667 | }; |
| 668 | |
| 669 | |
| 670 | // Check if the current span constellation does match |
| 671 | // Store backtracking relevant data and say, how to proceed |
| Akron | c3a5df8 | 2016-04-29 16:56:53 +0200 | [diff] [blame] | 672 | private boolean doesMatch () throws IOException { |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 673 | if (DEBUG) |
| 674 | log.trace("In the match test branch"); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 675 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 676 | if (this.wrapStart == -1) |
| 677 | this.wrapStart = this.wrapSpans.start(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 678 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 679 | if (this.embeddedStart == -1) { |
| 680 | this.embeddedStart = this.embeddedSpans.start(); |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 681 | }; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 682 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 683 | this.wrapEnd = -1; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 684 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 685 | // Shortcut to prevent lazyloading of .end() |
| Akron | a7b936d | 2016-03-04 13:40:54 +0100 | [diff] [blame] | 686 | // [--- |
| 687 | // [--- |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 688 | if (this.wrapStart > this.embeddedStart) { |
| 689 | // Can't match for in, rin, ew, sw, and m |
| 690 | // and will always lead to next_b |
| 691 | if (flag >= WITHIN) { |
| 692 | this.nextSpanB(); |
| 693 | if (DEBUG) |
| 694 | _logCurrentCase((byte) 16); |
| 695 | return false; |
| 696 | }; |
| 697 | } |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 698 | |
| Akron | a7b936d | 2016-03-04 13:40:54 +0100 | [diff] [blame] | 699 | // [--- |
| 700 | // [--- |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 701 | else if (this.wrapStart < this.embeddedStart) { |
| 702 | // Can't match for sw and m and will always |
| 703 | // lead to next_a |
| Akron | c3a5df8 | 2016-04-29 16:56:53 +0200 | [diff] [blame] | 704 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 705 | if (flag >= STARTSWITH) { |
| Akron | c3a5df8 | 2016-04-29 16:56:53 +0200 | [diff] [blame] | 706 | if (DEBUG) |
| 707 | log.trace("Shortcut for lazy loading"); |
| 708 | |
| 709 | this.storeEmbedded(); |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 710 | this.nextSpanA(); |
| Akron | c12567c | 2016-06-03 00:40:52 +0200 | [diff] [blame] | 711 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 712 | if (DEBUG) |
| 713 | _logCurrentCase((byte) 15); |
| 714 | return false; |
| 715 | }; |
| 716 | }; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 717 | |
| Akron | 63cd32f | 2016-04-21 17:56:06 +0200 | [diff] [blame] | 718 | if (this.embeddedEnd == -1) { |
| 719 | this.embeddedEnd = this.embeddedSpans.end(); |
| 720 | }; |
| 721 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 722 | // Now check correctly |
| 723 | byte currentCase = this.withinCase(); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 724 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 725 | if (DEBUG) |
| 726 | _logCurrentCase(currentCase); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 727 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 728 | boolean match = false; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 729 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 730 | // Test case |
| 731 | if (currentCase >= (byte) 3 && currentCase <= (byte) 11) { |
| 732 | switch (flag) { |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 733 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 734 | case WITHIN: |
| 735 | if (currentCase >= 6 && currentCase <= 10 |
| 736 | && currentCase != 8) |
| 737 | match = true; |
| 738 | break; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 739 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 740 | case REAL_WITHIN: |
| 741 | if (currentCase == 6 || currentCase == 9 |
| 742 | || currentCase == 10) |
| 743 | match = true; |
| 744 | break; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 745 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 746 | case MATCH: |
| 747 | if (currentCase == 7) |
| 748 | match = true; |
| 749 | break; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 750 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 751 | case STARTSWITH: |
| 752 | if (currentCase == 7 || currentCase == 6) |
| 753 | match = true; |
| 754 | break; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 755 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 756 | case ENDSWITH: |
| 757 | if (currentCase == 7 || currentCase == 10) |
| 758 | match = true; |
| 759 | break; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 760 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 761 | case OVERLAP: |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 762 | match = true; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 763 | break; |
| 764 | |
| 765 | case REAL_OVERLAP: |
| 766 | if (currentCase == 3 || currentCase == 11) |
| 767 | match = true; |
| 768 | break; |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 769 | }; |
| 770 | }; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 771 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 772 | try { |
| 773 | this.todo(currentCase); |
| 774 | } |
| 775 | catch (IOException e) { |
| 776 | return false; |
| 777 | } |
| 778 | return match; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 779 | }; |
| 780 | |
| 781 | |
| 782 | private void _logCurrentCase (byte currentCase) { |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 783 | log.trace("Current Case is {}", currentCase); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 784 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 785 | String _e = _currentEmbedded().toString(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 786 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 787 | log.trace(" |---| {}", _currentWrap().toString()); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 788 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 789 | switch (currentCase) { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 790 | case 1: |
| 791 | log.trace("|-| {}", _e); |
| 792 | break; |
| 793 | case 2: |
| 794 | log.trace("|---| {}", _e); |
| 795 | break; |
| 796 | case 3: |
| 797 | log.trace(" |---| {}", _e); |
| 798 | break; |
| 799 | case 4: |
| 800 | log.trace(" |-----| {}", _e); |
| 801 | break; |
| 802 | case 5: |
| 803 | log.trace(" |-------| {}", _e); |
| 804 | break; |
| 805 | case 6: |
| 806 | log.trace(" |-| {}", _e); |
| 807 | break; |
| 808 | case 7: |
| 809 | log.trace(" |---| {}", _e); |
| 810 | break; |
| 811 | case 8: |
| 812 | log.trace(" |-----| {}", _e); |
| 813 | break; |
| 814 | case 9: |
| 815 | log.trace(" |-| {}", _e); |
| 816 | break; |
| 817 | case 10: |
| 818 | log.trace(" |-| {}", _e); |
| 819 | break; |
| 820 | case 11: |
| 821 | log.trace(" |---| {}", _e); |
| 822 | break; |
| 823 | case 12: |
| 824 | log.trace(" |-| {}", _e); |
| 825 | break; |
| 826 | case 13: |
| 827 | log.trace(" |-| {}", _e); |
| 828 | break; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 829 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 830 | case 15: |
| 831 | // Fake case |
| 832 | log.trace(" |---? {}", _e); |
| 833 | break; |
| 834 | |
| 835 | case 16: |
| 836 | // Fake case |
| 837 | log.trace(" |---? {}", _e); |
| 838 | break; |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 839 | }; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 840 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 841 | |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 842 | |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 843 | private WithinSpan _currentWrap () { |
| 844 | WithinSpan _wrap = new WithinSpan(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 845 | _wrap.start = this.wrapStart != -1 ? this.wrapStart : this.wrapSpans |
| 846 | .start(); |
| 847 | _wrap.end = this.wrapEnd != -1 ? this.wrapEnd : this.wrapSpans.end(); |
| 848 | _wrap.doc = this.wrapDoc != -1 ? this.wrapDoc : this.wrapSpans.doc(); |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 849 | return _wrap; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 850 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 851 | |
| 852 | |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 853 | private WithinSpan _currentEmbedded () { |
| 854 | WithinSpan _embedded = new WithinSpan(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 855 | _embedded.start = this.embeddedStart != -1 ? this.embeddedStart |
| 856 | : this.embeddedSpans.start(); |
| 857 | _embedded.end = this.embeddedEnd != -1 ? this.embeddedEnd |
| 858 | : this.embeddedSpans.end(); |
| 859 | _embedded.doc = this.embeddedDoc != -1 ? this.embeddedDoc |
| 860 | : this.embeddedSpans.doc(); |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 861 | return _embedded; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 862 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 863 | |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 864 | |
| 865 | private void todo (byte currentCase) throws IOException { |
| Akron | c3a5df8 | 2016-04-29 16:56:53 +0200 | [diff] [blame] | 866 | if (DEBUG) { |
| 867 | log.trace("Check what to do next ..."); |
| 868 | }; |
| 869 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 870 | /* |
| 871 | Check what to do next with the spans. |
| 872 | |
| 873 | The different follow up steps are: |
| 874 | - storeEmbedded -> store span B for later checks |
| 875 | - nextSpanA -> forward a |
| 876 | - nextSpanB -> forward b |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 877 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 878 | These rules were automatically generated |
| 879 | */ |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 880 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 881 | // Case 1, 2 |
| 882 | if (currentCase <= (byte) 2) { |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 883 | this.nextSpanB(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | // Case 12, 13 |
| 887 | else if (currentCase >= (byte) 12) { |
| 888 | this.storeEmbedded(); |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 889 | this.nextSpanA(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | // Case 3, 4, 5, 8 |
| 893 | else if (currentCase <= (byte) 5 || currentCase == (byte) 8) { |
| 894 | if (flag <= 2) |
| 895 | this.storeEmbedded(); |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 896 | this.nextSpanB(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | // Case 11 |
| 900 | else if (currentCase == (byte) 11) { |
| 901 | if (this.flag == REAL_WITHIN) { |
| 902 | this.nextSpanB(); |
| 903 | } |
| 904 | else if (this.flag >= STARTSWITH) { |
| Akron | c3a5df8 | 2016-04-29 16:56:53 +0200 | [diff] [blame] | 905 | |
| 906 | // TODO: May need storeEmbedded |
| 907 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 908 | this.nextSpanA(); |
| 909 | } |
| 910 | else { |
| 911 | this.storeEmbedded(); |
| 912 | this.nextSpanB(); |
| 913 | }; |
| 914 | } |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 915 | |
| 916 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 917 | // Case 6, 7, 9, 10 |
| 918 | else { |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 919 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 920 | if ( |
| 921 | // Case 6 |
| 922 | (currentCase == (byte) 6 && this.flag == MATCH) || |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 923 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 924 | // Case 7 |
| 925 | (currentCase == (byte) 7 && this.flag == REAL_WITHIN) || |
| 926 | |
| 927 | // Case 9, 10 |
| 928 | (currentCase >= (byte) 9 && this.flag >= STARTSWITH)) { |
| 929 | |
| Akron | c3a5df8 | 2016-04-29 16:56:53 +0200 | [diff] [blame] | 930 | // TODO: May need storeEmbedded |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 931 | this.nextSpanA(); |
| 932 | } |
| 933 | else { |
| 934 | this.storeEmbedded(); |
| 935 | this.nextSpanB(); |
| 936 | }; |
| 937 | }; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 938 | }; |
| 939 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 940 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 941 | // Store the current embedded span in the first spanStore |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 942 | private void storeEmbedded () throws IOException { |
| 943 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 944 | // Create a current copy |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 945 | WithinSpan embedded = new WithinSpan(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 946 | embedded.start = this.embeddedStart != -1 ? this.embeddedStart |
| 947 | : this.embeddedSpans.start(); |
| 948 | embedded.end = this.embeddedEnd != -1 ? this.embeddedEnd |
| 949 | : this.embeddedSpans.end(); |
| 950 | embedded.doc = this.embeddedDoc; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 951 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 952 | // Copy payloads |
| 953 | if (this.embeddedPayload != null) { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 954 | embedded.payload = new ArrayList<byte[]>( |
| 955 | this.embeddedPayload.size()); |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 956 | embedded.payload.addAll(this.embeddedPayload); |
| 957 | } |
| 958 | else if (this.embeddedSpans.isPayloadAvailable()) { |
| 959 | embedded.payload = new ArrayList<byte[]>(3); |
| 960 | Collection<byte[]> payload = this.embeddedSpans.getPayload(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 961 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 962 | this.embeddedPayload = new ArrayList<byte[]>(payload.size()); |
| 963 | this.embeddedPayload.addAll(payload); |
| 964 | embedded.payload.addAll(payload); |
| 965 | }; |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 966 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 967 | this.spanStore1.add(embedded); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 968 | |
| Nils Diewald | 83c9b16 | 2015-02-03 21:05:07 +0000 | [diff] [blame] | 969 | if (DEBUG) |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 970 | log.trace("Pushed to spanStore 1 {} (in storeEmbedded)", |
| 971 | embedded.toString()); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 972 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 973 | |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 974 | |
| 975 | // Return case number |
| 976 | private byte withinCase () { |
| 977 | |
| Akron | 63cd32f | 2016-04-21 17:56:06 +0200 | [diff] [blame] | 978 | if (DEBUG) { |
| Akron | 6759b04 | 2016-04-28 01:25:00 +0200 | [diff] [blame] | 979 | log.trace(">>>>>>>>>>>>>> {}-{}|{}-{}", this.wrapStart, |
| 980 | this.wrapSpans.end(), this.embeddedStart, |
| 981 | this.embeddedSpans.end()); |
| Akron | 63cd32f | 2016-04-21 17:56:06 +0200 | [diff] [blame] | 982 | }; |
| 983 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 984 | // case 1-5 |
| 985 | if (this.wrapStart > this.embeddedStart) { |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 986 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 987 | // Case 1 |
| 988 | // |-| |
| 989 | // |-| |
| 990 | if (this.wrapStart > this.embeddedEnd) { |
| 991 | return (byte) 1; |
| 992 | } |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 993 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 994 | // Case 2 |
| 995 | // |-| |
| 996 | // |-| |
| 997 | else if (this.wrapStart == this.embeddedEnd) { |
| 998 | return (byte) 2; |
| 999 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1000 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1001 | // Load wrapEnd |
| 1002 | this.wrapEnd = this.wrapSpans.end(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1003 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1004 | // Case 3 |
| 1005 | // |---| |
| 1006 | // |---| |
| 1007 | if (this.wrapEnd > this.embeddedEnd) { |
| 1008 | return (byte) 3; |
| 1009 | } |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 1010 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1011 | // Case 4 |
| 1012 | // |-| |
| 1013 | // |---| |
| 1014 | else if (this.wrapEnd == this.embeddedEnd) { |
| 1015 | return (byte) 4; |
| 1016 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1017 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1018 | // Case 5 |
| 1019 | // |-| |
| 1020 | // |---| |
| 1021 | return (byte) 5; |
| 1022 | } |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1023 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1024 | // case 6-8 |
| 1025 | else if (this.wrapStart == this.embeddedStart) { |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 1026 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1027 | // Load wrapEnd |
| 1028 | this.wrapEnd = this.wrapSpans.end(); |
| Akron | a7b936d | 2016-03-04 13:40:54 +0100 | [diff] [blame] | 1029 | // this.embeddedEnd = this.embeddedSpans.end(); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 1030 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1031 | // Case 6 |
| 1032 | // |---| |
| 1033 | // |-| |
| 1034 | if (this.wrapEnd > this.embeddedEnd) { |
| 1035 | return (byte) 6; |
| 1036 | } |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 1037 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1038 | // Case 7 |
| 1039 | // |---| |
| 1040 | // |---| |
| 1041 | else if (this.wrapEnd == this.embeddedEnd) { |
| 1042 | return (byte) 7; |
| 1043 | }; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1044 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1045 | // Case 8 |
| 1046 | // |-| |
| 1047 | // |---| |
| 1048 | return (byte) 8; |
| 1049 | } |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1050 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1051 | // wrapStart < embeddedStart |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1052 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1053 | // Load wrapEnd |
| 1054 | this.wrapEnd = this.wrapSpans.end(); |
| Nils Diewald | 6802acd | 2014-03-18 18:29:30 +0000 | [diff] [blame] | 1055 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1056 | // Case 13 |
| 1057 | // |-| |
| 1058 | // |-| |
| 1059 | if (this.wrapEnd < this.embeddedStart) { |
| 1060 | return (byte) 13; |
| 1061 | } |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1062 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1063 | // Case 9 |
| 1064 | // |---| |
| 1065 | // |-| |
| 1066 | else if (this.wrapEnd > this.embeddedEnd) { |
| 1067 | return (byte) 9; |
| 1068 | } |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1069 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1070 | // Case 10 |
| 1071 | // |---| |
| 1072 | // |-| |
| 1073 | else if (this.wrapEnd == this.embeddedEnd) { |
| 1074 | return (byte) 10; |
| 1075 | } |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1076 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1077 | // Case 11 |
| 1078 | // |---| |
| 1079 | // |---| |
| 1080 | else if (this.wrapEnd > this.embeddedStart) { |
| 1081 | return (byte) 11; |
| 1082 | } |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1083 | |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1084 | // case 12 |
| 1085 | // |-| |
| 1086 | // |-| |
| 1087 | return (byte) 12; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1088 | }; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1089 | |
| 1090 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1091 | /** |
| 1092 | * Returns the document number of the current match. Initially |
| 1093 | * invalid. |
| 1094 | */ |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1095 | @Override |
| 1096 | public int doc () { |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1097 | return matchDoc; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1098 | }; |
| 1099 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1100 | |
| 1101 | /** |
| 1102 | * Returns the start position of the embedding wrap. Initially |
| 1103 | * invalid. |
| 1104 | */ |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1105 | @Override |
| 1106 | public int start () { |
| Nils Diewald | cd22686 | 2015-02-11 22:27:45 +0000 | [diff] [blame] | 1107 | return matchStart; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1108 | }; |
| 1109 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1110 | |
| 1111 | /** |
| 1112 | * Returns the end position of the embedding wrap. Initially |
| 1113 | * invalid. |
| 1114 | */ |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1115 | @Override |
| 1116 | public int end () { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1117 | return matchEnd; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1118 | }; |
| 1119 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1120 | |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1121 | /** |
| 1122 | * Returns the payload data for the current span. |
| 1123 | * This is invalid until {@link #next()} is called for |
| 1124 | * the first time. |
| 1125 | * This method must not be called more than once after each call |
| 1126 | * of {@link #next()}. However, most payloads are loaded lazily, |
| 1127 | * so if the payload data for the current position is not needed, |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1128 | * this method may not be called at all for performance reasons. |
| 1129 | * An ordered |
| 1130 | * SpanQuery does not lazy load, so if you have payloads in your |
| 1131 | * index and |
| 1132 | * you do not want ordered SpanNearQuerys to collect payloads, you |
| 1133 | * can |
| Nils Diewald | e072501 | 2014-09-25 19:32:52 +0000 | [diff] [blame] | 1134 | * disable collection with a constructor option.<br> |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1135 | * <br> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1136 | * Note that the return type is a collection, thus the ordering |
| 1137 | * should not be relied upon. |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1138 | * <br/> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1139 | * |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1140 | * @lucene.experimental |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1141 | * |
| 1142 | * @return a List of byte arrays containing the data of this |
| 1143 | * payload, otherwise null if isPayloadAvailable is false |
| 1144 | * @throws IOException |
| 1145 | * if there is a low-level I/O error |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1146 | */ |
| 1147 | // public abstract Collection<byte[]> getPayload() throws IOException; |
| 1148 | @Override |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1149 | public Collection<byte[]> getPayload () throws IOException { |
| 1150 | return matchPayload; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1151 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1152 | |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1153 | |
| 1154 | /** |
| 1155 | * Checks if a payload can be loaded at this position. |
| 1156 | * <p/> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1157 | * Payloads can only be loaded once per call to {@link #next()}. |
| 1158 | * |
| 1159 | * @return true if there is a payload available at this position |
| 1160 | * that can be loaded |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1161 | */ |
| 1162 | @Override |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1163 | public boolean isPayloadAvailable () { |
| 1164 | return matchPayload.isEmpty() == false; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1165 | }; |
| 1166 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1167 | |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1168 | // Todo: This may be in the wrong version |
| 1169 | @Override |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1170 | public long cost () { |
| 1171 | return wrapSpans.cost() + embeddedSpans.cost(); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1172 | }; |
| 1173 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1174 | |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1175 | @Override |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1176 | public String toString () { |
| 1177 | return getClass().getName() |
| 1178 | + "(" |
| 1179 | + query.toString() |
| 1180 | + ")@" |
| 1181 | + (embeddedDoc <= 0 ? "START" : (more ? (doc() + ":" + start() |
| 1182 | + "-" + end()) : "END")); |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1183 | }; |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 1184 | |
| 1185 | |
| 1186 | // This was formerly the default candidate span class, |
| 1187 | // before it was refactored out |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1188 | private class WithinSpan implements Comparable<WithinSpan>, Cloneable { |
| 1189 | public int start = -1, end = -1, doc = -1; |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 1190 | |
| 1191 | public Collection<byte[]> payload; |
| 1192 | |
| 1193 | public short elementRef = -1; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1194 | |
| Akron | 6759b04 | 2016-04-28 01:25:00 +0200 | [diff] [blame] | 1195 | |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 1196 | public void clear () { |
| 1197 | this.start = -1; |
| 1198 | this.end = -1; |
| 1199 | this.doc = -1; |
| 1200 | clearPayload(); |
| 1201 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1202 | |
| 1203 | |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 1204 | @Override |
| 1205 | public int compareTo (WithinSpan o) { |
| 1206 | /* optimizable for short numbers to return o.end - this.end */ |
| 1207 | if (this.doc < o.doc) { |
| 1208 | return -1; |
| 1209 | } |
| 1210 | else if (this.doc == o.doc) { |
| 1211 | if (this.start < o.start) { |
| 1212 | return -1; |
| 1213 | } |
| 1214 | else if (this.start == o.start) { |
| 1215 | if (this.end < o.end) |
| 1216 | return -1; |
| 1217 | }; |
| 1218 | }; |
| 1219 | return 1; |
| 1220 | }; |
| 1221 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1222 | |
| 1223 | public short getElementRef () { |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 1224 | return elementRef; |
| 1225 | } |
| 1226 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1227 | |
| 1228 | public void setElementRef (short elementRef) { |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 1229 | this.elementRef = elementRef; |
| 1230 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1231 | |
| 1232 | |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 1233 | @Override |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1234 | public Object clone () { |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 1235 | WithinSpan span = new WithinSpan(); |
| 1236 | span.start = this.start; |
| 1237 | span.end = this.end; |
| 1238 | span.doc = this.doc; |
| 1239 | span.payload.addAll(this.payload); |
| 1240 | return span; |
| 1241 | }; |
| 1242 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1243 | |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 1244 | public WithinSpan copyFrom (WithinSpan o) { |
| 1245 | this.start = o.start; |
| 1246 | this.end = o.end; |
| 1247 | this.doc = o.doc; |
| 1248 | // this.clearPayload(); |
| 1249 | this.payload.addAll(o.payload); |
| 1250 | return this; |
| 1251 | }; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1252 | |
| 1253 | |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 1254 | public void clearPayload () { |
| 1255 | if (this.payload != null) |
| 1256 | this.payload.clear(); |
| 1257 | }; |
| 1258 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1259 | |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 1260 | public String toString () { |
| 1261 | StringBuilder sb = new StringBuilder("["); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 1262 | return sb.append(this.start).append('-').append(this.end) |
| 1263 | .append('(').append(this.doc).append(')').append(']') |
| 1264 | .toString(); |
| Nils Diewald | 41750bf | 2015-02-06 17:45:20 +0000 | [diff] [blame] | 1265 | }; |
| 1266 | }; |
| Nils Diewald | f399a67 | 2013-11-18 17:55:22 +0000 | [diff] [blame] | 1267 | }; |