mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 04:31:56 +08:00
FEATURE: allow searching in title in advanced search
Add UI for matching in title only in advanced search options
This commit is contained in:
parent
11b544ef4e
commit
ed08545d1f
|
@ -18,6 +18,7 @@ const REGEXP_TAGS_REPLACE = /(^(tags?:|#(?=[a-z0-9\-]+::tag))|::tag\s?$
|
|||
|
||||
const REGEXP_IN_MATCH = /^(in|with):(posted|watching|tracking|bookmarks|first|pinned|unpinned|wiki|unseen|image)/ig;
|
||||
const REGEXP_SPECIAL_IN_LIKES_MATCH = /^in:likes/ig;
|
||||
const REGEXP_SPECIAL_IN_TITLE_MATCH = /^in:title/ig;
|
||||
const REGEXP_SPECIAL_IN_PRIVATE_MATCH = /^in:private/ig;
|
||||
const REGEXP_SPECIAL_IN_SEEN_MATCH = /^in:seen/ig;
|
||||
|
||||
|
@ -81,6 +82,7 @@ export default Em.Component.extend({
|
|||
in: '',
|
||||
special: {
|
||||
in: {
|
||||
title: false,
|
||||
likes: false,
|
||||
private: false,
|
||||
seen: false
|
||||
|
@ -111,6 +113,7 @@ export default Em.Component.extend({
|
|||
this.setSearchedTermValueForTags();
|
||||
this.setSearchedTermValue('searchedTerms.in', REGEXP_IN_PREFIX, REGEXP_IN_MATCH);
|
||||
this.setSearchedTermSpecialInValue('searchedTerms.special.in.likes', REGEXP_SPECIAL_IN_LIKES_MATCH);
|
||||
this.setSearchedTermSpecialInValue('searchedTerms.special.in.title', REGEXP_SPECIAL_IN_TITLE_MATCH);
|
||||
this.setSearchedTermSpecialInValue('searchedTerms.special.in.private', REGEXP_SPECIAL_IN_PRIVATE_MATCH);
|
||||
this.setSearchedTermSpecialInValue('searchedTerms.special.in.seen', REGEXP_SPECIAL_IN_SEEN_MATCH);
|
||||
this.setSearchedTermValue('searchedTerms.status', REGEXP_STATUS_PREFIX);
|
||||
|
@ -424,15 +427,14 @@ export default Em.Component.extend({
|
|||
}
|
||||
},
|
||||
|
||||
@observes('searchedTerms.special.in.likes')
|
||||
updateSearchTermForSpecialInLikes() {
|
||||
const match = this.filterBlocks(REGEXP_SPECIAL_IN_LIKES_MATCH);
|
||||
const inFilter = this.get('searchedTerms.special.in.likes');
|
||||
updateInRegex(regex, filter) {
|
||||
const match = this.filterBlocks(regex);
|
||||
const inFilter = this.get('searchedTerms.special.in.' + filter);
|
||||
let searchTerm = this.get('searchTerm') || '';
|
||||
|
||||
if (inFilter) {
|
||||
if (match.length === 0) {
|
||||
searchTerm += ` in:likes`;
|
||||
searchTerm += ` in:${filter}`;
|
||||
this.set('searchTerm', searchTerm.trim());
|
||||
}
|
||||
} else if (match.length !== 0) {
|
||||
|
@ -441,38 +443,24 @@ export default Em.Component.extend({
|
|||
}
|
||||
},
|
||||
|
||||
@observes('searchedTerms.special.in.likes')
|
||||
updateSearchTermForSpecialInLikes() {
|
||||
this.updateInRegex(REGEXP_SPECIAL_IN_LIKES_MATCH, 'likes');
|
||||
},
|
||||
|
||||
@observes('searchedTerms.special.in.private')
|
||||
updateSearchTermForSpecialInPrivate() {
|
||||
const match = this.filterBlocks(REGEXP_SPECIAL_IN_PRIVATE_MATCH);
|
||||
const inFilter = this.get('searchedTerms.special.in.private');
|
||||
let searchTerm = this.get('searchTerm') || '';
|
||||
|
||||
if (inFilter) {
|
||||
if (match.length === 0) {
|
||||
searchTerm += ` in:private`;
|
||||
this.set('searchTerm', searchTerm.trim());
|
||||
}
|
||||
} else if (match.length !== 0) {
|
||||
searchTerm = searchTerm.replace(match, '');
|
||||
this.set('searchTerm', searchTerm.trim());
|
||||
}
|
||||
this.updateInRegex(REGEXP_SPECIAL_IN_PRIVATE_MATCH, 'private');
|
||||
},
|
||||
|
||||
@observes('searchedTerms.special.in.seen')
|
||||
updateSearchTermForSpecialInSeen() {
|
||||
const match = this.filterBlocks(REGEXP_SPECIAL_IN_SEEN_MATCH);
|
||||
const inFilter = this.get('searchedTerms.special.in.seen');
|
||||
let searchTerm = this.get('searchTerm') || '';
|
||||
this.updateInRegex(REGEXP_SPECIAL_IN_SEEN_MATCH, 'seen');
|
||||
},
|
||||
|
||||
if (inFilter) {
|
||||
if (match.length === 0) {
|
||||
searchTerm += ` in:seen`;
|
||||
this.set('searchTerm', searchTerm.trim());
|
||||
}
|
||||
} else if (match.length !== 0) {
|
||||
searchTerm = searchTerm.replace(match, '');
|
||||
this.set('searchTerm', searchTerm.trim());
|
||||
}
|
||||
@observes('searchedTerms.special.in.title')
|
||||
updateSearchTermForSpecialInTitle() {
|
||||
this.updateInRegex(REGEXP_SPECIAL_IN_TITLE_MATCH, 'title');
|
||||
},
|
||||
|
||||
@observes('searchedTerms.status')
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
<div class="controls">
|
||||
{{#if currentUser}}
|
||||
<section class='field'>
|
||||
<label>{{input type="checkbox" class="in-likes" checked=searchedTerms.special.in.title}} {{i18n "search.advanced.filters.title"}}</label>
|
||||
<label>{{input type="checkbox" class="in-likes" checked=searchedTerms.special.in.likes}} {{i18n "search.advanced.filters.likes"}}</label>
|
||||
<label>{{input type="checkbox" class="in-private" checked=searchedTerms.special.in.private}} {{i18n "search.advanced.filters.private"}}</label>
|
||||
<label>{{input type="checkbox" class="in-seen" checked=searchedTerms.special.in.seen}} {{i18n "search.advanced.filters.seen"}}</label>
|
||||
|
|
|
@ -1508,6 +1508,7 @@ en:
|
|||
label: Tagged
|
||||
filters:
|
||||
label: Only return topics/posts...
|
||||
title: Matching in title only
|
||||
likes: I liked
|
||||
posted: I posted in
|
||||
watching: I'm watching
|
||||
|
|
Loading…
Reference in New Issue
Block a user