FEATURE: if full search returns no results, show google search form

This commit is contained in:
Neil Lalonde 2017-08-14 18:07:49 -04:00
parent 4085c40e50
commit d506e577a5
8 changed files with 65 additions and 8 deletions

View File

@ -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('/')}`;
}
});

View File

@ -87,6 +87,11 @@ export default Ember.Controller.extend({
return escapeExpression(q);
},
@computed('canCreateTopic', 'siteSettings.login_required')
showSuggestion(canCreateTopic, loginRequired) {
return canCreateTopic || !loginRequired;
},
_searchOnSortChange: true,
setSearchTerm(term) {

View File

@ -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>

View File

@ -15,7 +15,9 @@
{{/if}}
</div>
{{create-topic-button canCreateTopic=canCreateTopic action=(action "createTopic" searchTerm)}}
{{#if hasResults}}
{{create-topic-button canCreateTopic=canCreateTopic action=(action "createTopic" searchTerm)}}
{{/if}}
{{#if canBulkSelect}}
{{d-button icon="list" class="bulk-select" title="topics.bulk.toggle" action="toggleBulkSelect"}}
@ -116,11 +118,25 @@
{{#conditional-loading-spinner condition=loading }}
{{#unless hasResults}}
<h3>
{{#if searchActive}}
{{i18n "search.no_results"}}
{{#if searchActive}}
<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}}
</h3>
{{/if}}
{{/unless}}
{{#if hasResults}}

View File

@ -108,7 +108,7 @@
}
.search-advanced-options {
border: 1px solid $primary-low;
border: 1px solid $primary-low;
padding: 10px;
.control-group.pull-left {
@ -121,6 +121,9 @@
}
}
.no-results-suggestion {
margin-top: 30px;
}
.search-footer {
margin-bottom: 30px;
}
@ -162,3 +165,7 @@
margin-bottom: 4px;
}
}
.google-search-form {
margin-top: 2em;
}

View File

@ -34,7 +34,7 @@
<p>
<form action='//google.com/search' id='google-search'>
<input type="text" name="q" value="<%= @slug %>">
<input type='hidden'name="as_sitesearch" value="<%= local_domain %>">
<input type='hidden' name="as_sitesearch" value="<%= local_domain %>">
<button class="btn btn-primary"><%= t 'page_not_found.search_google' %></button>
</form>
</p>

View File

@ -1353,6 +1353,12 @@ en:
post_format: "#{{post_number}} by {{username}}"
results_page: "Search Results"
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:
user: "Search posts by @{{username}}"

View File

@ -53,7 +53,10 @@ QUnit.test("perform various searches", assert => {
fillIn('.search input.full-page-search', 'none');
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');
click('.search .btn-primary');