mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-24 05: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;
|
this.startsEnds = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean intersects(IntIterator positionsIter) {
|
public int countIntersections(IntIterator positionsIter) {
|
||||||
if (null == startsEnds || !positionsIter.hasNext()) {
|
if (null == startsEnds || !positionsIter.hasNext()) {
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var iter = startsEnds.iterator();
|
var iter = startsEnds.iterator();
|
||||||
int start = -1;
|
int start = -1;
|
||||||
int end = -1;
|
int end = -1;
|
||||||
|
|
||||||
|
int cnt = 0;
|
||||||
while (iter.hasNext() && positionsIter.hasNext()) {
|
while (iter.hasNext() && positionsIter.hasNext()) {
|
||||||
if (start < 0) {
|
if (start < 0) {
|
||||||
start = iter.nextInt();
|
start = iter.nextInt();
|
||||||
@ -38,13 +39,13 @@ public class DocumentSpan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (position < end) {
|
if (position < end) {
|
||||||
return true;
|
cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
start = -1;
|
start = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsPosition(int position) {
|
public boolean containsPosition(int position) {
|
||||||
|
@ -245,9 +245,6 @@ public class IndexResultScoreCalculator {
|
|||||||
if (positions[i] != null && ctx.regularMask.get(i)) {
|
if (positions[i] != null && ctx.regularMask.get(i)) {
|
||||||
searchableKeywordsCount ++;
|
searchableKeywordsCount ++;
|
||||||
|
|
||||||
boolean titleMatch = false;
|
|
||||||
boolean headingMatch = false;
|
|
||||||
|
|
||||||
IntList positionValues = positions[i].values();
|
IntList positionValues = positions[i].values();
|
||||||
|
|
||||||
for (int idx = 0; idx < positionValues.size(); idx++) {
|
for (int idx = 0; idx < positionValues.size(); idx++) {
|
||||||
@ -255,28 +252,26 @@ public class IndexResultScoreCalculator {
|
|||||||
firstPosition = Math.max(firstPosition, pos);
|
firstPosition = Math.max(firstPosition, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spans.title.intersects(positionValues.iterator())) {
|
int cnt;
|
||||||
titleMatch = true;
|
if ((cnt = spans.title.countIntersections(positionValues.iterator())) != 0) {
|
||||||
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) {
|
|
||||||
unorderedMatchInTitleCount++;
|
unorderedMatchInTitleCount++;
|
||||||
|
weightedCounts[i] += 2.5f * cnt;
|
||||||
}
|
}
|
||||||
if (headingMatch) {
|
if ((cnt = spans.heading.countIntersections(positionValues.iterator())) != 0) {
|
||||||
unorderedMatchInHeadingCount++;
|
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