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 3c2e753abb5..b2ddfc879d1 100644 --- a/app/assets/javascripts/discourse/app/components/search-advanced-options.js +++ b/app/assets/javascripts/discourse/app/components/search-advanced-options.js @@ -11,7 +11,7 @@ const REGEXP_CATEGORY_PREFIX = /^(category:|#)/gi; const REGEXP_TAGS_PREFIX = /^(tags?:|#(?=[a-z0-9\-]+::tag))/gi; const REGEXP_IN_PREFIX = /^(in|with):/gi; const REGEXP_STATUS_PREFIX = /^status:/gi; -const REGEXP_MIN_POST_COUNT_PREFIX = /^min_post_count:/gi; +const REGEXP_MIN_POSTS_PREFIX = /^min_posts:/gi; const REGEXP_MIN_VIEWS_PREFIX = /^min_views:/gi; const REGEXP_MAX_VIEWS_PREFIX = /^max_views:/gi; const REGEXP_POST_TIME_PREFIX = /^(before|after):/gi; @@ -94,7 +94,7 @@ export default Component.extend({ all_tags: false, }, status: null, - min_post_count: null, + min_posts: null, min_views: null, max_views: null, time: { @@ -162,8 +162,8 @@ export default Component.extend({ this.setSearchedTermValueForPostTime(); this.setSearchedTermValue( - "searchedTerms.min_post_count", - REGEXP_MIN_POST_COUNT_PREFIX + "searchedTerms.min_posts", + REGEXP_MIN_POSTS_PREFIX ); this.setSearchedTermValue( @@ -355,7 +355,7 @@ export default Component.extend({ @action onChangeSearchTermMinPostCount(value) { - this.set("searchedTerms.min_post_count", value.length ? value : null); + this.set("searchedTerms.min_posts", value.length ? value : null); this._updateSearchTermForMinPostCount(); }, @@ -632,18 +632,18 @@ export default Component.extend({ }, _updateSearchTermForMinPostCount() { - const match = this.filterBlocks(REGEXP_MIN_POST_COUNT_PREFIX); - const postsCountFilter = this.get("searchedTerms.min_post_count"); + const match = this.filterBlocks(REGEXP_MIN_POSTS_PREFIX); + const postsCountFilter = this.get("searchedTerms.min_posts"); let searchTerm = this.searchTerm || ""; if (postsCountFilter) { if (match.length !== 0) { searchTerm = searchTerm.replace( match[0], - `min_post_count:${postsCountFilter}` + `min_posts:${postsCountFilter}` ); } else { - searchTerm += ` min_post_count:${postsCountFilter}`; + searchTerm += ` min_posts:${postsCountFilter}`; } this._updateSearchTerm(searchTerm); diff --git a/app/assets/javascripts/discourse/app/templates/components/search-advanced-options.hbs b/app/assets/javascripts/discourse/app/templates/components/search-advanced-options.hbs index dc83db3c8fa..a12f34e25e1 100644 --- a/app/assets/javascripts/discourse/app/templates/components/search-advanced-options.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/search-advanced-options.hbs @@ -153,7 +153,7 @@
{{input type="number" - value=(readonly searchedTerms.min_post_count) + value=(readonly searchedTerms.min_posts) class="input-small" id="search-min-post-count" input=(action "onChangeSearchTermMinPostCount" value="target.value") diff --git a/lib/search.rb b/lib/search.rb index dcd7ded42a1..9284ac95c59 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -369,6 +369,10 @@ class Search posts.where("topics.posts_count = ?", match.to_i) end + advanced_filter(/^min_posts:(\d+)$/i) do |posts, match| + posts.where("topics.posts_count >= ?", match.to_i) + end + advanced_filter(/^min_post_count:(\d+)$/i) do |posts, match| posts.where("topics.posts_count >= ?", match.to_i) end diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb index 68469b3847c..113276085fd 100644 --- a/spec/components/search_spec.rb +++ b/spec/components/search_spec.rb @@ -1278,6 +1278,7 @@ describe Search do expect(Search.execute('test STATUS:OPEN').posts.length).to eq(1) expect(Search.execute('test posts_count:1').posts.length).to eq(1) expect(Search.execute('test min_post_count:1').posts.length).to eq(1) + expect(Search.execute('test min_posts:1').posts.length).to eq(1) topic.update(closed: true) second_topic.update(category: public_category)