Merge lp:~mhr3/unity-lens-applications/ascii-fold-app-data into lp:unity-lens-applications

Proposed by Michal Hruby
Status: Merged
Approved by: Gord Allott
Approved revision: 265
Merged at revision: 265
Proposed branch: lp:~mhr3/unity-lens-applications/ascii-fold-app-data
Merge into: lp:unity-lens-applications
Diff against target: 99 lines (+37/-8)
2 files modified
src/unity-package-search.cc (+18/-6)
src/utils.vala (+19/-2)
To merge this branch: bzr merge lp:~mhr3/unity-lens-applications/ascii-fold-app-data
Reviewer Review Type Date Requested Status
Gord Allott (community) Approve
Review via email: mp+93217@code.launchpad.net

Description of the change

Ascii fold application data to make it easier to search.

To post a comment you must log in.
Revision history for this message
Gord Allott (gordallott) wrote :

+1 looks good here

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity-package-search.cc'
2--- src/unity-package-search.cc 2012-01-24 15:48:18 +0000
3+++ src/unity-package-search.cc 2012-02-15 14:56:48 +0000
4@@ -54,7 +54,7 @@
5
6 extern "C"
7 {
8-extern gchar* unity_applications_lens_utils_uncamelcase (const gchar* input);
9+extern gchar* unity_applications_lens_utils_preprocess_string (const gchar* input);
10 }
11
12 struct _UnityPackageSearcher
13@@ -175,15 +175,25 @@
14 indexer->set_document(doc);
15 if (gmenu_tree_entry_get_display_name (entry))
16 {
17- dum1 = unity_applications_lens_utils_uncamelcase (
18+ dum1 = unity_applications_lens_utils_preprocess_string (
19 gmenu_tree_entry_get_display_name (entry));
20 indexer->index_text(dum1, 5);
21 g_free (dum1);
22 }
23 if (gmenu_tree_entry_get_name (entry))
24- indexer->index_text(gmenu_tree_entry_get_name (entry), 5);
25+ {
26+ dum1 = unity_applications_lens_utils_preprocess_string (
27+ gmenu_tree_entry_get_name (entry));
28+ indexer->index_text(dum1, 5);
29+ g_free (dum1);
30+ }
31 if (gmenu_tree_entry_get_comment (entry))
32- indexer->index_text(gmenu_tree_entry_get_comment (entry), 0);
33+ {
34+ dum1 = unity_applications_lens_utils_preprocess_string (
35+ gmenu_tree_entry_get_comment (entry));
36+ indexer->index_text (dum1, 0);
37+ g_free (dum1);
38+ }
39
40 /* Index the XDG categories */
41 appman = unity_app_info_manager_get_default ();
42@@ -209,8 +219,10 @@
43 &len);
44 for (i = 0; i < len; i++)
45 {
46- indexer->index_text (keywords[i], 3);
47- indexer->index_text (keywords[i], 3, "KW");
48+ dum1 = unity_applications_lens_utils_preprocess_string (keywords[i]);
49+ indexer->index_text (dum1, 3);
50+ indexer->index_text (dum1, 3, "KW");
51+ g_free (dum1);
52 }
53
54
55
56=== modified file 'src/utils.vala'
57--- src/utils.vala 2012-01-24 15:48:18 +0000
58+++ src/utils.vala 2012-02-15 14:56:48 +0000
59@@ -69,13 +69,30 @@
60 * .desktop file */
61 return actor;
62 }
63-
64+
65 public bool is_search_empty (Unity.LensSearch search)
66 {
67 if (search.search_string == null) return true;
68 return search.search_string == "";
69 }
70
71+ private static Dee.ICUTermFilter icu_filter;
72+
73+ public string preprocess_string (string text)
74+ {
75+ if (icu_filter == null)
76+ {
77+ icu_filter = new Dee.ICUTermFilter.ascii_folder ();
78+ }
79+
80+ var uncamelcased = uncamelcase (text);
81+ var folded = icu_filter.apply (uncamelcased);
82+
83+ if (uncamelcased == folded) return uncamelcased;
84+
85+ return "%s\n%s".printf (uncamelcased, folded);
86+ }
87+
88 private static Regex camelcase_matcher;
89
90 public string uncamelcase (string text)
91@@ -86,7 +103,7 @@
92 {
93 // 1+ upper characters followed by 1+ non-upper
94 // (but preceded by non-upper or start of the string)
95- camelcase_matcher = new Regex ("(?<=^|[^[:upper:]])[[:upper:]]+[^[:upper:]]+",
96+ camelcase_matcher = new Regex ("(?<=^|[^[:upper:]\\s])[[:upper:]]+[^[:upper:]]+",
97 RegexCompileFlags.OPTIMIZE);
98 }
99 catch (Error e) { warning ("%s", e.message); }

Subscribers

People subscribed via source and target branches