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