Skip to content

Commit

Permalink
Merge branch 'hotfix-es-50'
Browse files Browse the repository at this point in the history
  • Loading branch information
tlovett1 committed Nov 11, 2016
2 parents 8ce41db + 8db8f52 commit dbcb82f
Show file tree
Hide file tree
Showing 8 changed files with 419 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A fast and flexible search and query engine for WordPress.

**Please note:** master is the stable branch

**Upgrade Notice:** Versions 1.6.1, 1.6.2, 1.7, 1.8, 2.1 require re-syncing.
**Upgrade Notice:** Versions 1.6.1, 1.6.2, 1.7, 1.8, 2.1, 2.1.2 require re-syncing.

ElasticPress, a fast and flexible search and query engine for WordPress, enables WordPress to find or “query” relevant content extremely fast through a variety of highly customizable modules. WordPress out-of-the-box struggles to analyze content relevancy and can be very slow. ElasticPress supercharges your WordPress website making for happier users and administrators.

Expand Down
88 changes: 70 additions & 18 deletions classes/class-ep-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,37 @@ public function refresh_index() {
return false;
}

/**
* Get Elasticsearch version
*
* @since 2.1.2
* @return string
*/
public function get_elasticsearch_version() {

$request_args = array( 'method' => 'GET' );

$request = ep_remote_request( '', apply_filters( 'ep_elasticsearch_version_request_args', $request_args ) );

if ( ! is_wp_error( $request ) ) {
if ( isset( $request['response']['code'] ) && 200 === $request['response']['code'] ) {
$response_body = wp_remote_retrieve_body( $request );

$response = json_decode( $response_body, true );

try {
$version = $response['version']['number'];
} catch ( Exception $e ) {
return false;
}

return $version;
}
}

return false;
}

