diff --git a/gui/src/components/search/SearchBar.js b/gui/src/components/search/SearchBar.js
index fb010c234f874c0e1ae2c419730ad0504364c807..03b5fd97bab3db14e231d9188ee1eabfe259c13a 100644
--- a/gui/src/components/search/SearchBar.js
+++ b/gui/src/components/search/SearchBar.js
@@ -26,7 +26,7 @@ const Options = {
  */
 export default function SearchBar() {
   const suggestionsTimerRef = useRef(null)
-  const {response: {statistics, pagination}, domain, query, setQuery} = useContext(searchContext)
+  const {response: {statistics, pagination}, domain, query, apiQuery, setQuery} = useContext(searchContext)
   const defaultOptions = useMemo(() => {
     return Object.keys(searchQuantities)
       .map(quantity => searchQuantities[quantity].name)
@@ -81,7 +81,7 @@ export default function SearchBar() {
     }
     suggestionsTimerRef.current = setTimeout(() => {
       setLoading(true)
-      api.suggestions_search(quantity, query, size ? null : value, size || 20, true)
+      api.suggestions_search(quantity, apiQuery, size ? null : value, size || 20, true)
         .then(response => {
           setLoading(false)
           const options = response.suggestions.map(value => Options.join(quantity, value))
diff --git a/nomad/app/api/repo.py b/nomad/app/api/repo.py
index 0ea8e9b7de35ccb6db89d5b5e0cf4fcaf108312d..0d2c9ac8a43058b01ee4b5ebc16b88e6f0510f18 100644
--- a/nomad/app/api/repo.py
+++ b/nomad/app/api/repo.py
@@ -680,9 +680,12 @@ class RepoSuggestionsResource(Resource):
         try:
             search_request.statistic(quantity, size=size, include=include, order=dict(_key='desc'))
             results = search_request.execute()
-            values = results['statistics'][quantity]
+            values = {
+                value: metric['code_runs']
+                for value, metric in results['statistics'][quantity].items()
+                if metric['code_runs'] > 0}
             results['suggestions'] = sorted(
-                values.keys(), key=lambda value: values[value]['code_runs'], reverse=True)
+                values.keys(), key=lambda value: values[value], reverse=True)
 
             return results, 200
         except KeyError as e: