Merge branch 'hotfix/0.16.2'

This commit is contained in:
vnmedeiros 2020-06-12 18:06:55 -03:00
commit e20c89fa81
7 changed files with 69 additions and 28 deletions

View File

@ -50,6 +50,13 @@ class Elastic_Press {
add_filter( 'ep_formatted_args', function ( $formatted_args ) { add_filter( 'ep_formatted_args', function ( $formatted_args ) {
$formatted_args['track_total_hits'] = true; $formatted_args['track_total_hits'] = true;
//https://www.elasticpress.io/blog/2019/02/custom-search-with-elasticpress-how-to-limit-results-to-full-text-matches/
if ( ! empty( $formatted_args['query']['bool']['should'] ) ) {
$formatted_args['query']['bool']['must'] = $formatted_args['query']['bool']['should'];
$formatted_args['query']['bool']['must'][0]['multi_match']['operator'] = 'AND';
unset( $formatted_args['query']['bool']['should'] );
unset( $formatted_args["query"]["bool"]["must"][0]["multi_match"]["type"] );
}
return $formatted_args; return $formatted_args;
} ); } );
@ -61,10 +68,10 @@ class Elastic_Press {
function elasticpress_config_mapping( $mapping ) { function elasticpress_config_mapping( $mapping ) {
$name_field = 'relationship_label'; $name_field = 'relationship_label';
$array_dynamic_templates = $mapping["mappings"]["post"]["dynamic_templates"]; $array_dynamic_templates = $mapping["mappings"]["dynamic_templates"];
foreach ($array_dynamic_templates as $key => $dynamic_templates) { foreach ($array_dynamic_templates as $key => $dynamic_templates) {
if ( isset($dynamic_templates['template_meta_types'] )) { if ( isset($dynamic_templates['template_meta_types'] )) {
$mapping["mappings"]["post"]["dynamic_templates"][$key]['template_meta_types']["mapping"]["properties"][$name_field] = ['type' => 'keyword', 'normalizer' => 'lowerasciinormalizer']; $mapping["mappings"]["dynamic_templates"][$key]['template_meta_types']["mapping"]["properties"][$name_field] = ['type' => 'keyword', 'normalizer' => 'lowerasciinormalizer'];
// $mapping["mappings"]["post"]["dynamic_templates"][$key]['template_meta_types']["mapping"]["properties"][$name_field] = // $mapping["mappings"]["post"]["dynamic_templates"][$key]['template_meta_types']["mapping"]["properties"][$name_field] =
// ['type' => 'nested', // ['type' => 'nested',
// 'properties' => [ // 'properties' => [
@ -72,7 +79,10 @@ class Elastic_Press {
// //,'description' => ['type'=>'text'] // //,'description' => ['type'=>'text']
// ] // ]
// ]; // ];
} elseif( isset($dynamic_templates['template_terms'] ) ) {
$mapping["mappings"]["dynamic_templates"][$key]['template_terms']['mapping']['properties']['term_name.id'] = ['type' => 'keyword', 'normalizer' => 'lowerasciinormalizer'];
} }
} }
return $mapping; return $mapping;
} }
@ -106,6 +116,14 @@ class Elastic_Press {
} }
} }
} }
if( isset($post_args['terms']) && !empty($post_args['terms']) ) {
foreach($post_args['terms'] as $key => $terms_doc) {
for($i = 0; $i < sizeof($terms_doc); $i++) {
$post_args['terms'][$key][$i]['term_name.id'] = $terms_doc[$i]['name'] . '.' . $terms_doc[$i]['term_id'] . '.parent=' . $terms_doc[$i]['parent'] ;
}
}
}
} }
return $post_args; return $post_args;
} }
@ -255,7 +273,7 @@ class Elastic_Press {
} }
} }
add_filter('ep_formatted_args', array($this, "prepare_request")); //filtro para os argumentos já no formato a ser enviado para o elasticpress. add_filter('ep_formatted_args', array($this, "prepare_request"), 10, 2); //filtro para os argumentos já no formato a ser enviado para o elasticpress.
return $args; return $args;
} }
@ -266,7 +284,18 @@ class Elastic_Press {
* *
* @return \Array with formatted array of args. * @return \Array with formatted array of args.
*/ */
public function prepare_request($formatted_args) { public function prepare_request($formatted_args, $args) {
if ( is_user_logged_in() && ! isset($args['post_status']) ) {
if ( isset( $formatted_args['post_filter']['bool']['must'] ) ) {
$post_filter = $formatted_args['post_filter']['bool']['must'];
foreach($post_filter as $idx => $filter) {
if( isset( $filter['terms']['post_status'] ) ) {
$formatted_args['post_filter']['bool']['must'][$idx]['terms']['post_status']=["private", "publish"];
break;
}
}
}
}
switch ($this->aggregation_type) { switch ($this->aggregation_type) {
case 'items': case 'items':
$formatted_args = $this->prepare_request_for_items($formatted_args); $formatted_args = $this->prepare_request_for_items($formatted_args);
@ -422,7 +451,7 @@ class Elastic_Press {
$temp[] = $item; $temp[] = $item;
} }
} }
} elseif ( isset($item['term'])) { } elseif ( isset($item['terms']) || isset($item['term']) ) {
$temp[] = $item; $temp[] = $item;
} }
} }
@ -436,12 +465,17 @@ class Elastic_Press {
"aggs" => array( "aggs" => array(
$id => array( $id => array(
"terms"=>array( "terms"=>array(
//"size" => $filter['max_options'], "order" => ["_key" => "asc" ],
"script" => [ "include" => "(.)*parent=$parent",
"lang" => "painless", "field" => "$field.term_name.id"
"source" => "for (int i = 0; i < doc['$field.parent'].length; ++i) { if (doc['$field.parent'][i] == $parent) { return doc['$field.term_id'][i]; }}", // "script" => [
//"source"=> "def c= [''];if(!params._source.terms.empty && params._source.$field != null){ for(term in params._source.$field) { if(term.parent==$parent) { c.add(term.term_id); }}} return c;" // "lang" => "painless",
] // //"source" => "List l = new ArrayList(doc['$field.term_name.id']); if (l == null) { return []; } return l"
// //"source" => "if ( doc.containsKey('$field.parent') ) { List l = params._source.$field; if (l == null) { return []; } List result = new ArrayList(); for(int i = 0; i < l.length; ++i) { if(l[i].parent == 0) { result.add( l[i]['term_name.id'] ); } } return result; } return [];"
// //"source" => "if (doc.containsKey('$field.parent')) { List l = new ArrayList(doc['$field.term_id']); for (int i = 0; i < l.length; ++i) { if (doc['$field.parent'][i] != $parent) { l.remove( i ); } } return l; } return [];"
// //"source" => "for (int i = 0; i < doc['$field.parent'].length; ++i) { if (doc['$field.parent'][i] == $parent) { return doc['$field.term_id'][i]; }}",
// //"source"=> "def c= [''];if(!params._source.terms.empty && params._source.$field != null){ for(term in params._source.$field) { if(term.parent==$parent) { c.add(term.term_id); }}} return c;"
// ]
) )
) )
) )
@ -450,18 +484,24 @@ class Elastic_Press {
if (!empty($filter['include'])) { if (!empty($filter['include'])) {
$custom_filter_include = $custom_filter; $custom_filter_include = $custom_filter;
$custom_filter_include['bool']['must'][] = ["bool" => [ "must"=> [ [ "terms" => ["$field.term_id" => $filter['include'] ] ] ] ] ]; $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'] = [ $aggs[$id.'.include'] = [
"filter" => $custom_filter_include, "filter" => $custom_filter_include,
"aggs" => array( "aggs" => array(
$id.'.include' => array( $id.'.include' => array(
"terms"=>array( "terms"=>array(
"script" => [ "order" => ["_key" => "asc" ],
"lang" => "painless", "field" => "$field.term_name.id",
"source" => "def c= ['']; for (int i = 0; i < doc['$field.term_id'].length; ++i) { if( [$terms_id_inlcude].contains(doc['$field.term_id'][i]) ) { c.add(doc['$field.term_id'][i]); } } return c;" "include" => "(.)*.($terms_id_inlcude).parent=$parent",
//"source"=> "def c= ['']; if(!params._source.terms.empty && params._source.$field != null) { for(term in params._source.$field) { if( [$terms_id_inlcude].contains(term.term_id) ) { c.add(term.term_id); }}} return c;" "min_doc_count" => 0
]
) )
// "terms"=>array(
// "script" => [
// "lang" => "painless",
// "source" => "def c= ['']; for (int i = 0; i < doc['$field.term_id'].length; ++i) { if( [$terms_id_inlcude].contains(doc['$field.term_id'][i]) ) { c.add(doc['$field.term_name.id'][i]); } } return c;"
// //"source"=> "def c= ['']; if(!params._source.terms.empty && params._source.$field != null) { for(term in params._source.$field) { if( [$terms_id_inlcude].contains(term.term_id) ) { c.add(term.term_id); }}} return c;"
// ]
// )
) )
) )
]; ];
@ -654,13 +694,14 @@ class Elastic_Press {
$taxonomy_slug = $description_types[2]; $taxonomy_slug = $description_types[2];
$taxonomy_id = Repositories\Taxonomies::get_instance()->get_id_by_db_identifier($taxonomy_slug); $taxonomy_id = Repositories\Taxonomies::get_instance()->get_id_by_db_identifier($taxonomy_slug);
foreach ($aggregation[$key]['buckets'] as $term) { foreach ($aggregation[$key]['buckets'] as $term) {
$term_id = intval($term['key']); $temp = explode('.', $term['key']);
$term_id = intval( $temp[count($temp)-2] );
$term_object = \Tainacan\Repositories\Terms::get_instance()->fetch($term_id, $taxonomy_slug); $term_object = \Tainacan\Repositories\Terms::get_instance()->fetch($term_id, $taxonomy_slug);
$count_query = $wpdb->prepare("SELECT COUNT(term_id) FROM $wpdb->term_taxonomy WHERE parent = %d", $term_id); $count_query = $wpdb->prepare("SELECT COUNT(term_id) FROM $wpdb->term_taxonomy WHERE parent = %d", $term_id);
$total_children = $wpdb->get_var($count_query); $total_children = $wpdb->get_var($count_query);
$fct = [ $fct = [
"type" => "Taxonomy", "type" => "Taxonomy",
"value" => $term['key'], "value" => $term_id,
"taxonomy" => $taxonomy_slug, "taxonomy" => $taxonomy_slug,
"taxonomy_id" => $taxonomy_id, "taxonomy_id" => $taxonomy_id,
"total_children" => $total_children, "total_children" => $total_children,

View File

@ -149,10 +149,10 @@ class Search_Engine {
$seperator = ''; $seperator = '';
$not_exact = empty($this->query_instance->query_vars['exact']); $not_exact = empty($this->query_instance->query_vars['exact']);
$terms = $this->get_search_terms(); $terms = $this->get_search_terms();
$fields = implode(", ' || ', ", $search_query_fields); $fields = implode(", ", $search_query_fields);
foreach ( $terms as $term ) { foreach ( $terms as $term ) {
$esc_term = $wpdb->prepare("%s", $not_exact ? "%".$term."%" : $term); $esc_term = $wpdb->prepare("%s", $not_exact ? "%".$term."%" : $term);
$searchQuery .= "{$seperator}CONCAT_WS( $fields ) LIKE $esc_term"; $searchQuery .= "{$seperator}CONCAT_WS(' || ', $fields ) LIKE $esc_term";
$seperator = ' OR '; $seperator = ' OR ';
} }
$searchQuery .= ')'; $searchQuery .= ')';

View File

@ -622,9 +622,6 @@ class Item extends Entity {
$fto = $item_meta->get_metadatum()->get_metadata_type_object(); $fto = $item_meta->get_metadatum()->get_metadata_type_object();
$before = str_replace('$type', $fto->get_slug(), $args['before']);
$return .= $before;
if ( $fto->get_core() ) { if ( $fto->get_core() ) {
if ( $args['exclude_core'] ) { if ( $args['exclude_core'] ) {
continue; continue;
@ -635,6 +632,9 @@ class Item extends Entity {
} }
} }
$before = str_replace('$type', $fto->get_slug(), $args['before']);
$return .= $before;
if ($item_meta->has_value() || !$args['hide_empty']) { if ($item_meta->has_value() || !$args['hide_empty']) {
$return .= $args['before_title'] . $item_meta->get_metadatum()->get_name() . $args['after_title']; $return .= $args['before_title'] . $item_meta->get_metadatum()->get_name() . $args['after_title'];
$return .= $args['before_value'] . $item_meta->get_value_as_html() . $args['after_value']; $return .= $args['before_value'] . $item_meta->get_value_as_html() . $args['after_value'];

View File

@ -895,6 +895,7 @@ abstract class Importer {
$author = $this->get_transient('author'); $author = $this->get_transient('author');
$this->add_log('---------------------------'); $this->add_log('---------------------------');
$this->add_log('Starting processing new item'); $this->add_log('Starting processing new item');
$this->add_log(date("Y-m-d H:i:s"));
$this->add_log('User in process: ' . $author); $this->add_log('User in process: ' . $author);
wp_set_current_user($author); wp_set_current_user($author);
$result = $this->$method_name(); $result = $this->$method_name();

View File

@ -4,7 +4,7 @@ Tags: museums, libraries, archives, GLAM, collections, repository
Requires at least: 4.8 Requires at least: 4.8
Tested up to: 5.4 Tested up to: 5.4
Requires PHP: 5.6 Requires PHP: 5.6
Stable tag: 0.16.1 Stable tag: 0.16.2
License: GPLv2 or later License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html License URI: http://www.gnu.org/licenses/gpl-3.0.html

View File

@ -4,13 +4,13 @@ Plugin Name: Tainacan
Plugin URI: https://tainacan.org/ Plugin URI: https://tainacan.org/
Description: Open source, powerfull and flexible repository platform for WordPress. Manage and publish you digital collections as easily as publishing a post to your blog, while having all the tools of a professional respository platform. Description: Open source, powerfull and flexible repository platform for WordPress. Manage and publish you digital collections as easily as publishing a post to your blog, while having all the tools of a professional respository platform.
Author: Tainacan.org Author: Tainacan.org
Version: 0.16.1 Version: 0.16.2
Text Domain: tainacan Text Domain: tainacan
License: GPLv2 or later License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/ */
const TAINACAN_VERSION = '0.16.1'; const TAINACAN_VERSION = '0.16.2';
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
$TAINACAN_BASE_URL = plugins_url('', __FILE__); $TAINACAN_BASE_URL = plugins_url('', __FILE__);

View File

@ -193,7 +193,6 @@
this.selected = metadata.terms; this.selected = metadata.terms;
} else { } else {
this.selected = []; this.selected = [];
return false;
} }
let onlyLabels = []; let onlyLabels = [];