/**
* Search for posts under a specific site index or the global index ($site_id = 0).
*
Expand Down Expand Up @@ -406,7 +437,25 @@ public function create_network_alias( $indexes ) {
* @return array|bool|mixed
*/
public function put_mapping() {
$mapping = require( apply_filters( 'ep_config_mapping_file', dirname( __FILE__ ) . '/../includes/mappings.php' ) );
if ( defined( 'EP_IS_NETWORK' ) && EP_IS_NETWORK ) {
$es_version = get_site_option( 'ep_es_version', false );
} else {
$es_version = get_option( 'ep_es_version', false );
}

$es_version = $this->get_elasticsearch_version();

if ( empty( $es_version ) ) {
$es_version = apply_filters( 'ep_fallback_elasticsearch_version', '2.0' );
}

if ( ! $es_version || version_compare( $es_version, '5.0' ) < 0 ) {
$mapping_file = 'pre-5-0.php';
} else {
$mapping_file = '5-0.php';
}

$mapping = require( apply_filters( 'ep_config_mapping_file', dirname( __FILE__ ) . '/../includes/mappings/' . $mapping_file ) );

/**
* We are removing shard/replica defaults but need to maintain the filters
Expand Down Expand Up @@ -928,7 +977,9 @@ public function format_args( $args ) {
}

$filter = array(
'and' => array(),
'bool' => array(
'must' => array(),
),
);
$use_filters = false;

Expand Down Expand Up @@ -996,7 +1047,7 @@ public function format_args( $args ) {
$relation = 'should';
}

$filter['and'][]['bool'][$relation] = $tax_filter;
$filter['bool']['must'][]['bool'][$relation] = $tax_filter;
}

$use_filters = true;
Expand All @@ -1008,7 +1059,7 @@ public function format_args( $args ) {
* @since 2.0
*/
if ( isset( $args['post_parent'] ) && '' !== $args['post_parent'] && 'any' !== strtolower( $args['post_parent'] ) ) {
$filter['and'][]['bool']['must'] = array(
$filter['bool']['must'][]['bool']['must'] = array(
'term' => array(
'post_parent' => $args['post_parent'],
),
Expand All @@ -1023,7 +1074,7 @@ public function format_args( $args ) {
* @since x.x
*/
if ( ! empty( $args['post__in'] ) ) {
$filter['and'][]['bool']['must'] = array(
$filter['bool']['must'][]['bool']['must'] = array(
'terms' => array(
'post_id' => array_values( (array) $args['post__in'] ),
),
Expand All @@ -1038,7 +1089,7 @@ public function format_args( $args ) {
* @since x.x
*/
if ( ! empty( $args['post__not_in'] ) ) {
$filter['and'][]['bool']['must_not'] = array(
$filter['bool']['must'][]['bool']['must_not'] = array(
'terms' => array(
'post_id' => (array) $args['post__not_in'],
),
Expand All @@ -1053,15 +1104,15 @@ public function format_args( $args ) {
* @since 1.0
*/
if ( ! empty( $args['author'] ) ) {
$filter['and'][] = array(
$filter['bool']['must'][] = array(
'term' => array(
'post_author.id' => $args['author'],
),
);

$use_filters = true;
} elseif ( ! empty( $args['author_name'] ) ) {
$filter['and'][] = array(
$filter['bool']['must'][] = array(
'term' => array(
'post_author.raw' => $args['author'],
),
Expand All @@ -1076,7 +1127,7 @@ public function format_args( $args ) {
* @since 1.3
*/
if ( $date_filter = EP_WP_Date_Query::simple_es_date_filter( $args ) ) {
$filter['and'][] = $date_filter;
$filter['bool']['must'][] = $date_filter;
$use_filters = true;
}

Expand All @@ -1091,7 +1142,7 @@ public function format_args( $args ) {
$date_filter = $date_query->get_es_filter();

if( array_key_exists('and', $date_filter ) ) {
$filter['and'][] = $date_filter['and'];
$filter['bool']['must'][] = $date_filter['and'];
$use_filters = true;
}

Expand Down Expand Up @@ -1380,7 +1431,7 @@ public function format_args( $args ) {
}

if ( ! empty( $meta_filter ) ) {
$filter['and'][]['bool'][$relation] = $meta_filter;
$filter['bool']['must'][]['bool'][$relation] = $meta_filter;

$use_filters = true;
}
Expand Down Expand Up @@ -1441,7 +1492,6 @@ public function format_args( $args ) {
'type' => 'phrase',
'fields' => $search_fields,
'boost' => apply_filters( 'ep_match_phrase_boost', 4, $search_fields, $args ),
'fuzziness' => 0,
)
),
array(
Expand Down Expand Up @@ -1477,7 +1527,9 @@ public function format_args( $args ) {
$query['bool']['should'][0]['multi_match']['query'] = $args['s'];
$formatted_args['query'] = $query;
} else if ( ! empty( $args['ep_match_all'] ) || ! empty( $args['ep_integrate'] ) ) {
$formatted_args['query']['match_all'] = array();
$formatted_args['query']['match_all'] = array(
'boost' => 1,
);
}

/**
Expand All @@ -1493,7 +1545,7 @@ public function format_args( $args ) {
$post_types = $post_types[0];
}

$filter['and'][] = array(
$filter['bool']['must'][] = array(
$terms_map_name => array(
'post_type.raw' => $post_types,
),
Expand All @@ -1502,7 +1554,7 @@ public function format_args( $args ) {
$use_filters = true;
}
} elseif ( empty( $args['s'] ) ) {
$filter['and'][] = array(
$filter['bool']['must'][] = array(
'term' => array(
'post_type.raw' => 'post',
),
Expand All @@ -1527,7 +1579,7 @@ public function format_args( $args ) {
$post_status = $post_status[0];
}

$filter['and'][] = array(
$filter['bool']['must'][] = array(
$terms_map_name => array(
'post_status' => $post_status,
),
Expand All @@ -1536,7 +1588,7 @@ public function format_args( $args ) {
$use_filters = true;
}
} else {
$filter['and'][] = array(
$filter['bool']['must'][] = array(
'term' => array(
'post_status' => 'publish',
),
Expand All @@ -1554,7 +1606,7 @@ public function format_args( $args ) {
}

if ( $use_filters ) {
$formatted_args['filter'] = $filter;
$formatted_args['post_filter'] = $filter;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions elasticpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Plugin Name: ElasticPress
* Description: A fast and flexible search and query engine for WordPress.
* Version: 2.1.1
* Version: 2.1.2
* Author: Taylor Lovett, Matt Gross, Aaron Holbrook, 10up
* Author URI: http://10up.com
* License: GPLv2 or later
Expand All @@ -22,7 +22,7 @@

define( 'EP_URL', plugin_dir_url( __FILE__ ) );
define( 'EP_PATH', plugin_dir_path( __FILE__ ) );
define( 'EP_VERSION', '2.1.1' );
define( 'EP_VERSION', '2.1.2' );
define( 'EP_MODULES_DIR', dirname( __FILE__ ) . '/modules' );

require_once( 'classes/class-ep-config.php' );
Expand Down
Loading

0 comments on commit dbcb82f

Please sign in to comment.