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_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);
|
||||
|
|
|
@ -153,7 +153,7 @@
|
|||
<div class="controls">
|
||||
{{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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue