Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tlovett1 committed Nov 1, 2017
2 parents 2575230 + cdfca16 commit f1b4c54
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 26 deletions.
2 changes: 1 addition & 1 deletion features/autosuggest/assets/js/autosuggest.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 28 additions & 13 deletions features/autosuggest/assets/js/src/autosuggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,15 @@
* @param searchText
* @returns object
*/
function buildSearchQuery( searchText, postType, searchFields ) {
function buildSearchQuery( searchText, postType, postStatus, searchFields ) {
if ( postType === 'all' || typeof( postType ) === 'undefined' || postType === '' ) {
postType = 'all';
}

if ( postStatus === '' ) {
postType = 'publish';
}

var query = {
sort: [
{
Expand All @@ -105,20 +109,30 @@
}
};

// If we're specifying post types, do it in an array
// If we're specifying post types/statuses, do it in an array
if ( typeof postType === 'string' && postType !== 'all' ) {
postType = postType.split(',');
postType = postType.split( ',' );
}

if ( typeof postStatus === 'string' ) {
postStatus = postStatus.split( ',' );
}

// Then add it as a filter to the end of the query
if ( $.isArray( postType ) ) {
query.post_filter = {
bool: {
must: [{
terms: { 'post_type.raw': postType }
}]
}
};
query.post_filter = {
bool: {
must: [
{
terms: { post_status: postStatus }
}
]
}
};

if ( 'all' !== postType ) {
query.post_filter.bool.must.push( {
terms: { 'post_type.raw': postType }
} );
}

return query;
Expand Down Expand Up @@ -168,7 +182,7 @@
}

for ( i = 0; i < options.length; ++i ) {
var text = options[i].text.toLowerCase();
var text = options[i].text;
var url = options[i].url;
itemString = '<li><span class="autosuggest-item" data-search="' + text + '" data-url="' + url + '">' + text + '</span></li>';
$( itemString ).appendTo( $localSuggestList );
Expand Down Expand Up @@ -303,10 +317,11 @@
var query;
var request;
var postType = epas.postType;
var postStatus = epas.postStatus;
var searchFields = epas.searchFields;

if ( val.length >= 2 ) {
query = buildSearchQuery( val, postType, searchFields );
query = buildSearchQuery( val, postType, postStatus, searchFields );
request = esSearch( query );

request.done( function( response ) {
Expand Down
3 changes: 2 additions & 1 deletion features/autosuggest/autosuggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ function ep_autosuggest_enqueue_scripts() {
*/
wp_localize_script( 'elasticpress-autosuggest', 'epas', apply_filters( 'ep_autosuggest_options', array(
'endpointUrl' => esc_url( untrailingslashit( $endpoint_url ) ),
'postType' => apply_filters( 'ep_term_suggest_post_type', 'all' ),
'postType' => apply_filters( 'ep_term_suggest_post_type', array( 'post', 'page' ) ),
'postStatus' => apply_filters( 'ep_term_suggest_post_status', 'publish' ),
'searchFields' => apply_filters( 'ep_term_suggest_search_fields', array(
'post_title.suggest',
'term_suggest',
Expand Down
22 changes: 11 additions & 11 deletions lang/elasticpress.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: ElasticPress 2.4\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/elasticpress\n"
"POT-Creation-Date: 2017-10-04 22:21:05+00:00\n"
"POT-Creation-Date: 2017-11-01 20:37:24+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down Expand Up @@ -143,27 +143,27 @@ msgstr ""
msgid "Unable to reach Elasticsearch Server! Check that service is running."
msgstr ""

#: classes/class-ep-api.php:2183
#: classes/class-ep-api.php:2212
msgid ""
"Invalid response from ElasticPress server. Please contact your "
"administrator."
msgstr ""

#: classes/class-ep-api.php:2196
#: classes/class-ep-api.php:2225
msgid ""
"Site not indexed. <p>Please run: <code>wp elasticpress index --setup "
"--network-wide</code> using WP-CLI. Or use the index button on the left of "
"this screen.</p>"
msgstr ""

#: classes/class-ep-api.php:2200
#: classes/class-ep-api.php:2229
msgid ""
"Site not indexed. <p>Please run: <code>wp elasticpress index --setup</code> "
"using WP-CLI. Or use the index button on the left of this screen.</p>"
msgstr ""

#: classes/class-ep-api.php:2335 classes/class-ep-api.php:2447
#: classes/class-ep-api.php:2498
#: classes/class-ep-api.php:2364 classes/class-ep-api.php:2476
#: classes/class-ep-api.php:2527
msgid "Elasticsearch Host is not available."
msgstr ""

Expand Down Expand Up @@ -336,14 +336,14 @@ msgstr ""
msgid "This address will be exposed to the public."
msgstr ""

#: features/autosuggest/autosuggest.php:206
#: features/autosuggest/autosuggest.php:207
msgid ""
"This feature modifies the site’s default user experience by presenting a "
"list of suggestions below detected search fields as text is entered into "
"the field."
msgstr ""

#: features/autosuggest/autosuggest.php:209
#: features/autosuggest/autosuggest.php:210
msgid ""
"You aren't using <a href='https://elasticpress.io'>ElasticPress.io</a> so "
"we can't be sure your host is properly secured. Autosuggest requires a "
Expand Down Expand Up @@ -457,14 +457,14 @@ msgstr ""
msgid "Weight results by date"
msgstr ""

#: features/woocommerce/woocommerce.php:661
#: features/woocommerce/woocommerce.php:672
msgid ""
"“I want a cotton, woman’s t-shirt, for under $15 that’s in stock.” Faceted "
"product browsing strains servers and increases load times. Your buyers can "
"find the perfect product quickly, and buy it quickly."
msgstr ""

#: features/woocommerce/woocommerce.php:672
#: features/woocommerce/woocommerce.php:683
msgid ""
"Most caching and performance tools can’t keep up with the nearly infinite "
"ways your visitors might filter or navigate your products. No matter how "
Expand All @@ -474,7 +474,7 @@ msgid ""
"end product management."
msgstr ""

#: features/woocommerce/woocommerce.php:686
#: features/woocommerce/woocommerce.php:697
msgid "WooCommerce not installed."
msgstr ""

Expand Down

0 comments on commit f1b4c54

Please sign in to comment.