FEATURE: Make search filters case insensitive (#10715)

FEATURE: Make search filters case insensitive (#10715)

diff --git a/app/assets/javascripts/discourse/app/components/search-advanced-options.js b/app/assets/javascripts/discourse/app/components/search-advanced-options.js
index 4667653..908e391 100644
--- a/app/assets/javascripts/discourse/app/components/search-advanced-options.js
+++ b/app/assets/javascripts/discourse/app/components/search-advanced-options.js
@@ -114,7 +114,7 @@ export default Component.extend({
     this.setSearchedTermValueForTags();
 
     let regExpInMatch = this.inOptions.map((option) => option.value).join("|");
-    const REGEXP_IN_MATCH = new RegExp(`(in|with):(${regExpInMatch})`);
+    const REGEXP_IN_MATCH = new RegExp(`(in|with):(${regExpInMatch})`, "i");
 
     this.setSearchedTermValue(
       "searchedTerms.in",
@@ -145,7 +145,10 @@ export default Component.extend({
     let regExpStatusMatch = this.statusOptions
       .map((status) => status.value)
       .join("|");
-    const REGEXP_STATUS_MATCH = new RegExp(`status:(${regExpStatusMatch})`);
+    const REGEXP_STATUS_MATCH = new RegExp(
+      `status:(${regExpStatusMatch})`,
+      "i"
+    );
 
     this.setSearchedTermValue(
       "searchedTerms.status",
@@ -203,7 +206,7 @@ export default Component.extend({
 
     let val = this.get(key);
     if (match.length !== 0) {
-      const userInput = match[0].replace(replaceRegEx, "");
+      const userInput = match[0].replace(replaceRegEx, "").toLowerCase();
 
       if (val !== userInput && userInput.length) {
         this.set(key, userInput);
@@ -298,7 +301,9 @@ export default Component.extend({
 
     if (match.length !== 0) {
       const existingInputWhen = this.get("searchedTerms.time.when");
-      const userInputWhen = match[0].match(REGEXP_POST_TIME_WHEN)[0];
+      const userInputWhen = match[0]
+        .match(REGEXP_POST_TIME_WHEN)[0]
+        .toLowerCase();
       const existingInputDays = this.get("searchedTerms.time.days");
       const userInputDays = match[0].replace(REGEXP_POST_TIME_PREFIX, "");
       const properties = {};
@@ -549,7 +554,7 @@ export default Component.extend({
 
   _updateSearchTermForIn() {
     let regExpInMatch = this.inOptions.map((option) => option.value).join("|");
-    const REGEXP_IN_MATCH = new RegExp(`(in|with):(${regExpInMatch})`);
+    const REGEXP_IN_MATCH = new RegExp(`(in|with):(${regExpInMatch})`, "i");
 
     const match = this.filterBlocks(REGEXP_IN_MATCH);
     const inFilter = this.get("searchedTerms.in");
@@ -577,7 +582,10 @@ export default Component.extend({
     let regExpStatusMatch = this.statusOptions
       .map((status) => status.value)
       .join("|");
-    const REGEXP_STATUS_MATCH = new RegExp(`status:(${regExpStatusMatch})`);
+    const REGEXP_STATUS_MATCH = new RegExp(
+      `status:(${regExpStatusMatch})`,
+      "i"
+    );
 
     const match = this.filterBlocks(REGEXP_STATUS_MATCH);
     const statusFilter = this.get("searchedTerms.status");
diff --git a/lib/search.rb b/lib/search.rb
index f2ded80..189e0f4 100644
--- a/lib/search.rb
+++ b/lib/search.rb
@@ -305,7 +305,7 @@ class Search
     Array.wrap(@custom_topic_eager_loads)
   end
 
-  advanced_filter(/^in:personal-direct$/) do |posts|
+  advanced_filter(/^in:personal-direct$/i) do |posts|
     if @guardian.user
       posts
         .joins("LEFT JOIN topic_allowed_groups tg ON posts.topic_id = tg.topic_id")
@@ -325,27 +325,27 @@ class Search
     end
   end
 
-  advanced_filter(/^in:tagged$/) do |posts|
+  advanced_filter(/^in:tagged$/i) do |posts|
     posts
       .where('EXISTS (SELECT 1 FROM topic_tags WHERE topic_tags.topic_id = posts.topic_id)')
   end
 
-  advanced_filter(/^in:untagged$/) do |posts|
+  advanced_filter(/^in:untagged$/i) do |posts|
     posts
       .joins("LEFT JOIN topic_tags ON
         topic_tags.topic_id = posts.topic_id")
       .where("topic_tags.id IS NULL")
   end
 
-  advanced_filter(/^status:open$/) do |posts|
+  advanced_filter(/^status:open$/i) do |posts|
     posts.where('NOT topics.closed AND NOT topics.archived')
   end
 
-  advanced_filter(/^status:closed$/) do |posts|
+  advanced_filter(/^status:closed$/i) do |posts|
     posts.where('topics.closed')
   end
 
-  advanced_filter(/^status:public$/) do |posts|
+  advanced_filter(/^status:public$/i) do |posts|
     category_ids = Category
       .where(read_restricted: false)
       .pluck(:id)
@@ -353,39 +353,39 @@ class Search
     posts.where("topics.category_id in (?)", category_ids)
   end
 
-  advanced_filter(/^status:archived$/) do |posts|
+  advanced_filter(/^status:archived$/i) do |posts|
     posts.where('topics.archived')
   end
 
-  advanced_filter(/^status:noreplies$/) do |posts|
+  advanced_filter(/^status:noreplies$/i) do |posts|
     posts.where("topics.posts_count = 1")
   end
 
-  advanced_filter(/^status:single_user$/) do |posts|
+  advanced_filter(/^status:single_user$/i) do |posts|
     posts.where("topics.participant_count = 1")
   end
 
-  advanced_filter(/^posts_count:(\d+)$/) do |posts, match|
+  advanced_filter(/^posts_count:(\d+)$/i) do |posts, match|
     posts.where("topics.posts_count = ?", match.to_i)
   end
 
-  advanced_filter(/^min_post_count:(\d+)$/) do |posts, match|
+  advanced_filter(/^min_post_count:(\d+)$/i) do |posts, match|
     posts.where("topics.posts_count >= ?", match.to_i)
   end
 
-  advanced_filter(/^in:first|^f$/) do |posts|
+  advanced_filter(/^in:first|^f$/i) do |posts|
     posts.where("posts.post_number = 1")
   end
 
-  advanced_filter(/^in:pinned$/) do |posts|
+  advanced_filter(/^in:pinned$/i) do |posts|
     posts.where("topics.pinned_at IS NOT NULL")
   end
 
-  advanced_filter(/^in:wiki$/) do |posts, match|
+  advanced_filter(/^in:wiki$/i) do |posts, match|
     posts.where(wiki: true)
   end
 
-  advanced_filter(/^badge:(.*)$/) do |posts, match|
+  advanced_filter(/^badge:(.*)$/i) do |posts, match|
     badge_id = Badge.where('name ilike ? OR id = ?', match, match.to_i).pluck_first(:id)
     if badge_id
       posts.where('posts.user_id IN (SELECT ub.user_id FROM user_badges ub WHERE ub.badge_id = ?)', badge_id)
@@ -403,34 +403,34 @@ class Search
     )")
   end
 
-  advanced_filter(/^in:(likes)$/) do |posts, match|
+  advanced_filter(/^in:(likes)$/i) do |posts, match|
     if @guardian.user
       post_action_type_filter(posts, PostActionType.types[:like])
     end
   end
 
-  advanced_filter(/^in:(bookmarks)$/) do |posts, match|
+  advanced_filter(/^in:(bookmarks)$/i) do |posts, match|
     if @guardian.user
       posts.where("posts.id IN (SELECT post_id FROM bookmarks WHERE bookmarks.user_id = #{@guardian.user.id})")
     end
   end
 
-  advanced_filter(/^in:posted$/) do |posts|
+  advanced_filter(/^in:posted$/i) do |posts|
     posts.where("posts.user_id = #{@guardian.user.id}") if @guardian.user
   end
 
-  advanced_filter(/^in:created$/) do |posts|
+  advanced_filter(/^in:created$/i) do |posts|
     posts.where(user_id: @guardian.user.id, post_number: 1) if @guardian.user
   end
 
-  advanced_filter(/^created:@(.*)$/) do |posts, match|
+  advanced_filter(/^created:@(.*)$/i) do |posts, match|
     user_id = User.where(username: match.downcase).pluck_first(:id)
     posts.where(user_id: user_id, post_number: 1)
   end
 
-  advanced_filter(/^in:(watching|tracking)$/) do |posts, match|
+  advanced_filter(/^in:(watching|tracking)$/i) do |posts, match|
     if @guardian.user
-      level = TopicUser.notification_levels[match.to_sym]
+      level = TopicUser.notification_levels[match.downcase.to_sym]
       posts.where("posts.topic_id IN (
                     SELECT tu.topic_id FROM topic_users tu
                     WHERE tu.user_id = :user_id AND
@@ -440,7 +440,7 @@ class Search
     end
   end
 
-  advanced_filter(/^in:seen$/) do |posts|
+  advanced_filter(/^in:seen$/i) do |posts|
     if @guardian.user
       posts
         .joins("INNER JOIN post_timings ON
@@ -451,7 +451,7 @@ class Search
     end
   end
 
-  advanced_filter(/^in:unseen$/) do |posts|
+  advanced_filter(/^in:unseen$/i) do |posts|
     if @guardian.user
       posts

[... diff too long, it was truncated ...]

GitHub sha: 4abbe3d3

1 Like

This commit appears in #10715 which was approved by eviltrout. It was merged by nbianca.