Merge lp:~davidmhewitt/slingshot/limit-appcenter-search-queries into lp:~elementary-pantheon/slingshot/trunk

Proposed by David Hewitt on 2017-03-07
Status: Merged
Approved by: Corentin Noël on 2017-05-05
Approved revision: 755
Merged at revision: 761
Proposed branch: lp:~davidmhewitt/slingshot/limit-appcenter-search-queries
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 45 lines (+16/-4)
1 file modified
lib/synapse-plugins/appcenter-plugin.vala (+16/-4)
To merge this branch: bzr merge lp:~davidmhewitt/slingshot/limit-appcenter-search-queries
Reviewer Review Type Date Requested Status
Corentin Noël looks good 2017-03-07 Approve on 2017-05-05
Review via email: mp+319261@code.launchpad.net

Commit message

Prevent AppCenter results for short/number only queries

Description of the change

Now only shows AppCenter results for search queries with 2 or more characters as long as they contain at least one letter.

To post a comment you must log in.
754. By David Hewitt on 2017-03-12

Removed code to detect links

755. By David Hewitt on 2017-03-12

Merge trunk

Corentin Noël (tintou) :
review: Approve (looks good)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/synapse-plugins/appcenter-plugin.vala'
2--- lib/synapse-plugins/appcenter-plugin.vala 2017-02-18 19:48:37 +0000
3+++ lib/synapse-plugins/appcenter-plugin.vala 2017-03-12 19:07:10 +0000
4@@ -80,6 +80,7 @@
5 }
6
7 private static AppInfo? appinfo;
8+ private static Regex regex;
9
10 static void register_plugin () {
11 bool appcenter_installed = false;
12@@ -101,6 +102,13 @@
13
14 static construct {
15 register_plugin ();
16+
17+ try {
18+ // 2 or more characters, must contain at least one letter
19+ regex = new Regex ("""^(?=\pL).{2,}$""", RegexCompileFlags.OPTIMIZE);
20+ } catch (Error e) {
21+ error ("Error creating regexp.");
22+ }
23 }
24
25 public bool handles_query (Query query) {
26@@ -108,11 +116,15 @@
27 }
28
29 public async ResultSet? search (Query query) throws SearchError {
30- ResultSet results = new ResultSet ();
31- Result search_result = new Result (query.query_string);
32- results.add (search_result, Match.Score.INCREMENT_MINOR);
33+ if (regex.match (query.query_string)) {
34+ ResultSet results = new ResultSet ();
35+ Result search_result = new Result (query.query_string);
36+ results.add (search_result, Match.Score.INCREMENT_MINOR);
37
38- return results;
39+ return results;
40+ } else {
41+ return null;
42+ }
43 }
44 }
45 }

Subscribers

People subscribed via source and target branches