Merge lp:~jeremy-munsch/synapse-project/improved-search2 into lp:synapse-project

Proposed by Jeremy Munsch
Status: Needs review
Proposed branch: lp:~jeremy-munsch/synapse-project/improved-search2
Merge into: lp:synapse-project
Diff against target: 179 lines (+104/-2)
2 files modified
src/core/desktop-file-service.vala (+56/-0)
src/plugins/desktop-file-plugin.vala (+48/-2)
To merge this branch: bzr merge lp:~jeremy-munsch/synapse-project/improved-search2
Reviewer Review Type Date Requested Status
Rico Tzschichholz Pending
Review via email: mp+279448@code.launchpad.net

Description of the change

* Add minimum MatchScore for given regex match : Using fuzzy only on title only
* Add Caseless Regex Compile Flag
* Add search in description, keywords, generic name, categories
* Comptes proportionnal relevancies for less valuable matches (categories, etc..)

For generic_name and keywords, it checks if locale is different than eng strings.
If so it takes the locale ones and add them to the english ones.
If not, it uses SUPPORTED_GETTEXT_DOMAINS_KEYS to add the available translations without any check though.

I believe I checked all I could to be compliant.

To post a comment you must log in.

Unmerged revisions

637. By Jeremy Munsch

* Add minimum MatchScore for given regex match : Using fuzzy only on title only
* Add Caseless Regex Compile Flag
* Add search in description, keywords, generic name, categories
* Comptes proportionnal relevancies for less valuable matches (categories, etc..)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/core/desktop-file-service.vala'
--- src/core/desktop-file-service.vala 2015-11-14 20:58:02 +0000
+++ src/core/desktop-file-service.vala 2015-12-03 14:45:08 +0000
@@ -82,6 +82,7 @@
82 public string name { get; construct set; }82 public string name { get; construct set; }
83 public string comment { get; set; default = ""; }83 public string comment { get; set; default = ""; }
84 public string icon_name { get; construct set; default = ""; }84 public string icon_name { get; construct set; default = ""; }
85 public string generic_name { get; set; default = ""; }
8586
86 public bool needs_terminal { get; set; default = false; }87 public bool needs_terminal { get; set; default = false; }
87 public string filename { get; construct set; }88 public string filename { get; construct set; }
@@ -93,6 +94,8 @@
9394
94 public string[] actions = null;95 public string[] actions = null;
95 public string[] mime_types = null;96 public string[] mime_types = null;
97 public string[] categories = null;
98 public string[] keywords = null;
9699
97 private string? name_folded = null;100 private string? name_folded = null;
98 public unowned string get_name_folded ()101 public unowned string get_name_folded ()
@@ -183,6 +186,55 @@
183 if (keyfile.has_key (KeyFileDesktop.GROUP, KeyFileDesktop.KEY_ACTIONS))186 if (keyfile.has_key (KeyFileDesktop.GROUP, KeyFileDesktop.KEY_ACTIONS))
184 actions = keyfile.get_string_list (KeyFileDesktop.GROUP, KeyFileDesktop.KEY_ACTIONS);187 actions = keyfile.get_string_list (KeyFileDesktop.GROUP, KeyFileDesktop.KEY_ACTIONS);
185188
189 unowned string string_comparator = "";
190 unowned string? textdomain = null;
191 StringBuilder key_info_builder = new StringBuilder ();
192 foreach (unowned string domain_key in DesktopFileService.SUPPORTED_GETTEXT_DOMAINS_KEYS)
193 if (keyfile.has_key (KeyFileDesktop.GROUP, domain_key)) {
194 textdomain = keyfile.get_string (KeyFileDesktop.GROUP, domain_key);
195 break;
196 }
197
198 if (keyfile.has_key (KeyFileDesktop.GROUP, KeyFileDesktop.KEY_GENERIC_NAME))
199 {
200 key_info_builder.append (keyfile.get_string (KeyFileDesktop.GROUP, KeyFileDesktop.KEY_GENERIC_NAME));
201 string_comparator = keyfile.get_locale_string (KeyFileDesktop.GROUP, KeyFileDesktop.KEY_GENERIC_NAME);
202 if (key_info_builder.str.hash () != string_comparator.hash ())
203 key_info_builder.append_c (' ').append (string_comparator);
204 else if (textdomain != null)
205 {
206 key_info_builder.append_c (' ')
207 .append (GLib.dgettext (textdomain, key_info_builder.str));
208 }
209 generic_name = key_info_builder.str;
210 }
211
212 // categories are never translated
213 if (keyfile.has_key (KeyFileDesktop.GROUP, KeyFileDesktop.KEY_CATEGORIES))
214 categories = keyfile.get_string_list (KeyFileDesktop.GROUP, KeyFileDesktop.KEY_CATEGORIES);
215
216 if (keyfile.has_key (KeyFileDesktop.GROUP, KeyFileDesktop.KEY_KEYWORDS))
217 {
218 string[] temp_keywords = keyfile.get_string_list (KeyFileDesktop.GROUP, KeyFileDesktop.KEY_KEYWORDS);
219 string[] locale_list = keyfile.get_locale_string_list (KeyFileDesktop.GROUP, KeyFileDesktop.KEY_KEYWORDS);
220 if (string.joinv ("", temp_keywords).hash () != string.joinv ("", locale_list).hash ())
221 {
222 foreach (unowned string word in locale_list)
223 {
224 temp_keywords += word;
225 }
226 keywords = temp_keywords;
227 }
228 else if (textdomain != null)
229 {
230 foreach (unowned string word in temp_keywords)
231 {
232 locale_list += GLib.dgettext (textdomain, word).dup ();
233 }
234 keywords = locale_list;
235 }
236 }
237
186 // special case these, people are using them quite often and wonder238 // special case these, people are using them quite often and wonder
187 // why they don't appear239 // why they don't appear
188 if (filename.has_suffix ("gconf-editor.desktop") ||240 if (filename.has_suffix ("gconf-editor.desktop") ||
@@ -221,6 +273,10 @@
221 private Gee.Map<string, Gee.List<DesktopFileInfo>> exec_map;273 private Gee.Map<string, Gee.List<DesktopFileInfo>> exec_map;
222 private Gee.Map<string, DesktopFileInfo> desktop_id_map;274 private Gee.Map<string, DesktopFileInfo> desktop_id_map;
223 private Gee.MultiMap<string, string> mimetype_parent_map;275 private Gee.MultiMap<string, string> mimetype_parent_map;
276 public const string[] SUPPORTED_GETTEXT_DOMAINS_KEYS = {
277 "X-Ubuntu-Gettext-Domain",
278 "X-GNOME-Gettext-Domain"
279 };
224280
225 construct281 construct
226 {282 {
227283
=== modified file 'src/plugins/desktop-file-plugin.vala'
--- src/plugins/desktop-file-plugin.vala 2015-11-14 20:58:02 +0000
+++ src/plugins/desktop-file-plugin.vala 2015-12-03 14:45:08 +0000
@@ -42,6 +42,9 @@
42 public string title_unaccented { get; construct; }42 public string title_unaccented { get; construct; }
43 public string desktop_id { get; construct; }43 public string desktop_id { get; construct; }
44 public string exec { get; construct; }44 public string exec { get; construct; }
45 public string generic_name_folded { get; set; }
46 public string categories_string_folded { get; set; }
47 public string keywords_string_folded { get; construct; }
4548
46 public DesktopFileMatch (DesktopFileInfo info)49 public DesktopFileMatch (DesktopFileInfo info)
47 {50 {
@@ -59,6 +62,9 @@
59 title_folded = desktop_info.get_name_folded () ?? title.casefold ();62 title_folded = desktop_info.get_name_folded () ?? title.casefold ();
60 title_unaccented = Utils.remove_accents (title_folded);63 title_unaccented = Utils.remove_accents (title_folded);
61 desktop_id = "application://" + desktop_info.desktop_id;64 desktop_id = "application://" + desktop_info.desktop_id;
65 generic_name_folded = desktop_info.generic_name.casefold ();
66 categories_string_folded = string.joinv (" ", desktop_info.categories).casefold ();
67 keywords_string_folded = string.joinv (" ", desktop_info.keywords).casefold ();
62 }68 }
63 }69 }
6470
@@ -130,12 +136,20 @@
130 return r;136 return r;
131 }137 }
132138
139 /**
140 * computes proportionnal relevancy
141 */
142 private int compute_proportional_match_score (int matcher_value, int average_score)
143 {
144 return (int)Math.floor ((long)matcher_value * average_score / MatchScore.HIGHEST);
145 }
146
133 private void full_search (Query q, ResultSet results,147 private void full_search (Query q, ResultSet results,
134 MatcherFlags flags = 0)148 MatcherFlags flags = 0)
135 {149 {
136 // try to match against global matchers and if those fail, try also exec150 // try to match against global matchers and if those fail, try also exec
137 var matchers = Query.get_matchers_for_query (q.query_string_folded,151 var matchers = Query.get_matchers_for_query (q.query_string_folded,
138 flags);152 flags, RegexCompileFlags.CASELESS);
139153
140 foreach (var dfm in desktop_files)154 foreach (var dfm in desktop_files)
141 {155 {
@@ -153,12 +167,44 @@
153 matched = true;167 matched = true;
154 break;168 break;
155 }169 }
156 else if (unaccented_title != null && matcher.key.match (unaccented_title))170 if (unaccented_title != null && matcher.key.match (unaccented_title))
157 {171 {
158 results.add (dfm, compute_relevancy (dfm, matcher.value - MatchScore.INCREMENT_SMALL));172 results.add (dfm, compute_relevancy (dfm, matcher.value - MatchScore.INCREMENT_SMALL));
159 matched = true;173 matched = true;
160 break;174 break;
161 }175 }
176 if (dfm.generic_name_folded != null
177 && matcher.value >= MatchScore.AVERAGE
178 && matcher.key.match (dfm.generic_name_folded))
179 {
180 results.add (dfm, compute_relevancy (dfm, compute_proportional_match_score (matcher.value, MatchScore.AVERAGE)));
181 matched = true;
182 break;
183 }
184 if (dfm.keywords_string_folded != null
185 && matcher.value >= MatchScore.AVERAGE
186 && matcher.key.match (dfm.keywords_string_folded))
187 {
188 results.add (dfm, compute_relevancy (dfm, compute_proportional_match_score (matcher.value, MatchScore.AVERAGE)));
189 matched = true;
190 break;
191 }
192 if (dfm.categories_string_folded != null
193 && matcher.value >= MatchScore.BELOW_AVERAGE
194 && matcher.key.match (dfm.categories_string_folded))
195 {
196 results.add (dfm, compute_relevancy (dfm, compute_proportional_match_score (matcher.value, MatchScore.BELOW_AVERAGE)));
197 matched = true;
198 break;
199 }
200 if (dfm.description != null
201 && matcher.value >= MatchScore.BELOW_AVERAGE
202 && matcher.key.match (dfm.description.casefold ()))
203 {
204 results.add (dfm, compute_relevancy (dfm, compute_proportional_match_score (matcher.value, MatchScore.BELOW_AVERAGE)));
205 matched = true;
206 break;
207 }
162 }208 }
163 if (!matched && dfm.exec.has_prefix (q.query_string))209 if (!matched && dfm.exec.has_prefix (q.query_string))
164 {210 {