Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/string_search.cc
| Show First 20 Lines • Show All 451 Lines • ▼ Show 20 Lines | int BLI_string_search_query(StringSearch *search, const char *query, void ***r_data) | ||||
| } | } | ||||
| std::sort(found_scores.begin(), found_scores.end(), std::greater<>()); | std::sort(found_scores.begin(), found_scores.end(), std::greater<>()); | ||||
| /* Add results to output vector in correct order. First come the results with the best match | /* Add results to output vector in correct order. First come the results with the best match | ||||
| * score. Results with the same score are in the order they have been added to the search. */ | * score. Results with the same score are in the order they have been added to the search. */ | ||||
| Vector<int> sorted_result_indices; | Vector<int> sorted_result_indices; | ||||
| for (const int score : found_scores) { | for (const int score : found_scores) { | ||||
| MutableSpan<int> indices = result_indices_by_score.lookup(score); | MutableSpan<int> indices = result_indices_by_score.lookup(score); | ||||
| if (score == found_scores[0]) { | if (score == found_scores[0] && query != NULL && strlen(query) != 0) { | ||||
| /* Sort items with best score by length. Shorter items are more likely the ones you are | /* 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 | * looking for. This also ensures that exact matches will be at the top, even if the query is | ||||
| * a substring of another item. */ | * a substring of another item. */ | ||||
| std::sort(indices.begin(), indices.end(), [&](int a, int b) { | std::sort(indices.begin(), indices.end(), [&](int a, int b) { | ||||
| return search->items[a].length < search->items[b].length; | return search->items[a].length < search->items[b].length; | ||||
| }); | }); | ||||
| } | } | ||||
| sorted_result_indices.extend(indices); | sorted_result_indices.extend(indices); | ||||
| Show All 19 Lines | |||||