Merge lp:~mhr3/unity-lens-applications/camelcase-friendly-index into lp:unity-lens-applications

Proposed by Michal Hruby
Status: Merged
Approved by: Mikkel Kamstrup Erlandsen
Approved revision: 263
Merged at revision: 261
Proposed branch: lp:~mhr3/unity-lens-applications/camelcase-friendly-index
Merge into: lp:unity-lens-applications
Diff against target: 233 lines (+70/-28)
8 files modified
TESTS-TODO.txt (+3/-0)
configure.ac (+1/-0)
src/Makefile.am (+2/-2)
src/daemon.vala (+7/-13)
src/runner.vala (+1/-1)
src/unity-package-search.cc (+12/-2)
src/unity-ratings-db.c (+1/-1)
src/utils.vala (+43/-9)
To merge this branch: bzr merge lp:~mhr3/unity-lens-applications/camelcase-friendly-index
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+89926@code.launchpad.net

Description of the change

Split CamelCase words from application names before feeding them to xapian, which allows us to search for any part of the name.

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Looks good and manual testing confirms that this works. Before I approve it can you queue a testcase in TESTS-TODO.txt?

review: Needs Fixing
Revision history for this message
Michal Hruby (mhr3) wrote :

Done.

263. By Michal Hruby

Add test desciption

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'TESTS-TODO.txt'
2--- TESTS-TODO.txt 2012-01-19 12:12:06 +0000
3+++ TESTS-TODO.txt 2012-01-25 08:25:28 +0000
4@@ -10,5 +10,8 @@
5 2) Start a search with non-sensical string and check that it returns 0 results
6 and that the "no-results-hint" is set in the method reply.
7
8+3) Make sure it's possible to search for CamelCase apps by searching "case",
9+ plus this should properly work with accented characters as well.
10+
11 More to come...
12
13
14=== modified file 'configure.ac'
15--- configure.ac 2012-01-12 15:29:22 +0000
16+++ configure.ac 2012-01-25 08:25:28 +0000
17@@ -18,6 +18,7 @@
18 AM_PROG_VALAC([0.12.1])
19 AS_IF([test -z "$VALAC"], [AC_MSG_ERROR(["No valac compiler found."])])
20 AC_PROG_CC
21+AC_PROG_CXX
22 AM_PROG_CC_C_O
23 AC_HEADER_STDC
24 AC_LANG([C++])
25
26=== modified file 'src/Makefile.am'
27--- src/Makefile.am 2012-01-18 17:02:52 +0000
28+++ src/Makefile.am 2012-01-25 08:25:28 +0000
29@@ -61,10 +61,10 @@
30 $(NULL)
31
32 unity-package-search.o : $(srcdir)/unity-package-search.cc $(srcdir)/unity-package-search.h
33- g++ -g $(unity_package_search_libs) -DGMENU_I_KNOW_THIS_IS_UNSTABLE `pkg-config --cflags --libs glib-2.0 libgnome-menu unity gee-1.0` -c $(srcdir)/unity-package-search.cc
34+ $(AM_V_GEN)$(CXX) -g $(unity_package_search_libs) -DGMENU_I_KNOW_THIS_IS_UNSTABLE `pkg-config --cflags --libs glib-2.0 libgnome-menu unity gee-1.0` -c $(srcdir)/unity-package-search.cc
35
36 unity-ratings-db.o : $(srcdir)/unity-ratings-db.c $(srcdir)/unity-ratings-db.h
37- gcc -g $(unity_ratings_db_libs) `pkg-config --cflags --libs glib-2.0` -c $(srcdir)/unity-ratings-db.c
38+ $(AM_V_CC)$(CC) -g $(unity_ratings_db_libs) `pkg-config --cflags --libs glib-2.0` -c $(srcdir)/unity-ratings-db.c
39
40 unity_applications_daemon_SOURCES = \
41 $(unity_applications_daemon_VALASOURCES:.vala=.c) \
42
43=== modified file 'src/daemon.vala'
44--- src/daemon.vala 2012-01-24 16:20:35 +0000
45+++ src/daemon.vala 2012-01-25 08:25:28 +0000
46@@ -357,16 +357,10 @@
47 scope.queue_search_changed (SearchType.GLOBAL);
48 }
49
50- private string prepare_zg_search_string (Unity.LensSearch? search,
51+ private string prepare_zg_search_string (Unity.LensSearch search,
52 string type_id="all")
53 {
54- string s;
55- if (search != null)
56- s = search.search_string;
57- else
58- s = "";
59-
60- s = s.strip ();
61+ string s = search.search_string.strip ();
62
63 if (!s.has_suffix ("*") && s != "")
64 s = s + "*";
65@@ -397,7 +391,7 @@
66
67 string pkg_search_string = prepare_pkg_search_string (search, type_id);
68
69- bool has_search = !Utils.search_is_invalid (search);
70+ bool has_search = !Utils.is_search_empty (search);
71
72 Timer timer = new Timer ();
73
74@@ -475,7 +469,7 @@
75 else
76 {
77 timer.start ();
78- string? filter_query = prepare_pkg_search_string (null, type_id);
79+ string? filter_query = prepare_pkg_search_string (search, type_id);
80 var random_pkgresults = pkgsearcher.get_random_apps (filter_query, 12);
81 add_pkg_search_result (random_pkgresults, installed_uris, available_uris,
82 model, Category.AVAILABLE, 6);
83@@ -502,7 +496,7 @@
84 * hits under one Applications category
85 */
86
87- if (Utils.search_is_invalid (search))
88+ if (Utils.is_search_empty (search))
89 {
90 yield update_global_without_search (search, cancellable);
91 return;
92@@ -576,9 +570,9 @@
93 search.finished ();
94 }
95
96- private string prepare_pkg_search_string (Unity.LensSearch? search, string type_id="all")
97+ private string prepare_pkg_search_string (Unity.LensSearch search, string type_id="all")
98 {
99- if (Utils.search_is_invalid (search))
100+ if (Utils.is_search_empty (search))
101 {
102 if (type_id == "all")
103 return "type:Application";
104
105=== modified file 'src/runner.vala'
106--- src/runner.vala 2011-12-07 16:21:04 +0000
107+++ src/runner.vala 2012-01-25 08:25:28 +0000
108@@ -139,7 +139,7 @@
109 model.clear ();
110
111 var search_string = search.search_string;
112- bool has_search = !Utils.search_is_invalid (search);
113+ bool has_search = !Utils.is_search_empty (search);
114
115 string uri;
116 Icon icon;
117
118=== modified file 'src/unity-package-search.cc'
119--- src/unity-package-search.cc 2011-09-27 12:22:51 +0000
120+++ src/unity-package-search.cc 2012-01-25 08:25:28 +0000
121@@ -52,6 +52,11 @@
122
123 #include "unity-package-search.h"
124
125+extern "C"
126+{
127+extern gchar* unity_applications_lens_utils_uncamelcase (const gchar* input);
128+}
129+
130 struct _UnityPackageSearcher
131 {
132 Xapian::Database *db;
133@@ -169,14 +174,19 @@
134 /* Index full text data */
135 indexer->set_document(doc);
136 if (gmenu_tree_entry_get_display_name (entry))
137- indexer->index_text(gmenu_tree_entry_get_display_name (entry), 5);
138+ {
139+ dum1 = unity_applications_lens_utils_uncamelcase (
140+ gmenu_tree_entry_get_display_name (entry));
141+ indexer->index_text(dum1, 5);
142+ g_free (dum1);
143+ }
144 if (gmenu_tree_entry_get_name (entry))
145 indexer->index_text(gmenu_tree_entry_get_name (entry), 5);
146 if (gmenu_tree_entry_get_comment (entry))
147 indexer->index_text(gmenu_tree_entry_get_comment (entry), 0);
148
149 /* Index the XDG categories */
150- appman = unity_app_info_manager_get_instance ();
151+ appman = unity_app_info_manager_get_default ();
152 cats = unity_app_info_manager_get_categories (appman, // const return
153 gmenu_tree_entry_get_desktop_file_id (entry),
154 &len);
155
156=== modified file 'src/unity-ratings-db.c'
157--- src/unity-ratings-db.c 2011-09-23 12:49:07 +0000
158+++ src/unity-ratings-db.c 2012-01-25 08:25:28 +0000
159@@ -168,7 +168,7 @@
160 if (data.size != 3*sizeof (gint32))
161 {
162 g_critical ("Unexpected datum size from ratings database %i bytes. "
163- "Expected %i bytes", data.size, 3*sizeof (gint32));
164+ "Expected %lu bytes", data.size, 3*sizeof (gint32));
165 goto not_found;
166 }
167
168
169=== modified file 'src/utils.vala'
170--- src/utils.vala 2011-12-06 15:25:46 +0000
171+++ src/utils.vala 2012-01-25 08:25:28 +0000
172@@ -70,18 +70,52 @@
173 return actor;
174 }
175
176- public bool search_is_invalid (Unity.LensSearch? search)
177+ public bool is_search_empty (Unity.LensSearch search)
178 {
179- /* This boolean expression is unfolded as we seem to get
180- * some null dereference if we join them in a big || expression */
181- if (search == null)
182- return true;
183- else if (search.search_string == null)
184- return true;
185-
186+ if (search.search_string == null) return true;
187 return search.search_string == "";
188 }
189-
190+
191+ private static Regex camelcase_matcher;
192+
193+ public string uncamelcase (string text)
194+ {
195+ if (camelcase_matcher == null)
196+ {
197+ try
198+ {
199+ // 1+ upper characters followed by 1+ non-upper
200+ // (but preceded by non-upper or start of the string)
201+ camelcase_matcher = new Regex ("(?<=^|[^[:upper:]])[[:upper:]]+[^[:upper:]]+",
202+ RegexCompileFlags.OPTIMIZE);
203+ }
204+ catch (Error e) { warning ("%s", e.message); }
205+ }
206+
207+ /* we want to do "pyKaraoke" -> "py Karaoke",
208+ "CompizConfig" -> "Compiz Config", but leave "System Monitor" alone
209+ */
210+ try
211+ {
212+ string result;
213+ result = camelcase_matcher.replace_eval (text, -1, 0, 0,(mi, builder) =>
214+ {
215+ int start_pos;
216+ mi.fetch_pos (0, out start_pos, null);
217+ if (start_pos != 0) builder.append_c (' ');
218+ builder.append (mi.fetch (0));
219+
220+ return false;
221+ });
222+ return result;
223+ }
224+ catch (Error e)
225+ {
226+ warning ("%s", e.message);
227+ return text;
228+ }
229+ }
230+
231 /* Substitute tilde character in @s by the home directory.
232 * Expansion of ~username also works if 'username' is found. */
233 public string subst_tilde (string s)

Subscribers

People subscribed via source and target branches