Skip to content
Prev Previous commit
Next Next commit
fix(search): use numeric for-loop instead of for-in on positions array
for (var i in positions) yields string keys ("0", "1", ...),
causing j = i + 1 to produce "01" (string concatenation) instead
of 1 (numeric addition). This made the inner while-loop skip
positions[1] for i=0 and exit immediately for all other starting
indices, so the algorithm always selected the first match's window
regardless of where the densest cluster was.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
  • Loading branch information
xr843 and claude committed Mar 22, 2026
commit 8a1e6d5b6db835eec52bc37d7e394debe6d22922
2 changes: 1 addition & 1 deletion assets/js/search_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function getBlurbForResult(result, item, positions) {
// Calculate the best section of the content to blurb
var best_i = -1;
var best_n = 0;
for (var i in positions) {
for (var i = 0; i < positions.length; i++) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! This is why I asked for the flipped test. I had a feeling there was a bug! 😁

var n = 1;
var j = i+1;
while (j < positions.length) {
Expand Down