add count terms in API

This commit is contained in:
vnmedeiros 2019-01-21 15:44:30 -02:00
parent aa46824ece
commit 09a99da1df
2 changed files with 49 additions and 0 deletions

View File

@ -33,6 +33,7 @@ class Elastic_Press {
return; // ElasticPress not active
}
add_filter('tainacan_fetch_args', [$this, 'filter_args'], 10, 2);
//add_filter('tainacan-api-get-items-alternate', [$this, 'filter_get_metadatum_values'], 10, 2);
add_action('ep_retrieve_aggregations', function ( array $aggregations, $scope, $args ) {
$this->last_aggregations = $aggregations;
@ -163,4 +164,9 @@ class Elastic_Press {
$formatted_args['aggs'] = $aggs;
return $formatted_args;
}
function filter_get_metadatum_values($metadatum_id, $args) {
error_log("FILTER-----");
return $metadatum_id;
}
} // END

View File

@ -968,6 +968,49 @@ class Metadata extends Repository {
////////////////////////////////////////////
////////////////////////////////////////////
// TODO refactor, put elsewhere:
// if (class_exists('EP_API')) {
// $args['items_filter']['ep_integrate'] = true;
// $items = $itemsRepo->fetch($args['items_filter'], $args['collection_id'], 'WP_Query');
// $items_aggregations = \Tainacan\Elastic_Press::get_instance()->last_aggregations; //if elasticPress active
// //error_log(\json_encode($items_aggregations));
// if( $metadatum_type === 'Tainacan\Metadata_Types\Relationship' ) {
// //eita...
// } elseif ( $metadatum_type === 'Tainacan\Metadata_Types\Taxonomy' ) {
// if ( isset( $items_aggregations["terms.$taxonomy_slug.term_id"] ) ) {
// $buckets = $items_aggregations["terms.$taxonomy_slug.term_id"][$taxonomy_slug]['buckets'];
// foreach ($buckets as $bucket) {
// $values[] = [
// 'value' => $r->term_taxonomy_id,
// 'label' => $label,
// //'total_children' => $total_children,
// 'taxonomy' => $taxonomy_slug,
// 'taxonomy_id' => $taxonomy_id,
// //'parent' => $r->parent,
// 'total_items' => ['doc_count'],
// 'type' => 'Taxonomy'
// ];
// }
// return [
// 'total' => $total,
// 'pages' => $pages,
// 'values' => $values
// ];
// }
// } else {
// if ( isset( $items_aggregations["meta.$metadatum_id.raw"] ) ) {
// $values = $items_aggregations["meta.$metadatum_id.raw"][$metadatum_id]["buckets"];
// return [
// 'total' => $total,
// 'pages' => $pages,
// 'values' => $values
// ];
// }
// }
// //return $items_aggregations;
// }
//////////////////////////////////////////////////////
$pagination = '';
if ( $args['offset'] >= 0 && $args['number'] >= 1 ) {
$pagination = $wpdb->prepare( "LIMIT %d,%d", (int) $args['offset'], (int) $args['number'] );