mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 14:33:14 +00:00
Merge pull request #1482 from mdarse/highlight-optimization
Optimize highlight speed
This commit is contained in:
@@ -272,15 +272,7 @@ class ElasticSearchEngine implements SearchEngineInterface
|
|||||||
|
|
||||||
$params['body']['from'] = $offset;
|
$params['body']['from'] = $offset;
|
||||||
$params['body']['size'] = $perPage;
|
$params['body']['size'] = $perPage;
|
||||||
$params['body']['highlight'] = [
|
$params['body']['highlight'] = $this->buildHighlightRules($context);
|
||||||
'pre_tags' => ['[[em]]'],
|
|
||||||
'post_tags' => ['[[/em]]'],
|
|
||||||
'order' => 'score',
|
|
||||||
'fields' => [
|
|
||||||
'caption.*' => new \stdClass(),
|
|
||||||
'private_caption.*' => new \stdClass()
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
if ($aggs = $this->getAggregationQueryParams($options)) {
|
if ($aggs = $this->getAggregationQueryParams($options)) {
|
||||||
$params['body']['aggs'] = $aggs;
|
$params['body']['aggs'] = $aggs;
|
||||||
@@ -319,6 +311,39 @@ class ElasticSearchEngine implements SearchEngineInterface
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function buildHighlightRules(QueryContext $context)
|
||||||
|
{
|
||||||
|
$fields = $context->getUnrestrictedFields() + $context->getPrivateFields();
|
||||||
|
$highlighted_fields = [];
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
switch ($field->getType()) {
|
||||||
|
case Mapping::TYPE_STRING:
|
||||||
|
$highlighted_fields[$field->getIndexField()] = [
|
||||||
|
// Requires calling Mapping::highlight() on this field mapping
|
||||||
|
'type' => 'fvh'
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case Mapping::TYPE_FLOAT:
|
||||||
|
case Mapping::TYPE_DOUBLE:
|
||||||
|
case Mapping::TYPE_INTEGER:
|
||||||
|
case Mapping::TYPE_LONG:
|
||||||
|
case Mapping::TYPE_SHORT:
|
||||||
|
case Mapping::TYPE_BYTE:
|
||||||
|
continue;
|
||||||
|
case Mapping::TYPE_DATE:
|
||||||
|
default:
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'pre_tags' => ['[[em]]'],
|
||||||
|
'post_tags' => ['[[/em]]'],
|
||||||
|
'order' => 'score',
|
||||||
|
'fields' => $highlighted_fields
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo Move in search engine service provider
|
* @todo Move in search engine service provider
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user