Skip to content

Commit

Permalink
Fix potential error by adding optional chaining for bestScore in sear…
Browse files Browse the repository at this point in the history
…chDocuments function
  • Loading branch information
joao-vasconcelos committed Dec 16, 2024
1 parent 97c05e2 commit 4376dca
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion frontend/hooks/useOtherSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ function searchDocuments<T extends SearchableDocument<T>>(
const sortedScoreDocs = scoredDocs.sort((a, b) => b.score - a.score);

// Filter out documents with a score less than half of the top score
const bestScore = sortedScoreDocs[0].score;
const bestScore = sortedScoreDocs[0]?.score;
const filteredScoreDocs = sortedScoreDocs.filter(scoredDoc => scoredDoc.score > Math.floor(bestScore / options.threshold) || bestScore === 0);

// If top score is 0, we filter out all documents
Expand Down

0 comments on commit 4376dca

Please sign in to comment.