Merge lp:~donadigo/slingshot/fix-app-ranking into lp:~elementary-pantheon/slingshot/trunk

Proposed by Adam Bieńkowski
Status: Merged
Approved by: David Hewitt
Approved revision: 754
Merged at revision: 753
Proposed branch: lp:~donadigo/slingshot/fix-app-ranking
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 140 lines (+62/-61)
1 file modified
lib/synapse-plugins/desktop-file-plugin.vala (+62/-61)
To merge this branch: bzr merge lp:~donadigo/slingshot/fix-app-ranking
Reviewer Review Type Date Requested Status
David Hewitt code, function Approve
Review via email: mp+319365@code.launchpad.net

Commit message

* Fix app ranking being incorrect about keywords

Description of the change

This branch aims to fix app rankings, and keyword queries which are currently incorrectly handeled (as well as actions).

The code should be easier to read and understand now since matchers are iterated only twice for app searching and action searching. Some of the statements caused returning the highest possible values for a match, these are now removed, I've also adjusted current values a little bit.

To post a comment you must log in.
Revision history for this message
David Hewitt (davidmhewitt) wrote :

I've tried all of the apps that come with elementary in the search plus a few others and all the results were as I'd expect. So this has definitely fixed the weird ordering of some of the results.

review: Approve (code, function)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/synapse-plugins/desktop-file-plugin.vala'
--- lib/synapse-plugins/desktop-file-plugin.vala 2017-02-15 13:14:11 +0000
+++ lib/synapse-plugins/desktop-file-plugin.vala 2017-03-08 19:39:36 +0000
@@ -191,74 +191,75 @@
191 unowned string generic_name = dfm.generic_name;191 unowned string generic_name = dfm.generic_name;
192 unowned string gettext_domain = dfm.gettext_domain;192 unowned string gettext_domain = dfm.gettext_domain;
193193
194 bool matched = false;
195 // FIXME: we need to do much smarter relevancy computation in fuzzy re
196 // "sysmon" matching "System Monitor" is very good as opposed to
197 // "seto" matching "System Monitor"
198 foreach (var matcher in matchers) {
199 MatchInfo info;
200 if (matcher.key.match (folded_title, 0, out info)) {
201 results.add (dfm, compute_relevancy (dfm, matcher.value));
202 matched = true;
203 break;
204 } else if (unaccented_title != null && matcher.key.match (unaccented_title)) {
205 results.add (dfm, compute_relevancy (dfm, matcher.value - Match.Score.INCREMENT_SMALL));
206 matched = true;
207 break;
208 } else if (info.is_partial_match ()) {
209 results.add (dfm, compute_relevancy (dfm, Match.Score.INCREMENT_SMALL));
210 matched = true;
211 break;
212 }
213 }
214
215 string id = dfm.desktop_id.replace ("application://", "");194 string id = dfm.desktop_id.replace ("application://", "");
216 var desktop_app_info = new DesktopAppInfo (id);195 var desktop_app_info = new DesktopAppInfo (id);
217 string[] actions = desktop_app_info.list_actions ();196
218 foreach (string action in actions) {197 MatchInfo info;
198
199 // Populate actions
200 foreach (string action in desktop_app_info.list_actions ()) {
219 string title = desktop_app_info.get_action_name (action);201 string title = desktop_app_info.get_action_name (action);
220 if (gettext_domain != null) {202 if (gettext_domain != null) {
221 title = GLib.dgettext (gettext_domain, title).down ();203 title = GLib.dgettext (gettext_domain, title).down ();
222 } else {204 } else {
223 title = title.down ();205 title = title.down ();
224 }206 }
225207
226 foreach (var matcher in matchers) {208 foreach (var matcher in matchers) {
227 MatchInfo action_info;209 if (matcher.key.match (title, 0, out info)) {
228 if (matcher.key.match (title, 0, out action_info) || title.contains (q.query_string_folded) || title.has_prefix (q.query_string)) {210 var am = new ActionMatch (id, action);
229 var am = new ActionMatch (id, action);211 results.add (am, compute_relevancy (dfm, matcher.value));
230 results.add (am, compute_relevancy (dfm, Match.Score.INCREMENT_SMALL));212 break;
231 matched = true;213 } else if (info.is_partial_match ()) {
232 break;214 var am = new ActionMatch (id, action);
233 } else if (action_info.is_partial_match ()) {215 results.add (am, compute_relevancy (dfm, Match.Score.AVERAGE));
234 var am = new ActionMatch (id, action);216 break;
235 results.add (am, compute_relevancy (dfm, Match.Score.INCREMENT_SMALL));217 }
236 matched = true; 218 }
237 break; 219 }
238 }220
239 }221 // Populate apps
240 }222 bool matched = false;
241223 unowned string[] keywords = desktop_app_info.get_keywords ();
242 foreach (unowned string keyword in desktop_app_info.get_keywords ()) {224 foreach (var matcher in matchers) {
243 string _keyword = keyword.down ();225 // FIXME: we need to do much smarter relevancy computation in fuzzy re
244 foreach (var matcher in matchers) {226 // "sysmon" matching "System Monitor" is very good as opposed to
245 MatchInfo action_info;227 // "seto" matching "System Monitor"
246 if (matcher.key.match (_keyword, 0, out action_info) || _keyword.contains (q.query_string_folded) || _keyword.has_prefix (q.query_string)) {228 if (matcher.key.match (folded_title, 0, out info)) {
247 results.add (dfm, compute_relevancy (dfm, Match.Score.INCREMENT_SMALL));229 results.add (dfm, compute_relevancy (dfm, matcher.value));
248 matched = true;230 matched = true;
249 break;231 break;
250 } else if (action_info.is_partial_match ()) {232 } else if (unaccented_title != null && matcher.key.match (unaccented_title)) {
251 results.add (dfm, compute_relevancy (dfm, Match.Score.INCREMENT_SMALL));233 results.add (dfm, compute_relevancy (dfm, matcher.value - Match.Score.INCREMENT_SMALL));
252 matched = true; 234 matched = true;
253 break; 235 break;
254 }236 } else if (info.is_partial_match ()) {
255 } 237 results.add (dfm, compute_relevancy (dfm, Match.Score.AVERAGE));
256 }238 matched = true;
257239 break;
258 if (!matched && (comment.down ().contains (q.query_string_folded) || generic_name.down ().contains (q.query_string_folded))) {240 }
259 results.add (dfm, compute_relevancy (dfm, Match.Score.AVERAGE - Match.Score.INCREMENT_MEDIUM));241
260 matched = true;242 foreach (string keyword in keywords) {
261 } if (!matched && dfm.exec.has_prefix (q.query_string)) {243 keyword = keyword.down ();
244 if (matcher.key.match (keyword, 0, out info)) {
245 results.add (dfm, compute_relevancy (dfm, matcher.value - Match.Score.INCREMENT_LARGE));
246 matched = true;
247 break;
248 } else if (info.is_partial_match ()) {
249 results.add (dfm, compute_relevancy (dfm, Match.Score.POOR - Match.Score.INCREMENT_LARGE));
250 matched = true;
251 break;
252 }
253 }
254 }
255
256 if (matched) {
257 continue;
258 }
259
260 if (comment.down ().contains (q.query_string_folded) || generic_name.down ().contains (q.query_string_folded)) {
261 results.add (dfm, compute_relevancy (dfm, Match.Score.BELOW_AVERAGE - Match.Score.INCREMENT_MEDIUM));
262 } else if (dfm.exec.has_prefix (q.query_string)) {
262 results.add (dfm, compute_relevancy (dfm, dfm.exec == q.query_string ?263 results.add (dfm, compute_relevancy (dfm, dfm.exec == q.query_string ?
263 Match.Score.VERY_GOOD : Match.Score.AVERAGE - Match.Score.INCREMENT_SMALL));264 Match.Score.VERY_GOOD : Match.Score.AVERAGE - Match.Score.INCREMENT_SMALL));
264 }265 }

Subscribers

People subscribed via source and target branches