mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-23 21:18:58 +00:00
(index) Correct weightedCounts calculations
This commit is contained in:
parent
6dda2c2d83
commit
63e5b0ab18
@ -17,15 +17,16 @@ public class DocumentSpan {
|
||||
this.startsEnds = null;
|
||||
}
|
||||
|
||||
public boolean intersects(IntIterator positionsIter) {
|
||||
public int countIntersections(IntIterator positionsIter) {
|
||||
if (null == startsEnds || !positionsIter.hasNext()) {
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
var iter = startsEnds.iterator();
|
||||
int start = -1;
|
||||
int end = -1;
|
||||
|
||||
int cnt = 0;
|
||||
while (iter.hasNext() && positionsIter.hasNext()) {
|
||||
if (start < 0) {
|
||||
start = iter.nextInt();
|
||||
@ -38,13 +39,13 @@ public class DocumentSpan {
|
||||
}
|
||||
|
||||
if (position < end) {
|
||||
return true;
|
||||
cnt++;
|
||||
}
|
||||
|
||||
start = -1;
|
||||
}
|
||||
|
||||
return false;
|
||||
return cnt;
|
||||
}
|
||||
|
||||
public boolean containsPosition(int position) {
|
||||
|
@ -245,9 +245,6 @@ public class IndexResultScoreCalculator {
|
||||
if (positions[i] != null && ctx.regularMask.get(i)) {
|
||||
searchableKeywordsCount ++;
|
||||
|
||||
boolean titleMatch = false;
|
||||
boolean headingMatch = false;
|
||||
|
||||
IntList positionValues = positions[i].values();
|
||||
|
||||
for (int idx = 0; idx < positionValues.size(); idx++) {
|
||||
@ -255,28 +252,26 @@ public class IndexResultScoreCalculator {
|
||||
firstPosition = Math.max(firstPosition, pos);
|
||||
}
|
||||
|
||||
if (spans.title.intersects(positionValues.iterator())) {
|
||||
titleMatch = true;
|
||||
weightedCounts[i] += 2.5f;
|
||||
}
|
||||
else if (spans.heading.intersects(positionValues.iterator())) {
|
||||
headingMatch = true;
|
||||
weightedCounts[i] += 2.5f;
|
||||
}
|
||||
else if (spans.code.intersects(positionValues.iterator()))
|
||||
weightedCounts[i] += 0.25f;
|
||||
else if (spans.anchor.intersects(positionValues.iterator()))
|
||||
weightedCounts[i] += 0.2f;
|
||||
else if (spans.nav.intersects(positionValues.iterator()))
|
||||
weightedCounts[i] += 0.1f;
|
||||
else
|
||||
weightedCounts[i] += 1.0f;
|
||||
|
||||
if (titleMatch) {
|
||||
int cnt;
|
||||
if ((cnt = spans.title.countIntersections(positionValues.iterator())) != 0) {
|
||||
unorderedMatchInTitleCount++;
|
||||
weightedCounts[i] += 2.5f * cnt;
|
||||
}
|
||||
if (headingMatch) {
|
||||
if ((cnt = spans.heading.countIntersections(positionValues.iterator())) != 0) {
|
||||
unorderedMatchInHeadingCount++;
|
||||
weightedCounts[i] += 2.5f * cnt;
|
||||
}
|
||||
if ((cnt = spans.code.countIntersections(positionValues.iterator())) != 0) {
|
||||
weightedCounts[i] += 0.25f * cnt;
|
||||
}
|
||||
if ((cnt = spans.anchor.countIntersections(positionValues.iterator())) != 0) {
|
||||
weightedCounts[i] += 0.2f * cnt;
|
||||
}
|
||||
if ((cnt = spans.nav.countIntersections(positionValues.iterator())) != 0) {
|
||||
weightedCounts[i] += 0.1f * cnt;
|
||||
}
|
||||
if ((cnt = spans.body.countIntersections(positionValues.iterator())) != 0) {
|
||||
weightedCounts[i] += 1.0f * cnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user