[Bf-blender-cvs] [c0a4c8c3fa6] master: Fix T86891: only sort query results for shortest string if there is a query
Dirk
noreply at git.blender.org
Wed Mar 24 12:55:49 CET 2021
Commit: c0a4c8c3fa68a7343a8444aaf4948f309adec4d6
Author: Dirk
Date: Wed Mar 24 12:53:00 2021 +0100
Branches: master
https://developer.blender.org/rBc0a4c8c3fa68a7343a8444aaf4948f309adec4d6
Fix T86891: only sort query results for shortest string if there is a query
Differential Revision: https://developer.blender.org/D10802
===================================================================
M source/blender/blenlib/intern/string_search.cc
===================================================================
diff --git a/source/blender/blenlib/intern/string_search.cc b/source/blender/blenlib/intern/string_search.cc
index 44baff1f5e3..25a13674932 100644
--- a/source/blender/blenlib/intern/string_search.cc
+++ b/source/blender/blenlib/intern/string_search.cc
@@ -432,9 +432,11 @@ int BLI_string_search_query(StringSearch *search, const char *query, void ***r_d
{
using namespace blender;
+ const StringRef query_str = query;
+
LinearAllocator<> allocator;
Vector<StringRef, 64> query_words;
- string_search::extract_normalized_words(query, allocator, query_words);
+ string_search::extract_normalized_words(query_str, allocator, query_words);
/* Compute score of every result. */
MultiValueMap<int, int> result_indices_by_score;
@@ -457,7 +459,7 @@ int BLI_string_search_query(StringSearch *search, const char *query, void ***r_d
Vector<int> sorted_result_indices;
for (const int score : found_scores) {
MutableSpan<int> indices = result_indices_by_score.lookup(score);
- if (score == found_scores[0]) {
+ if (score == found_scores[0] && !query_str.is_empty()) {
/* Sort items with best score by length. Shorter items are more likely the ones you are
* looking for. This also ensures that exact matches will be at the top, even if the query is
* a substring of another item. */
More information about the Bf-blender-cvs
mailing list