mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
port to 4.1 search mix type
This commit is contained in:
@@ -619,6 +619,8 @@ class ElasticSearchEngine implements SearchEngineInterface
|
||||
foreach ($context->getHighlightedFields() as $field) {
|
||||
switch ($field->getType()) {
|
||||
case FieldMapping::TYPE_STRING:
|
||||
case FieldMapping::TYPE_DOUBLE:
|
||||
case FieldMapping::TYPE_DATE:
|
||||
$index_field = $field->getIndexField();
|
||||
$raw_index_field = $field->getIndexField(true);
|
||||
$highlighted_fields[$index_field . ".light"] = [
|
||||
@@ -628,13 +630,10 @@ class ElasticSearchEngine implements SearchEngineInterface
|
||||
];
|
||||
break;
|
||||
case FieldMapping::TYPE_FLOAT:
|
||||
case FieldMapping::TYPE_DOUBLE:
|
||||
case FieldMapping::TYPE_INTEGER:
|
||||
case FieldMapping::TYPE_LONG:
|
||||
case FieldMapping::TYPE_SHORT:
|
||||
case FieldMapping::TYPE_BYTE:
|
||||
continue;
|
||||
case FieldMapping::TYPE_DATE:
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of phrasea-4.0.
|
||||
*
|
||||
* (c) Alchemy <info@alchemy.fr>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
|
||||
|
||||
class DoubleFieldMapping extends ComplexFieldMapping
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $enableAnalysis = true;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $analyzer = null;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $termVector = null;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($name)
|
||||
{
|
||||
parent::__construct($name, self::TYPE_DOUBLE);
|
||||
}
|
||||
|
||||
|
||||
public function disableAnalysis()
|
||||
{
|
||||
$this->enableAnalysis = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function enableAnalysis()
|
||||
{
|
||||
$this->enableAnalysis = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getProperties()
|
||||
{
|
||||
$properties = [];
|
||||
|
||||
if ($this->analyzer) {
|
||||
$properties['analyzer'] = $this->analyzer;
|
||||
}
|
||||
|
||||
if (! $this->enableAnalysis) {
|
||||
$properties['index'] = 'not_analyzed';
|
||||
}
|
||||
|
||||
if ($this->termVector) {
|
||||
$properties['term_vector'] = $this->termVector;
|
||||
}
|
||||
|
||||
return array_replace(parent::getProperties(), $properties);
|
||||
}
|
||||
}
|
@@ -19,28 +19,55 @@ class FieldToFieldMappingConverter
|
||||
|
||||
public function convertField(Field $field, array $locales)
|
||||
{
|
||||
if ($field->getType() === FieldMapping::TYPE_DATE) {
|
||||
return new DateFieldMapping($field->getName(), FieldMapping::DATE_FORMAT_CAPTION);
|
||||
$ret = null;
|
||||
switch($field->getType()) {
|
||||
case FieldMapping::TYPE_DATE:
|
||||
$ret = new DateFieldMapping($field->getName(), FieldMapping::DATE_FORMAT_MYSQL_OR_CAPTION);
|
||||
if (! $field->isFacet() && ! $field->isSearchable()) {
|
||||
$ret->disableIndexing();
|
||||
}
|
||||
else {
|
||||
$ret->addChild(
|
||||
(new StringFieldMapping('light'))
|
||||
->setAnalyzer('general_light')
|
||||
->enableTermVectors()
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case FieldMapping::TYPE_STRING:
|
||||
$ret = new StringFieldMapping($field->getName());
|
||||
if (! $field->isFacet() && ! $field->isSearchable()) {
|
||||
$ret->disableIndexing();
|
||||
}
|
||||
else {
|
||||
$ret->addChild(
|
||||
(new StringFieldMapping('raw'))
|
||||
->enableRawIndexing());
|
||||
$ret->addAnalyzedChildren($locales);
|
||||
$ret->enableTermVectors(true);
|
||||
}
|
||||
break;
|
||||
|
||||
case FieldMapping::TYPE_DOUBLE:
|
||||
$ret = new DoubleFieldMapping($field->getName());
|
||||
if (! $field->isFacet() && ! $field->isSearchable()) {
|
||||
$ret->disableIndexing();
|
||||
}
|
||||
else {
|
||||
$ret->addChild(
|
||||
(new StringFieldMapping('light'))
|
||||
->setAnalyzer('general_light')
|
||||
->enableTermVectors()
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$ret = new FieldMapping($field->getName(), $field->getType());
|
||||
break;
|
||||
}
|
||||
|
||||
if ($field->getType() === FieldMapping::TYPE_STRING) {
|
||||
$fieldMapping = new StringFieldMapping($field->getName());
|
||||
|
||||
if (! $field->isFacet() && ! $field->isSearchable()) {
|
||||
$fieldMapping->disableIndexing();
|
||||
} else {
|
||||
$fieldMapping->addChild((new StringFieldMapping('raw'))->enableRawIndexing());
|
||||
|
||||
$child = new CompletionFieldMapping('suggest');
|
||||
$fieldMapping->addChild($child);
|
||||
|
||||
$fieldMapping->addAnalyzedChildren($locales);
|
||||
$fieldMapping->enableTermVectors(true);
|
||||
}
|
||||
|
||||
return $fieldMapping;
|
||||
}
|
||||
|
||||
return new FieldMapping($field->getName(), $field->getType());
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
@@ -107,13 +107,28 @@ class QueryContext
|
||||
*/
|
||||
public function localizeField(Field $field)
|
||||
{
|
||||
$ret = null;
|
||||
$index_field = $field->getIndexField();
|
||||
|
||||
if ($field->getType() === FieldMapping::TYPE_STRING) {
|
||||
return $this->localizeFieldName($index_field);
|
||||
} else {
|
||||
return [$index_field];
|
||||
switch($field->getType()) {
|
||||
case FieldMapping::TYPE_STRING:
|
||||
$ret = $this->localizeFieldName($index_field);
|
||||
break;
|
||||
|
||||
case FieldMapping::TYPE_DATE:
|
||||
case FieldMapping::TYPE_DOUBLE:
|
||||
$ret = [
|
||||
$index_field . '.light',
|
||||
$index_field
|
||||
];
|
||||
break;
|
||||
|
||||
default:
|
||||
$ret = [$index_field];
|
||||
break;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function localizeFieldName($field)
|
||||
|
@@ -30,14 +30,14 @@ class ValueChecker
|
||||
case FieldMapping::TYPE_LONG:
|
||||
case FieldMapping::TYPE_SHORT:
|
||||
case FieldMapping::TYPE_BYTE:
|
||||
if ($is_numeric) {
|
||||
// if ($is_numeric) {
|
||||
$filtered[] = $item;
|
||||
}
|
||||
// }
|
||||
break;
|
||||
case FieldMapping::TYPE_DATE:
|
||||
if ($is_valid_date) {
|
||||
// if ($is_valid_date) {
|
||||
$filtered[] = $item;
|
||||
}
|
||||
// }
|
||||
break;
|
||||
case FieldMapping::TYPE_STRING:
|
||||
default:
|
||||
|
@@ -26,28 +26,28 @@ class ValueCheckerTest extends \PHPUnit_Framework_TestCase
|
||||
$values = [
|
||||
[FieldMapping::TYPE_FLOAT , 42 , true ],
|
||||
[FieldMapping::TYPE_FLOAT , '42' , true ],
|
||||
[FieldMapping::TYPE_FLOAT , '42foo' , false],
|
||||
[FieldMapping::TYPE_FLOAT , 'foo' , false],
|
||||
[FieldMapping::TYPE_FLOAT , '42foo' , true],
|
||||
[FieldMapping::TYPE_FLOAT , 'foo' , true],
|
||||
[FieldMapping::TYPE_DOUBLE , 42 , true ],
|
||||
[FieldMapping::TYPE_DOUBLE , '42' , true ],
|
||||
[FieldMapping::TYPE_DOUBLE , '42foo' , false],
|
||||
[FieldMapping::TYPE_DOUBLE , 'foo' , false],
|
||||
[FieldMapping::TYPE_DOUBLE , '42foo' , true],
|
||||
[FieldMapping::TYPE_DOUBLE , 'foo' , true],
|
||||
[FieldMapping::TYPE_INTEGER, 42 , true ],
|
||||
[FieldMapping::TYPE_INTEGER, '42' , true ],
|
||||
[FieldMapping::TYPE_INTEGER, '42foo' , false],
|
||||
[FieldMapping::TYPE_INTEGER, 'foo' , false],
|
||||
[FieldMapping::TYPE_INTEGER, '42foo' , true],
|
||||
[FieldMapping::TYPE_INTEGER, 'foo' , true],
|
||||
[FieldMapping::TYPE_LONG , 42 , true ],
|
||||
[FieldMapping::TYPE_LONG , '42' , true ],
|
||||
[FieldMapping::TYPE_LONG , '42foo' , false],
|
||||
[FieldMapping::TYPE_LONG , 'foo' , false],
|
||||
[FieldMapping::TYPE_LONG , '42foo' , true],
|
||||
[FieldMapping::TYPE_LONG , 'foo' , true],
|
||||
[FieldMapping::TYPE_SHORT , 42 , true ],
|
||||
[FieldMapping::TYPE_SHORT , '42' , true ],
|
||||
[FieldMapping::TYPE_SHORT , '42foo' , false],
|
||||
[FieldMapping::TYPE_SHORT , 'foo' , false],
|
||||
[FieldMapping::TYPE_SHORT , '42foo' , true],
|
||||
[FieldMapping::TYPE_SHORT , 'foo' , true],
|
||||
[FieldMapping::TYPE_BYTE , 42 , true ],
|
||||
[FieldMapping::TYPE_BYTE , '42' , true ],
|
||||
[FieldMapping::TYPE_BYTE , '42foo' , false],
|
||||
[FieldMapping::TYPE_BYTE , 'foo' , false],
|
||||
[FieldMapping::TYPE_BYTE , '42foo' , true],
|
||||
[FieldMapping::TYPE_BYTE , 'foo' , true],
|
||||
|
||||
[FieldMapping::TYPE_STRING , 'foo' , true ],
|
||||
[FieldMapping::TYPE_STRING , '42' , true ],
|
||||
@@ -61,8 +61,8 @@ class ValueCheckerTest extends \PHPUnit_Framework_TestCase
|
||||
[FieldMapping::TYPE_BOOLEAN, 42 , true ],
|
||||
|
||||
[FieldMapping::TYPE_DATE , '2015/01/01' , true ],
|
||||
[FieldMapping::TYPE_DATE , '2015/01/01 00:00:00', false],
|
||||
[FieldMapping::TYPE_DATE , 'foo' , false],
|
||||
[FieldMapping::TYPE_DATE , '2015/01/01 00:00:00', true],
|
||||
[FieldMapping::TYPE_DATE , 'foo' , true],
|
||||
];
|
||||
|
||||
foreach ($values as &$value) {
|
||||
|
Reference in New Issue
Block a user