Merge pull request #3559 from alchemy-fr/PHRAS-3162_es-document-is-empy-pdf_4.1

PHRAS-3162 merge  es-document-is-empy-pdf_4.1, This problem occurs when the last character is a utf-8 character
This commit is contained in:
Nicolas Maillat
2020-07-08 17:33:13 +02:00
committed by GitHub

View File

@@ -11,13 +11,10 @@
namespace Alchemy\Phrasea\SearchEngine\Elastic; namespace Alchemy\Phrasea\SearchEngine\Elastic;
use Alchemy\Phrasea\SearchEngine\Elastic\Exception\MergeException;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Flag;
use appbox; use appbox;
use DateTime; use DateTime;
use igorw; use Exception;
class RecordHelper class RecordHelper
{ {
@@ -100,31 +97,31 @@ class RecordHelper
$a = explode(';', preg_replace('/\D+/', ';', trim($value))); $a = explode(';', preg_replace('/\D+/', ';', trim($value)));
switch (count($a)) { switch (count($a)) {
case 1: // yyyy case 1: // yyyy
$date = new \DateTime($a[0] . '-01-01'); // will throw if date is not valid $date = new DateTime($a[0] . '-01-01'); // will throw if date is not valid
$v_fix = $date->format('Y'); $v_fix = $date->format('Y');
break; break;
case 2: // yyyy;mm case 2: // yyyy;mm
$date = new \DateTime( $a[0] . '-' . $a[1] . '-01'); $date = new DateTime( $a[0] . '-' . $a[1] . '-01');
$v_fix = $date->format('Y-m'); $v_fix = $date->format('Y-m');
break; break;
case 3: // yyyy;mm;dd case 3: // yyyy;mm;dd
$date = new \DateTime($a[0] . '-' . $a[1] . '-' . $a[2]); $date = new DateTime($a[0] . '-' . $a[1] . '-' . $a[2]);
$v_fix = $date->format('Y-m-d'); $v_fix = $date->format('Y-m-d');
break; break;
case 4: case 4:
$date = new \DateTime($a[0] . '-' . $a[1] . '-' . $a[2] . ' ' . $a[3] . ':00:00'); $date = new DateTime($a[0] . '-' . $a[1] . '-' . $a[2] . ' ' . $a[3] . ':00:00');
$v_fix = $date->format('Y-m-d H:i:s'); $v_fix = $date->format('Y-m-d H:i:s');
break; break;
case 5: case 5:
$date = new \DateTime($a[0] . '-' . $a[1] . '-' . $a[2] . ' ' . $a[3] . ':' . $a[4] . ':00'); $date = new DateTime($a[0] . '-' . $a[1] . '-' . $a[2] . ' ' . $a[3] . ':' . $a[4] . ':00');
$v_fix = $date->format('Y-m-d H:i:s'); $v_fix = $date->format('Y-m-d H:i:s');
break; break;
case 6: case 6:
$date = new \DateTime($a[0] . '-' . $a[1] . '-' . $a[2] . ' ' . $a[3] . ':' . $a[4] . ':' . $a[5]); $date = new DateTime($a[0] . '-' . $a[1] . '-' . $a[2] . ' ' . $a[3] . ':' . $a[4] . ':' . $a[5]);
$v_fix = $date->format('Y-m-d H:i:s'); $v_fix = $date->format('Y-m-d H:i:s');
break; break;
} }
} catch (\Exception $e) { } catch (Exception $e) {
// no-op, v_fix = null // no-op, v_fix = null
} }
@@ -151,8 +148,16 @@ class RecordHelper
return (bool) $value; return (bool) $value;
case FieldMapping::TYPE_STRING: case FieldMapping::TYPE_STRING:
$value = substr($value, 0, 32766); // for lucene limit, before a better solution $value = str_replace("\0", '', $value); // no null char for lucene !
return str_replace("\0", '', $value); if( strlen($value) > 32766) { // for lucene limit, before a better solution
for($l=32766; $l > 0; $l--) {
if(ord(substr($value, $l-1, 1)) < 128) {
break;
}
}
$value = substr($value, 0, $l);
}
return $value;
default: default:
return $value; return $value;