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