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

Proposed by David Hewitt
Status: Merged
Approved by: Corentin Noël
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 Approve
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

Removed code to detect links

755. By David Hewitt

Merge trunk

Revision history for this message
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
=== modified file 'lib/synapse-plugins/appcenter-plugin.vala'
--- lib/synapse-plugins/appcenter-plugin.vala 2017-02-18 19:48:37 +0000
+++ lib/synapse-plugins/appcenter-plugin.vala 2017-03-12 19:07:10 +0000
@@ -80,6 +80,7 @@
80 }80 }
8181
82 private static AppInfo? appinfo;82 private static AppInfo? appinfo;
83 private static Regex regex;
8384
84 static void register_plugin () {85 static void register_plugin () {
85 bool appcenter_installed = false;86 bool appcenter_installed = false;
@@ -101,6 +102,13 @@
101102
102 static construct {103 static construct {
103 register_plugin ();104 register_plugin ();
105
106 try {
107 // 2 or more characters, must contain at least one letter
108 regex = new Regex ("""^(?=\pL).{2,}$""", RegexCompileFlags.OPTIMIZE);
109 } catch (Error e) {
110 error ("Error creating regexp.");
111 }
104 }112 }
105113
106 public bool handles_query (Query query) {114 public bool handles_query (Query query) {
@@ -108,11 +116,15 @@
108 }116 }
109117
110 public async ResultSet? search (Query query) throws SearchError {118 public async ResultSet? search (Query query) throws SearchError {
111 ResultSet results = new ResultSet ();119 if (regex.match (query.query_string)) {
112 Result search_result = new Result (query.query_string);120 ResultSet results = new ResultSet ();
113 results.add (search_result, Match.Score.INCREMENT_MINOR);121 Result search_result = new Result (query.query_string);
122 results.add (search_result, Match.Score.INCREMENT_MINOR);
114123
115 return results;124 return results;
125 } else {
126 return null;
127 }
116 }128 }
117 }129 }
118}130}

Subscribers

People subscribed via source and target branches