mirror of
https://github.com/discourse/discourse.git
synced 2025-03-21 04:55:46 +08:00
FEATURE: add alias for min_post_count search filter
This commit is contained in:
parent
2b254f4305
commit
4498c59085
@ -11,7 +11,7 @@ const REGEXP_CATEGORY_PREFIX = /^(category:|#)/gi;
|
|||||||
const REGEXP_TAGS_PREFIX = /^(tags?:|#(?=[a-z0-9\-]+::tag))/gi;
|
const REGEXP_TAGS_PREFIX = /^(tags?:|#(?=[a-z0-9\-]+::tag))/gi;
|
||||||
const REGEXP_IN_PREFIX = /^(in|with):/gi;
|
const REGEXP_IN_PREFIX = /^(in|with):/gi;
|
||||||
const REGEXP_STATUS_PREFIX = /^status:/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_MIN_VIEWS_PREFIX = /^min_views:/gi;
|
||||||
const REGEXP_MAX_VIEWS_PREFIX = /^max_views:/gi;
|
const REGEXP_MAX_VIEWS_PREFIX = /^max_views:/gi;
|
||||||
const REGEXP_POST_TIME_PREFIX = /^(before|after):/gi;
|
const REGEXP_POST_TIME_PREFIX = /^(before|after):/gi;
|
||||||
@ -94,7 +94,7 @@ export default Component.extend({
|
|||||||
all_tags: false,
|
all_tags: false,
|
||||||
},
|
},
|
||||||
status: null,
|
status: null,
|
||||||
min_post_count: null,
|
min_posts: null,
|
||||||
min_views: null,
|
min_views: null,
|
||||||
max_views: null,
|
max_views: null,
|
||||||
time: {
|
time: {
|
||||||
@ -162,8 +162,8 @@ export default Component.extend({
|
|||||||
this.setSearchedTermValueForPostTime();
|
this.setSearchedTermValueForPostTime();
|
||||||
|
|
||||||
this.setSearchedTermValue(
|
this.setSearchedTermValue(
|
||||||
"searchedTerms.min_post_count",
|
"searchedTerms.min_posts",
|
||||||
REGEXP_MIN_POST_COUNT_PREFIX
|
REGEXP_MIN_POSTS_PREFIX
|
||||||
);
|
);
|
||||||
|
|
||||||
this.setSearchedTermValue(
|
this.setSearchedTermValue(
|
||||||
@ -355,7 +355,7 @@ export default Component.extend({
|
|||||||
|
|
||||||
@action
|
@action
|
||||||
onChangeSearchTermMinPostCount(value) {
|
onChangeSearchTermMinPostCount(value) {
|
||||||
this.set("searchedTerms.min_post_count", value.length ? value : null);
|
this.set("searchedTerms.min_posts", value.length ? value : null);
|
||||||
this._updateSearchTermForMinPostCount();
|
this._updateSearchTermForMinPostCount();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -632,18 +632,18 @@ export default Component.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
_updateSearchTermForMinPostCount() {
|
_updateSearchTermForMinPostCount() {
|
||||||
const match = this.filterBlocks(REGEXP_MIN_POST_COUNT_PREFIX);
|
const match = this.filterBlocks(REGEXP_MIN_POSTS_PREFIX);
|
||||||
const postsCountFilter = this.get("searchedTerms.min_post_count");
|
const postsCountFilter = this.get("searchedTerms.min_posts");
|
||||||
let searchTerm = this.searchTerm || "";
|
let searchTerm = this.searchTerm || "";
|
||||||
|
|
||||||
if (postsCountFilter) {
|
if (postsCountFilter) {
|
||||||
if (match.length !== 0) {
|
if (match.length !== 0) {
|
||||||
searchTerm = searchTerm.replace(
|
searchTerm = searchTerm.replace(
|
||||||
match[0],
|
match[0],
|
||||||
`min_post_count:${postsCountFilter}`
|
`min_posts:${postsCountFilter}`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
searchTerm += ` min_post_count:${postsCountFilter}`;
|
searchTerm += ` min_posts:${postsCountFilter}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._updateSearchTerm(searchTerm);
|
this._updateSearchTerm(searchTerm);
|
||||||
|
@ -153,7 +153,7 @@
|
|||||||
<div class="controls">
|
<div class="controls">
|
||||||
{{input
|
{{input
|
||||||
type="number"
|
type="number"
|
||||||
value=(readonly searchedTerms.min_post_count)
|
value=(readonly searchedTerms.min_posts)
|
||||||
class="input-small"
|
class="input-small"
|
||||||
id="search-min-post-count"
|
id="search-min-post-count"
|
||||||
input=(action "onChangeSearchTermMinPostCount" value="target.value")
|
input=(action "onChangeSearchTermMinPostCount" value="target.value")
|
||||||
|
@ -369,6 +369,10 @@ class Search
|
|||||||
posts.where("topics.posts_count = ?", match.to_i)
|
posts.where("topics.posts_count = ?", match.to_i)
|
||||||
end
|
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|
|
advanced_filter(/^min_post_count:(\d+)$/i) do |posts, match|
|
||||||
posts.where("topics.posts_count >= ?", match.to_i)
|
posts.where("topics.posts_count >= ?", match.to_i)
|
||||||
end
|
end
|
||||||
|
@ -1278,6 +1278,7 @@ describe Search do
|
|||||||
expect(Search.execute('test STATUS:OPEN').posts.length).to eq(1)
|
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 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_post_count:1').posts.length).to eq(1)
|
||||||
|
expect(Search.execute('test min_posts:1').posts.length).to eq(1)
|
||||||
|
|
||||||
topic.update(closed: true)
|
topic.update(closed: true)
|
||||||
second_topic.update(category: public_category)
|
second_topic.update(category: public_category)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user