示例#1
0
/**
 * 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);
}
示例#2
0
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);

}
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);
}
/**
 * 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);
}