static GSList * search_tree (ShellAppSystem *self, GSList *terms, GHashTable *apps) { GSList *prefix_results = NULL; GSList *substring_results = NULL; GSList *normalized_terms; GHashTableIter iter; gpointer key, value; normalized_terms = normalize_terms (terms); g_hash_table_iter_init (&iter, apps); while (g_hash_table_iter_next (&iter, &key, &value)) { const char *id = key; ShellApp *app = value; (void)id; _shell_app_do_match (app, normalized_terms, &prefix_results, &substring_results); } g_slist_free_full (normalized_terms, g_free); return sort_and_concat_results (self, prefix_results, substring_results); }
/** * shell_app_system_subsearch: * @system: A #ShellAppSystem * @previous_results: (element-type ShellApp): List of previous results * @terms: (element-type utf8): List of terms, logical AND * * Search through a previous result set; for more information, see * js/ui/search.js. Note the value of @prefs must be * the same as passed to shell_app_system_initial_search(). Note that returned * strings are only valid until a return to the main loop. * * Returns: (transfer container) (element-type ShellApp): List of application identifiers */ GSList * shell_app_system_subsearch (ShellAppSystem *system, GSList *previous_results, GSList *terms) { GSList *iter; GSList *prefix_results = NULL; GSList *substring_results = NULL; GSList *normalized_terms = normalize_terms (terms); for (iter = previous_results; iter; iter = iter->next) { ShellApp *app = iter->data; _shell_app_do_match (app, normalized_terms, &prefix_results, &substring_results); } g_slist_free_full (normalized_terms, g_free); /* Note that a shorter term might have matched as a prefix, but when extended only as a substring, so we have to redo the sort rather than reusing the existing ordering */ return sort_and_concat_results (system, prefix_results, substring_results); }
/** * cinnamon_app_system_subsearch: * @system: A #CinnamonAppSystem * @previous_results: (element-type CinnamonApp): List of previous results * @terms: (element-type utf8): List of terms, logical AND * * Search through a previous result set; for more information, see * js/ui/search.js. Note the value of @prefs must be * the same as passed to cinnamon_app_system_initial_search(). Note that returned * strings are only valid until a return to the main loop. * * Returns: (transfer container) (element-type CinnamonApp): List of application identifiers */ GSList * cinnamon_app_system_subsearch (CinnamonAppSystem *system, GSList *previous_results, GSList *terms) { GSList *iter; GSList *prefix_results = NULL; GSList *substring_results = NULL; GSList *normalized_terms = normalize_terms (terms); for (iter = previous_results; iter; iter = iter->next) { CinnamonApp *app = iter->data; _cinnamon_app_do_match (app, normalized_terms, &prefix_results, &substring_results); } g_slist_foreach (normalized_terms, (GFunc)g_free, NULL); g_slist_free (normalized_terms); /* Note that a shorter term might have matched as a prefix, but when extended only as a substring, so we have to redo the sort rather than reusing the existing ordering */ return g_slist_concat (prefix_results, substring_results); }
static GSList * search_tree (CinnamonAppSystem *self, GSList *terms, GHashTable *apps) { GSList *prefix_results = NULL; GSList *substring_results = NULL; GSList *normalized_terms; GHashTableIter iter; gpointer key, value; normalized_terms = normalize_terms (terms); g_hash_table_iter_init (&iter, apps); while (g_hash_table_iter_next (&iter, &key, &value)) { const char *id = key; CinnamonApp *app = value; (void)id; _cinnamon_app_do_match (app, normalized_terms, &prefix_results, &substring_results); } g_slist_foreach (normalized_terms, (GFunc)g_free, NULL); g_slist_free (normalized_terms); return g_slist_concat (prefix_results, substring_results); }
static GSList * shell_app_system_initial_search_internal (ShellAppSystem *self, GSList *terms, GSList *source) { GSList *multiple_prefix_results = NULL; GSList *prefix_results = NULL; GSList *multiple_subtring_results = NULL; GSList *substring_results = NULL; GSList *iter; GSList *normalized_terms = normalize_terms (terms); for (iter = source; iter; iter = iter->next) { ShellAppInfo *info = iter->data; shell_app_system_do_match (self, info, normalized_terms, &multiple_prefix_results, &prefix_results, &multiple_subtring_results, &substring_results); } g_slist_foreach (normalized_terms, (GFunc)g_free, NULL); g_slist_free (normalized_terms); return sort_and_concat_results (self, multiple_prefix_results, prefix_results, multiple_subtring_results, substring_results); }
/** * cinnamon_contact_system_initial_search: * @cinnamon: A #CinnamonContactSystem * @terms: (element-type utf8): List of terms, logical AND * * Search through contacts for the given search terms. * * Returns: (transfer container) (element-type utf8): List of contact * identifiers */ GSList * cinnamon_contact_system_initial_search (CinnamonContactSystem *self, GSList *terms) { FolksIndividual *individual; GSList *results = NULL; GeeMap *individuals = NULL; ContactSearchResult *result; GeeMapIterator *iter; gpointer key; guint weight; GSList *normalized_terms = normalize_terms (terms); g_return_val_if_fail (CINNAMON_IS_CONTACT_SYSTEM (self), NULL); individuals = folks_individual_aggregator_get_individuals (self->priv->aggregator); iter = gee_map_map_iterator (individuals); while (gee_map_iterator_next (iter)) { individual = gee_map_iterator_get_value (iter); weight = do_match (self, individual, normalized_terms); if (weight != 0) { key = gee_map_iterator_get_key (iter); result = g_slice_new (ContactSearchResult); result->key = (gchar *) key; result->weight = weight; results = g_slist_append (results, result); } g_object_unref (individual); } return sort_and_prepare_results (results); }
/** * shell_app_system_subsearch: * @system: A #ShellAppSystem * @prefs: %TRUE if we should search preferences instead of apps * @previous_results: (element-type utf8): List of previous results * @terms: (element-type utf8): List of terms, logical AND * * Search through a previous result set; for more information, see * js/ui/search.js. Note the value of @prefs must be * the same as passed to shell_app_system_initial_search(). Note that returned * strings are only valid until a return to the main loop. * * Returns: (transfer container) (element-type utf8): List of application identifiers */ GSList * shell_app_system_subsearch (ShellAppSystem *system, gboolean prefs, GSList *previous_results, GSList *terms) { GSList *iter; GSList *multiple_prefix_results = NULL; GSList *prefix_results = NULL; GSList *multiple_substring_results = NULL; GSList *substring_results = NULL; GSList *normalized_terms = normalize_terms (terms); /* Note prefs is deliberately ignored; both apps and prefs are in app_id_to_app, * but we have the parameter for consistency and in case in the future * they're not in the same data structure. */ for (iter = previous_results; iter; iter = iter->next) { const char *id = iter->data; ShellAppInfo *info; info = g_hash_table_lookup (system->priv->app_id_to_info, id); if (!info) continue; shell_app_system_do_match (system, info, normalized_terms, &multiple_prefix_results, &prefix_results, &multiple_substring_results, &substring_results); } g_slist_foreach (normalized_terms, (GFunc)g_free, NULL); g_slist_free (normalized_terms); /* Note that a shorter term might have matched as a prefix, but when extended only as a substring, so we have to redo the sort rather than reusing the existing ordering */ return sort_and_concat_results (system, multiple_prefix_results, prefix_results, multiple_substring_results, substring_results); }