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

Proposed by Adam Bieńkowski on 2017-03-08
Status: Merged
Approved by: David Hewitt on 2017-03-08
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 2017-03-08 Approve on 2017-03-08
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.
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
1=== modified file 'lib/synapse-plugins/desktop-file-plugin.vala'
2--- lib/synapse-plugins/desktop-file-plugin.vala 2017-02-15 13:14:11 +0000
3+++ lib/synapse-plugins/desktop-file-plugin.vala 2017-03-08 19:39:36 +0000
4@@ -191,74 +191,75 @@
5 unowned string generic_name = dfm.generic_name;
6 unowned string gettext_domain = dfm.gettext_domain;
7
8- bool matched = false;
9- // FIXME: we need to do much smarter relevancy computation in fuzzy re
10- // "sysmon" matching "System Monitor" is very good as opposed to
11- // "seto" matching "System Monitor"
12- foreach (var matcher in matchers) {
13- MatchInfo info;
14- if (matcher.key.match (folded_title, 0, out info)) {
15- results.add (dfm, compute_relevancy (dfm, matcher.value));
16- matched = true;
17- break;
18- } else if (unaccented_title != null && matcher.key.match (unaccented_title)) {
19- results.add (dfm, compute_relevancy (dfm, matcher.value - Match.Score.INCREMENT_SMALL));
20- matched = true;
21- break;
22- } else if (info.is_partial_match ()) {
23- results.add (dfm, compute_relevancy (dfm, Match.Score.INCREMENT_SMALL));
24- matched = true;
25- break;
26- }
27- }
28-
29 string id = dfm.desktop_id.replace ("application://", "");
30 var desktop_app_info = new DesktopAppInfo (id);
31- string[] actions = desktop_app_info.list_actions ();
32- foreach (string action in actions) {
33+
34+ MatchInfo info;
35+
36+ // Populate actions
37+ foreach (string action in desktop_app_info.list_actions ()) {
38 string title = desktop_app_info.get_action_name (action);
39 if (gettext_domain != null) {
40 title = GLib.dgettext (gettext_domain, title).down ();
41 } else {
42 title = title.down ();
43- }
44-
45- foreach (var matcher in matchers) {
46- MatchInfo action_info;
47- if (matcher.key.match (title, 0, out action_info) || title.contains (q.query_string_folded) || title.has_prefix (q.query_string)) {
48- var am = new ActionMatch (id, action);
49- results.add (am, compute_relevancy (dfm, Match.Score.INCREMENT_SMALL));
50- matched = true;
51- break;
52- } else if (action_info.is_partial_match ()) {
53- var am = new ActionMatch (id, action);
54- results.add (am, compute_relevancy (dfm, Match.Score.INCREMENT_SMALL));
55- matched = true;
56- break;
57- }
58- }
59- }
60-
61- foreach (unowned string keyword in desktop_app_info.get_keywords ()) {
62- string _keyword = keyword.down ();
63- foreach (var matcher in matchers) {
64- MatchInfo action_info;
65- if (matcher.key.match (_keyword, 0, out action_info) || _keyword.contains (q.query_string_folded) || _keyword.has_prefix (q.query_string)) {
66- results.add (dfm, compute_relevancy (dfm, Match.Score.INCREMENT_SMALL));
67- matched = true;
68- break;
69- } else if (action_info.is_partial_match ()) {
70- results.add (dfm, compute_relevancy (dfm, Match.Score.INCREMENT_SMALL));
71- matched = true;
72- break;
73- }
74- }
75- }
76-
77- if (!matched && (comment.down ().contains (q.query_string_folded) || generic_name.down ().contains (q.query_string_folded))) {
78- results.add (dfm, compute_relevancy (dfm, Match.Score.AVERAGE - Match.Score.INCREMENT_MEDIUM));
79- matched = true;
80- } if (!matched && dfm.exec.has_prefix (q.query_string)) {
81+ }
82+
83+ foreach (var matcher in matchers) {
84+ if (matcher.key.match (title, 0, out info)) {
85+ var am = new ActionMatch (id, action);
86+ results.add (am, compute_relevancy (dfm, matcher.value));
87+ break;
88+ } else if (info.is_partial_match ()) {
89+ var am = new ActionMatch (id, action);
90+ results.add (am, compute_relevancy (dfm, Match.Score.AVERAGE));
91+ break;
92+ }
93+ }
94+ }
95+
96+ // Populate apps
97+ bool matched = false;
98+ unowned string[] keywords = desktop_app_info.get_keywords ();
99+ foreach (var matcher in matchers) {
100+ // FIXME: we need to do much smarter relevancy computation in fuzzy re
101+ // "sysmon" matching "System Monitor" is very good as opposed to
102+ // "seto" matching "System Monitor"
103+ if (matcher.key.match (folded_title, 0, out info)) {
104+ results.add (dfm, compute_relevancy (dfm, matcher.value));
105+ matched = true;
106+ break;
107+ } else if (unaccented_title != null && matcher.key.match (unaccented_title)) {
108+ results.add (dfm, compute_relevancy (dfm, matcher.value - Match.Score.INCREMENT_SMALL));
109+ matched = true;
110+ break;
111+ } else if (info.is_partial_match ()) {
112+ results.add (dfm, compute_relevancy (dfm, Match.Score.AVERAGE));
113+ matched = true;
114+ break;
115+ }
116+
117+ foreach (string keyword in keywords) {
118+ keyword = keyword.down ();
119+ if (matcher.key.match (keyword, 0, out info)) {
120+ results.add (dfm, compute_relevancy (dfm, matcher.value - Match.Score.INCREMENT_LARGE));
121+ matched = true;
122+ break;
123+ } else if (info.is_partial_match ()) {
124+ results.add (dfm, compute_relevancy (dfm, Match.Score.POOR - Match.Score.INCREMENT_LARGE));
125+ matched = true;
126+ break;
127+ }
128+ }
129+ }
130+
131+ if (matched) {
132+ continue;
133+ }
134+
135+ if (comment.down ().contains (q.query_string_folded) || generic_name.down ().contains (q.query_string_folded)) {
136+ results.add (dfm, compute_relevancy (dfm, Match.Score.BELOW_AVERAGE - Match.Score.INCREMENT_MEDIUM));
137+ } else if (dfm.exec.has_prefix (q.query_string)) {
138 results.add (dfm, compute_relevancy (dfm, dfm.exec == q.query_string ?
139 Match.Score.VERY_GOOD : Match.Score.AVERAGE - Match.Score.INCREMENT_SMALL));
140 }

Subscribers

People subscribed via source and target branches