Skip to content

Commit

Permalink
fix divide by zero error
Browse files Browse the repository at this point in the history
  • Loading branch information
samsface committed Sep 27, 2024
1 parent 81e4ed0 commit d95b3e9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion editor/fuzzy_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "scene/gui/tree.h"

const int max_results = 100;
const float cull_factor = 0.5f;

Vector<int> FuzzySearchResult::get_matches() const {
Vector<int> matches_array;
Expand Down Expand Up @@ -97,6 +98,10 @@ PackedStringArray get_query(const String &p_query) {
Vector<Ref<FuzzySearchResult>> sort_and_filter(const Vector<Ref<FuzzySearchResult>> &p_results) {
Vector<Ref<FuzzySearchResult>> res;

if (p_results.is_empty()) {
return res;
}

float total_score = 0;
for (const Ref<FuzzySearchResult> &result : p_results) {
total_score += result->score;
Expand All @@ -112,7 +117,7 @@ Vector<Ref<FuzzySearchResult>> sort_and_filter(const Vector<Ref<FuzzySearchResul

// Prune low score entries before even sorting
for (Ref<FuzzySearchResult> i : p_results) {
if (i->score >= mean_score * 0.5) {
if (i->score >= mean_score * cull_factor) {
res.push_back(i);
}

Expand Down

0 comments on commit d95b3e9

Please sign in to comment.