mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 14:12:10 +08:00
FEATURE: if full search returns no results, show google search form
This commit is contained in:
@ -0,0 +1,13 @@
|
|||||||
|
import computed from "ember-addons/ember-computed-decorators";
|
||||||
|
|
||||||
|
export default Ember.Component.extend({
|
||||||
|
classNames: ['google-search-form'],
|
||||||
|
classNameBindings: ['hidden:hidden'],
|
||||||
|
|
||||||
|
hidden: Ember.computed.alias('siteSettings.login_required'),
|
||||||
|
|
||||||
|
@computed
|
||||||
|
siteUrl() {
|
||||||
|
return `${location.protocol}//${location.host}${Discourse.getURL('/')}`;
|
||||||
|
}
|
||||||
|
});
|
@ -87,6 +87,11 @@ export default Ember.Controller.extend({
|
|||||||
return escapeExpression(q);
|
return escapeExpression(q);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@computed('canCreateTopic', 'siteSettings.login_required')
|
||||||
|
showSuggestion(canCreateTopic, loginRequired) {
|
||||||
|
return canCreateTopic || !loginRequired;
|
||||||
|
},
|
||||||
|
|
||||||
_searchOnSortChange: true,
|
_searchOnSortChange: true,
|
||||||
|
|
||||||
setSearchTerm(term) {
|
setSearchTerm(term) {
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
<div>
|
||||||
|
<form action='//google.com/search' id='google-search'>
|
||||||
|
<input type="text" name="q" value="{{searchTerm}}">
|
||||||
|
<input type='hidden' name="as_sitesearch" value="{{siteUrl}}">
|
||||||
|
<button class="btn btn-primary">{{i18n 'search.search_google_button'}}</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
@ -15,7 +15,9 @@
|
|||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{#if hasResults}}
|
||||||
{{create-topic-button canCreateTopic=canCreateTopic action=(action "createTopic" searchTerm)}}
|
{{create-topic-button canCreateTopic=canCreateTopic action=(action "createTopic" searchTerm)}}
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
{{#if canBulkSelect}}
|
{{#if canBulkSelect}}
|
||||||
{{d-button icon="list" class="bulk-select" title="topics.bulk.toggle" action="toggleBulkSelect"}}
|
{{d-button icon="list" class="bulk-select" title="topics.bulk.toggle" action="toggleBulkSelect"}}
|
||||||
@ -116,11 +118,25 @@
|
|||||||
|
|
||||||
{{#conditional-loading-spinner condition=loading }}
|
{{#conditional-loading-spinner condition=loading }}
|
||||||
{{#unless hasResults}}
|
{{#unless hasResults}}
|
||||||
<h3>
|
|
||||||
{{#if searchActive}}
|
{{#if searchActive}}
|
||||||
{{i18n "search.no_results"}}
|
<h3>{{i18n "search.no_results"}}</h3>
|
||||||
|
|
||||||
|
{{#if showSuggestion}}
|
||||||
|
<div class="no-results-suggestion">
|
||||||
|
{{i18n "search.cant_find"}}
|
||||||
|
{{#if canCreateTopic}}
|
||||||
|
<a href {{action "createTopic" searchTerm}}>{{i18n "search.start_new_topic"}}</a>
|
||||||
|
{{#unless siteSettings.login_required}}
|
||||||
|
{{i18n "search.or_search_google"}}
|
||||||
|
{{/unless}}
|
||||||
|
{{else}}
|
||||||
|
{{i18n "search.search_google"}}
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{{google-search searchTerm=searchTerm}}
|
||||||
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</h3>
|
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
|
||||||
{{#if hasResults}}
|
{{#if hasResults}}
|
||||||
|
@ -121,6 +121,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.no-results-suggestion {
|
||||||
|
margin-top: 30px;
|
||||||
|
}
|
||||||
.search-footer {
|
.search-footer {
|
||||||
margin-bottom: 30px;
|
margin-bottom: 30px;
|
||||||
}
|
}
|
||||||
@ -162,3 +165,7 @@
|
|||||||
margin-bottom: 4px;
|
margin-bottom: 4px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.google-search-form {
|
||||||
|
margin-top: 2em;
|
||||||
|
}
|
||||||
|
@ -1353,6 +1353,12 @@ en:
|
|||||||
post_format: "#{{post_number}} by {{username}}"
|
post_format: "#{{post_number}} by {{username}}"
|
||||||
results_page: "Search Results"
|
results_page: "Search Results"
|
||||||
more_results: "There are more results. Please narrow your search criteria."
|
more_results: "There are more results. Please narrow your search criteria."
|
||||||
|
cant_find: "Can't find what you're looking for?"
|
||||||
|
start_new_topic: "Why not create a topic?"
|
||||||
|
or_search_google: "Or use Google to search instead:"
|
||||||
|
search_google: "Try searching with Google instead:"
|
||||||
|
search_google_button: "Google"
|
||||||
|
search_google_title: "Search this site"
|
||||||
|
|
||||||
context:
|
context:
|
||||||
user: "Search posts by @{{username}}"
|
user: "Search posts by @{{username}}"
|
||||||
|
@ -53,7 +53,10 @@ QUnit.test("perform various searches", assert => {
|
|||||||
fillIn('.search input.full-page-search', 'none');
|
fillIn('.search input.full-page-search', 'none');
|
||||||
click('.search .btn-primary');
|
click('.search .btn-primary');
|
||||||
|
|
||||||
andThen(() => assert.ok(find('.fps-topic').length === 0), 'has no results');
|
andThen(() => {
|
||||||
|
assert.ok(find('.fps-topic').length === 0, 'has no results');
|
||||||
|
assert.ok(find('.no-results-suggestion .google-search-form'));
|
||||||
|
});
|
||||||
|
|
||||||
fillIn('.search input.full-page-search', 'posts');
|
fillIn('.search input.full-page-search', 'posts');
|
||||||
click('.search .btn-primary');
|
click('.search .btn-primary');
|
||||||
|
Reference in New Issue
Block a user