Match all terms on help search

This commit is contained in:
James Booth
2017-04-07 00:36:36 +01:00
parent 6cba96fdd1
commit a39440b61d

View File

@@ -2319,24 +2319,29 @@ cmd_search_index(char *term)
{ {
GList *results = NULL; GList *results = NULL;
gchar **processed_terms = g_str_tokenize_and_fold(term, NULL, NULL); gchar **terms = g_str_tokenize_and_fold(term, NULL, NULL);
int terms_len = g_strv_length(processed_terms); int terms_len = g_strv_length(terms);
GList *commands = g_hash_table_get_keys(search_index);
GList *curr = commands;
while (curr) {
char *command = curr->data;
int matches = 0;
int i = 0; int i = 0;
for (i = 0; i < terms_len; i++) { for (i = 0; i < terms_len; i++) {
GList *index_keys = g_hash_table_get_keys(search_index); char *command_index = g_hash_table_lookup(search_index, command);
GList *curr = index_keys; if (g_str_match_string(terms[i], command_index, FALSE)) {
while (curr) { matches++;
char *index_entry = g_hash_table_lookup(search_index, curr->data); }
if (g_str_match_string(processed_terms[i], index_entry, FALSE)) { }
results = g_list_append(results, curr->data); if (matches == terms_len) {
results = g_list_append(results, command);
} }
curr = g_list_next(curr); curr = g_list_next(curr);
} }
g_list_free(index_keys);
}
g_strfreev(processed_terms); g_list_free(commands);
g_strfreev(terms);
return results; return results;
} }