Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
cmmarslender committed Jul 25, 2019
2 parents b11ea2c + 2eae5c3 commit acb6e63
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 33 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file, per [the Keep a Changelog standard](http://keepachangelog.com/).

## [3.1.1] - 2019-07-25
### Fixed
- Ensure taxonomies that are shared among multiple post types show up on the weighting screen

## [3.1.0] - 2019-07-22
### Added
- Support for nested tax queries. Props [@dkotter](https://github.com/dkotter)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"require-dev": {
"10up/phpcs-composer": "dev-master",
"wpackagist-plugin/woocommerce":"dev-trunk"
"wpackagist-plugin/woocommerce":"*"
},
"scripts": {
"lint": "phpcs .",
Expand Down
16 changes: 6 additions & 10 deletions composer.lock

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

4 changes: 2 additions & 2 deletions elasticpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: ElasticPress
* Description: A fast and flexible search and query engine for WordPress.
* Version: 3.1
* Version: 3.1.1
* Author: 10up
* Author URI: http://10up.com
* License: GPLv2 or later
Expand All @@ -27,7 +27,7 @@

define( 'EP_URL', plugin_dir_url( __FILE__ ) );
define( 'EP_PATH', plugin_dir_path( __FILE__ ) );
define( 'EP_VERSION', '3.1' );
define( 'EP_VERSION', '3.1.1' );

/**
* PSR-4-ish autoloading
Expand Down
14 changes: 9 additions & 5 deletions includes/classes/Feature/Search/Weighting.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ public function get_weightable_fields_for_post_type( $post_type ) {
),
);

$taxonomies = get_taxonomies(
$public_taxonomies = get_taxonomies(
[
'public' => true,
'object_type' => [ $post_type ],
'public' => true,
]
);

$post_type_taxonomies = get_object_taxonomies( $post_type );

$taxonomies = array_intersect( $public_taxonomies, $post_type_taxonomies );

if ( $taxonomies ) {
$fields['taxonomies'] = [
'label' => __( 'Taxonomies', 'elasticpress' ),
Expand Down Expand Up @@ -203,7 +206,7 @@ public function render_settings_page() {
* @param array $current_values Current stored weighting values
*/
public function render_settings_section( $post_type, $field, $current_values ) {
if ( isset( $field['children'] ) ) :
if ( isset( $field['children'] ) && ! empty( $field['children'] ) ) :
?>
<div class="field-group">
<h3><?php echo esc_html( $field['label'] ); ?></h3>
Expand Down Expand Up @@ -338,9 +341,10 @@ public function recursively_inject_weights_to_fields( &$fieldset, $weights ) {
if ( 0 !== $weight ) {
$fieldset['fields'][ $key ] = "{$field}^{$weight}";
}
} else {
} elseif ( isset( $weights[ $field ] ) && false === $weights[ $field ]['enabled'] ) {
unset( $fieldset['fields'][ $key ] );
}
// else: Leave anything that isn't explicitly disabled alone. Could have been added by search_fields, and if it is not present in the UI, we shouldn't touch it here

// If fieldset has fuzziness enabled and fuzziness is disabled for this field, unset the field
if ( isset( $fieldset['fuzziness'] ) && $fieldset['fuzziness'] && isset( $weights[ $field ]['fuzziness'] ) && false === $weights[ $field ]['fuzziness'] ) {
Expand Down
20 changes: 18 additions & 2 deletions includes/classes/Feature/SearchOrdering/SearchOrdering.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function setup() {
/** Search Feature @var Feature\Search\Search $search */
$search = $features->get_registered_feature( 'search' );

if ( ! $search->is_active() ) {
if ( ! $search->is_active() && $this->is_active() ) {
$features->deactivate_feature( $this->slug );
return;
}
Expand All @@ -74,6 +74,7 @@ public function setup() {
add_action( 'posts_results', [ $this, 'posts_results' ], 20, 2 ); // Runs after core ES is done
add_action( 'rest_api_init', [ $this, 'rest_api_init' ] );
add_filter( 'ep_sync_taxonomies', [ $this, 'filter_sync_taxonomies' ] );
add_filter( 'ep_weighting_fields_for_post_type', [ $this, 'weighting_fields_for_post_type' ], 1, 2 );
add_filter( 'ep_weighting_configuration_for_search', [ $this, 'filter_weighting_configuration' ], 10, 2 );
add_filter( 'ep_weighting_configuration_for_autosuggest', [ $this, 'filter_weighting_configuration' ], 10, 1 );
add_filter( 'ep_weighting_configuration_defaults_for_autosuggest', [ $this, 'filter_weighting_configuration' ], 10, 1 );
Expand Down Expand Up @@ -102,7 +103,6 @@ public function requirements_status() {
$search = $features->get_registered_feature( 'search' );

if ( ! $search->is_active() ) {
$features->deactivate_feature( $this->slug );
return new FeatureRequirementsStatus( 2, __( 'This feature requires the "Post Search" feature to be enabled', 'elasticpress' ) );
}

Expand Down Expand Up @@ -464,6 +464,22 @@ public function create_or_return_custom_result_term( $term_name ) {
return $term;
}

/**
* Filters available fields for weighting to exclude the custom results taxonomy
*
* @param array $fields Current weightable fields
* @param string $post_type Current post type
*
* @return array Final weightable fields
*/
public function weighting_fields_for_post_type( $fields, $post_type ) {
if ( isset( $fields['taxonomies'] ) && isset( $fields['taxonomies']['children'] ) && isset( $fields['taxonomies']['children'][ 'terms.' . self::TAXONOMY_NAME . '.name' ] ) ) {
unset( $fields['taxonomies']['children'][ 'terms.' . self::TAXONOMY_NAME . '.name' ] );
}

return $fields;
}

/**
* Filters the weighting configuration to insert our weighting config when we're searching
*
Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Please refer to [Github](https://github.com/10up/ElasticPress) for detailed usag

== Changelog ==

= 3.1.1 =
- Ensure taxonomies that are shared among multiple post types show up on the weighting screen

= 3.1.0 =

- Support for nested tax queries. Props [@dkotter](https://github.com/dkotter)
Expand Down
24 changes: 14 additions & 10 deletions tests/features/TestSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,13 @@ public function testDecayingEnabled() {
isset(
$this->fired_actions['ep_formatted_args']['query'],
$this->fired_actions['ep_formatted_args']['query']['function_score'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['exp'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['exp']['post_date_gmt'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['exp']['post_date_gmt']['scale'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['exp']['post_date_gmt']['decay'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['exp']['post_date_gmt']['offset']
$this->fired_actions['ep_formatted_args']['query']['function_score']['functions'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['functions'][0],
$this->fired_actions['ep_formatted_args']['query']['function_score']['functions'][0]['exp'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['functions'][0]['exp']['post_date_gmt'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['functions'][0]['exp']['post_date_gmt']['scale'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['functions'][0]['exp']['post_date_gmt']['decay'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['functions'][0]['exp']['post_date_gmt']['offset']
)
);
}
Expand Down Expand Up @@ -212,11 +214,13 @@ public function testDecayingDisabled() {
$this->assertTrue(
! isset(
$this->fired_actions['ep_formatted_args']['query']['function_score'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['exp'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['exp']['post_date_gmt'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['exp']['post_date_gmt']['scale'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['exp']['post_date_gmt']['decay'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['exp']['post_date_gmt']['offset']
$this->fired_actions['ep_formatted_args']['query']['function_score']['functions'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['functions'][0],
$this->fired_actions['ep_formatted_args']['query']['function_score']['functions'][0]['exp'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['functions'][0]['exp']['post_date_gmt'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['functions'][0]['exp']['post_date_gmt']['scale'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['functions'][0]['exp']['post_date_gmt']['decay'],
$this->fired_actions['ep_formatted_args']['query']['function_score']['functions'][0]['exp']['post_date_gmt']['offset']
)
);
$this->assertTrue(
Expand Down
8 changes: 5 additions & 3 deletions tests/indexables/TestPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,9 @@ public function testSearchMetaQuery() {
$this->assertEquals( 2, $query->post_count );
$this->assertEquals( 2, $query->found_posts );

// Only check for fields which are provided in search_fields.
// Only check for fields which are provided in search_fields and weighting.
// Weighting always defaults to enabling post_title, so we assume that will match as well
// unless disabled in the UI
$args = array(
's' => 'findme',
'search_fields' => array(
Expand All @@ -1443,8 +1445,8 @@ public function testSearchMetaQuery() {

$query = new \WP_Query( $args );

$this->assertEquals( 1, $query->post_count );
$this->assertEquals( 1, $query->found_posts );
$this->assertEquals( 2, $query->post_count );
$this->assertEquals( 2, $query->found_posts );
}

/**
Expand Down

0 comments on commit acb6e63

Please sign in to comment.