From ee49c01d8663451c8200e998087cfb79283ecf82 Mon Sep 17 00:00:00 2001 From: Viktor Lofgren Date: Sat, 3 Aug 2024 14:47:23 +0200 Subject: [PATCH] (index) Tune ranking for verbatim matches in the title, rewarding shorter titles --- .../index/results/IndexResultScoreCalculator.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/code/index/java/nu/marginalia/index/results/IndexResultScoreCalculator.java b/code/index/java/nu/marginalia/index/results/IndexResultScoreCalculator.java index 74895cf2..aa414c1e 100644 --- a/code/index/java/nu/marginalia/index/results/IndexResultScoreCalculator.java +++ b/code/index/java/nu/marginalia/index/results/IndexResultScoreCalculator.java @@ -197,7 +197,7 @@ public class IndexResultScoreCalculator { temporalBias = 0; } - final int titleLength = spans.title.length(); + final int titleLength = Math.max(1, spans.title.length()); float coherenceScore = 0.f; @@ -246,7 +246,9 @@ public class IndexResultScoreCalculator { coherenceScore = 0.75f * largestOptional; } - coherenceScore += (float) Math.pow(coherences.countOptional(positions) / (double) coherences.numOptional(), 2); + if (coherences.numOptional() > 0) { + coherenceScore += (float) Math.pow(coherences.countOptional(positions) / (double) coherences.numOptional(), 2); + } float[] weightedCounts = new float[compiledQuery.size()]; int firstPosition = Integer.MAX_VALUE;