mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-23 13:09:00 +00:00
(index) Correct off-by-1 error in DocumentSpan.containsRange
This commit is contained in:
parent
f09669a5b0
commit
d919179ba3
@ -107,7 +107,7 @@ public class DocumentSpan {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (position + len < end) {
|
||||
if (position + len <= end) {
|
||||
return true;
|
||||
} else if (sei + 2 < startsEnds.size()) {
|
||||
start = startsEnds.getInt(sei++);
|
||||
@ -198,6 +198,8 @@ public class DocumentSpan {
|
||||
var iter = startsEnds.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
// The length of each span is b - a; but we receive them in the order a b;
|
||||
// thus we subtract the start from the length and add the end
|
||||
len -= iter.nextInt();
|
||||
len += iter.nextInt();
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package nu.marginalia.index.forward;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import nu.marginalia.index.forward.spans.ForwardIndexSpansReader;
|
||||
import nu.marginalia.index.forward.spans.ForwardIndexSpansWriter;
|
||||
import nu.marginalia.language.sentence.tag.HtmlTag;
|
||||
@ -37,9 +38,10 @@ class ForwardIndexSpansReaderTest {
|
||||
writer.writeSpan(HtmlTag.HEADING.code, VarintCodedSequence.generate(1, 3, 5, 8).buffer());
|
||||
offset1 = writer.endRecord();
|
||||
|
||||
writer.beginRecord(2);
|
||||
writer.beginRecord(3);
|
||||
writer.writeSpan(HtmlTag.CODE.code, VarintCodedSequence.generate(2, 4, 6, 7).buffer());
|
||||
writer.writeSpan(HtmlTag.ANCHOR.code, VarintCodedSequence.generate(3, 5).buffer());
|
||||
writer.writeSpan(HtmlTag.NAV.code, VarintCodedSequence.generate(1, 3).buffer());
|
||||
offset2 = writer.endRecord();
|
||||
}
|
||||
|
||||
@ -60,6 +62,10 @@ class ForwardIndexSpansReaderTest {
|
||||
assertFalse(spans2.code.containsPosition(7));
|
||||
assertFalse(spans2.code.containsPosition(8));
|
||||
|
||||
assertTrue(spans2.nav.containsRange(IntList.of(1), 2));
|
||||
assertTrue(spans2.nav.containsRange(IntList.of(2), 1));
|
||||
assertTrue(spans2.nav.containsPosition(1));
|
||||
|
||||
assertEquals(1, spans2.anchor.size());
|
||||
|
||||
assertEquals(0, spans2.title.size());
|
||||
|
Loading…
Reference in New Issue
Block a user