FIX: Improve quick search speed and result highlights (#14610)

FIX: Improve quick search speed and result highlights (#14610)

diff --git a/app/assets/javascripts/discourse/app/widgets/search-menu.js b/app/assets/javascripts/discourse/app/widgets/search-menu.js
index 47dc787..dbaf835 100644
--- a/app/assets/javascripts/discourse/app/widgets/search-menu.js
+++ b/app/assets/javascripts/discourse/app/widgets/search-menu.js
@@ -15,7 +15,7 @@ import { CANCELLED_STATUS } from "discourse/lib/autocomplete";
 const CATEGORY_SLUG_REGEXP = /(\#[a-zA-Z0-9\-:]*)$/gi;
 const USERNAME_REGEXP = /(\@[a-zA-Z0-9\-\_]*)$/gi;
 const SUGGESTIONS_REGEXP = /(in:|status:|order:|:)([a-zA-Z]*)$/gi;
-export const TOPIC_REPLACE_REGEXP = /\stopic:\d+/i;
+export const TOPIC_REPLACE_REGEXP = /\btopic:\d+\s?/i;
 export const MODIFIER_REGEXP = /.*(\#|\@|:).*$/gi;
 export const DEFAULT_TYPE_FILTER = "exclude_topics";
 
@@ -385,10 +385,14 @@ export default createWidget("search-menu", {
       const highlightTerm = searchData.term.replace(TOPIC_REPLACE_REGEXP, "");
       this.searchService().set("highlightTerm", highlightTerm);
     }
-    searchData.loading = SearchHelper.includesTopics() ? true : false;
 
-    const delay = SearchHelper.includesTopics() ? 400 : 200;
-    discourseDebounce(SearchHelper, SearchHelper.perform, this, delay);
+    if (SearchHelper.includesTopics()) {
+      searchData.loading = true;
+      SearchHelper.perform(this);
+    } else {
+      searchData.loading = false;
+      discourseDebounce(SearchHelper, SearchHelper.perform, this, 400);
+    }
   },
 
   moreOfType(type) {
diff --git a/app/assets/javascripts/discourse/tests/acceptance/search-test.js b/app/assets/javascripts/discourse/tests/acceptance/search-test.js
index 9579165..f384289 100644
--- a/app/assets/javascripts/discourse/tests/acceptance/search-test.js
+++ b/app/assets/javascripts/discourse/tests/acceptance/search-test.js
@@ -197,6 +197,17 @@ acceptance("Search - Anonymous", function (needs) {
       "highlights the post correctly"
     );
 
+    await fillIn("#search-term", "topic:280 interface");
+    await focus("input#search-term");
+    await triggerKeyEvent(".search-menu", "keydown", 40);
+    await click(document.activeElement);
+
+    assert.equal(
+      query("#post_7 span.highlighted").textContent.trim(),
+      "interface",
+      "highlights the post when term is after modifier"
+    );
+
     await click(".clear-search");
     assert.equal(query("#search-term").value, "", "clear button works");
   });

GitHub sha: 2a7280ac48c2663ca291251a2de766859dfd2eff

This commit appears in #14610 which was approved by danielwaterworth. It was merged by pmusaraj.