1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

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);
int i = 0; GList *commands = g_hash_table_get_keys(search_index);
for (i = 0; i < terms_len; i++) { GList *curr = commands;
GList *index_keys = g_hash_table_get_keys(search_index); while (curr) {
GList *curr = index_keys; char *command = curr->data;
while (curr) { int matches = 0;
char *index_entry = g_hash_table_lookup(search_index, curr->data); int i = 0;
if (g_str_match_string(processed_terms[i], index_entry, FALSE)) { for (i = 0; i < terms_len; i++) {
results = g_list_append(results, curr->data); char *command_index = g_hash_table_lookup(search_index, command);
if (g_str_match_string(terms[i], command_index, FALSE)) {
matches++;
} }
curr = g_list_next(curr);
} }
g_list_free(index_keys); if (matches == terms_len) {
results = g_list_append(results, command);
}
curr = g_list_next(curr);
} }
g_strfreev(processed_terms); g_list_free(commands);
g_strfreev(terms);
return results; return results;
} }