From 0d6573038b65ad36b22f160600faa55851a6a1a6 Mon Sep 17 00:00:00 2001 From: Rafael Chaves Freitas Date: Sun, 24 May 2020 14:20:29 -0300 Subject: [PATCH 1/2] swap implode parameters in Elastic_Press class to be compatible with php 7.4 --- src/classes/class-tainacan-elastic-press.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/classes/class-tainacan-elastic-press.php b/src/classes/class-tainacan-elastic-press.php index 01e2a4eb7..886f20605 100644 --- a/src/classes/class-tainacan-elastic-press.php +++ b/src/classes/class-tainacan-elastic-press.php @@ -445,7 +445,7 @@ class Elastic_Press { if (!empty($filter['include'])) { $custom_filter_include = $custom_filter; $custom_filter_include['bool']['must'][] = ["bool" => [ "must"=> [ [ "terms" => ["$field.term_id" => $filter['include'] ] ] ] ] ]; - $terms_id_inlcude = \implode($filter['include'], ","); + $terms_id_inlcude = \implode( ",", $filter['include']); $aggs[$id.'.include'] = [ "filter" => $custom_filter_include, "aggs" => array( @@ -479,7 +479,7 @@ class Elastic_Press { $custom_filter_include = $custom_filter; $custom_filter_include['bool']['must'][] = ["bool" => [ "must"=> [ [ "terms" => ["$field" => $filter['include'] ] ] ] ] ]; $meta_label = explode(".",$id)[1] . '.' . explode(".",$id)[2]; - $meta_id_inlcude = "'" . \implode($filter['include'], "','") . "'"; + $meta_id_inlcude = "'" . \implode("','", $filter['include']) . "'"; $aggs[$id.'.include'] = [ "filter" => $custom_filter_include, "aggs" => array( From fa2739ea72e72aebc5d468de8f9b952f3cf154c6 Mon Sep 17 00:00:00 2001 From: Rafael Chaves Freitas Date: Sun, 24 May 2020 14:21:39 -0300 Subject: [PATCH 2/2] add filter to ElasticPress track total hits --- src/classes/class-tainacan-elastic-press.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/classes/class-tainacan-elastic-press.php b/src/classes/class-tainacan-elastic-press.php index 886f20605..f139faa8c 100644 --- a/src/classes/class-tainacan-elastic-press.php +++ b/src/classes/class-tainacan-elastic-press.php @@ -48,6 +48,11 @@ class Elastic_Press { add_filter( 'ep_config_mapping', [$this, 'elasticpress_config_mapping'], 10, 1 ); add_filter( 'ep_post_sync_args', [$this, 'ep_post_sync_args'], 10, 2 ); + add_filter( 'ep_formatted_args', function ( $formatted_args ) { + $formatted_args['track_total_hits'] = true; + return $formatted_args; + } ); + // add_action('ep_add_query_log', function($query) { //using to DEBUG // error_log("DEGUG:"); // error_log($query["args"]["body"]);