Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions core/string/fuzzy_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,20 @@ void FuzzySearch::sort_and_filter(Vector<FuzzySearchResult> &p_results) const {
}

void FuzzySearch::set_query(const String &p_query) {
set_query(p_query, !p_query.is_lowercase());
}

void FuzzySearch::set_query(const String &p_query, bool p_case_sensitive) {
tokens.clear();
case_sensitive = p_case_sensitive;

for (const String &string : p_query.split(" ", false)) {
tokens.append({ static_cast<int>(tokens.size()), string });
tokens.append({
static_cast<int>(tokens.size()),
p_case_sensitive ? string : string.to_lower(),
});
}

case_sensitive = !p_query.is_lowercase();

struct TokenComparator {
bool operator()(const FuzzySearchToken &A, const FuzzySearchToken &B) const {
if (A.string.length() == B.string.length()) {
Expand Down
3 changes: 2 additions & 1 deletion core/string/fuzzy_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,17 @@ class FuzzySearchResult {
class FuzzySearch {
Vector<FuzzySearchToken> tokens;

bool case_sensitive = false;
void sort_and_filter(Vector<FuzzySearchResult> &p_results) const;

public:
int start_offset = 0;
bool case_sensitive = false;
int max_results = 100;
int max_misses = 2;
bool allow_subsequences = true;

void set_query(const String &p_query);
void set_query(const String &p_query, bool p_case_sensitive);
bool search(const String &p_target, FuzzySearchResult &p_result) const;
void search_all(const PackedStringArray &p_targets, Vector<FuzzySearchResult> &p_results) const;
};