mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-13 13:03:20 +00:00
Add highlights query
This commit is contained in:

committed by
Benoît Burnichon

parent
1ef4c1300d
commit
2d5a36f5a2
@@ -44,6 +44,8 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface
|
|||||||
private $subdefs;
|
private $subdefs;
|
||||||
/** @var ArrayCollection */
|
/** @var ArrayCollection */
|
||||||
private $flags;
|
private $flags;
|
||||||
|
/** @var ArrayCollection */
|
||||||
|
private $highlight;
|
||||||
|
|
||||||
/** {@inheritdoc} */
|
/** {@inheritdoc} */
|
||||||
public function getId()
|
public function getId()
|
||||||
@@ -319,4 +321,20 @@ class ElasticsearchRecord implements RecordInterface, MutableRecordInterface
|
|||||||
{
|
{
|
||||||
$this->position = $position;
|
$this->position = $position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ArrayCollection
|
||||||
|
*/
|
||||||
|
public function getHighlight()
|
||||||
|
{
|
||||||
|
return $this->highlight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ArrayCollection $highlight
|
||||||
|
*/
|
||||||
|
public function setHighlight(ArrayCollection $highlight)
|
||||||
|
{
|
||||||
|
$this->highlight = $highlight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -60,4 +60,7 @@ interface RecordInterface
|
|||||||
|
|
||||||
/** @return ArrayCollection */
|
/** @return ArrayCollection */
|
||||||
public function getExif();
|
public function getExif();
|
||||||
|
|
||||||
|
/** @return ArrayCollection */
|
||||||
|
public function getCaption();
|
||||||
}
|
}
|
||||||
|
@@ -268,6 +268,12 @@ class ElasticSearchEngine implements SearchEngineInterface
|
|||||||
|
|
||||||
$params['body']['from'] = $offset;
|
$params['body']['from'] = $offset;
|
||||||
$params['body']['size'] = $perPage;
|
$params['body']['size'] = $perPage;
|
||||||
|
$params['body']['highlight'] = [
|
||||||
|
'pre_tags' => ['[[em]]'],
|
||||||
|
'post_tags' => ['[[/em]]'],
|
||||||
|
'order' => 'score',
|
||||||
|
'fields' => ['caption.*' => new \stdClass()]
|
||||||
|
];
|
||||||
|
|
||||||
if ($aggs = $this->getAggregationQueryParams($options)) {
|
if ($aggs = $this->getAggregationQueryParams($options)) {
|
||||||
$params['body']['aggs'] = $aggs;
|
$params['body']['aggs'] = $aggs;
|
||||||
@@ -280,7 +286,7 @@ class ElasticSearchEngine implements SearchEngineInterface
|
|||||||
|
|
||||||
$n = 0;
|
$n = 0;
|
||||||
foreach ($res['hits']['hits'] as $hit) {
|
foreach ($res['hits']['hits'] as $hit) {
|
||||||
$results[] = ElasticsearchRecordHydrator::hydrate($hit['_source'], $n++);
|
$results[] = ElasticsearchRecordHydrator::hydrate($hit, $n++);
|
||||||
}
|
}
|
||||||
|
|
||||||
$facets = $this->facetsResponseFactory->__invoke($res);
|
$facets = $this->facetsResponseFactory->__invoke($res);
|
||||||
|
@@ -17,8 +17,11 @@ use igorw;
|
|||||||
|
|
||||||
class ElasticsearchRecordHydrator
|
class ElasticsearchRecordHydrator
|
||||||
{
|
{
|
||||||
public static function hydrate(array $data, $position)
|
public static function hydrate(array $hit, $position)
|
||||||
{
|
{
|
||||||
|
$data = $hit['_source'];
|
||||||
|
$highlight = isset($hit['highlight']) ? $hit['highlight'] : [];
|
||||||
|
|
||||||
$record = new ElasticsearchRecord();
|
$record = new ElasticsearchRecord();
|
||||||
|
|
||||||
$record->setPosition($position);
|
$record->setPosition($position);
|
||||||
@@ -43,6 +46,7 @@ class ElasticsearchRecordHydrator
|
|||||||
$record->setExif(new ArrayCollection((array) igorw\get_in($data, ['exif'], [])));
|
$record->setExif(new ArrayCollection((array) igorw\get_in($data, ['exif'], [])));
|
||||||
$record->setSubdefs(new ArrayCollection((array) igorw\get_in($data, ['subdefs'], [])));
|
$record->setSubdefs(new ArrayCollection((array) igorw\get_in($data, ['subdefs'], [])));
|
||||||
$record->setFlags(new ArrayCollection((array) igorw\get_in($data, ['flags'], [])));
|
$record->setFlags(new ArrayCollection((array) igorw\get_in($data, ['flags'], [])));
|
||||||
|
$record->setHighlight(new ArrayCollection($highlight));
|
||||||
|
|
||||||
return $record;
|
return $record;
|
||||||
}
|
}
|
||||||
|
@@ -232,6 +232,7 @@ class RecordIndexer
|
|||||||
} else {
|
} else {
|
||||||
$m->addRawVersion();
|
$m->addRawVersion();
|
||||||
$m->addAnalyzedVersion($this->locales);
|
$m->addAnalyzedVersion($this->locales);
|
||||||
|
$m->highlight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -210,6 +210,15 @@ class Mapping
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function highlight()
|
||||||
|
{
|
||||||
|
$field = &$this->currentField();
|
||||||
|
|
||||||
|
$field['term_vector'] = 'with_positions_offsets';
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function has($name)
|
public function has($name)
|
||||||
{
|
{
|
||||||
return isset($this->fields[$name]);
|
return isset($this->fields[$name]);
|
||||||
|
@@ -40,9 +40,34 @@ class PhraseanetExtension extends \Twig_Extension
|
|||||||
)),
|
)),
|
||||||
new \Twig_SimpleFunction('record_flags', array($this, 'getRecordFlags')),
|
new \Twig_SimpleFunction('record_flags', array($this, 'getRecordFlags')),
|
||||||
new \Twig_SimpleFunction('border_checker_from_fqcn', array($this, 'getCheckerFromFQCN')),
|
new \Twig_SimpleFunction('border_checker_from_fqcn', array($this, 'getCheckerFromFQCN')),
|
||||||
|
new \Twig_SimpleFunction('caption_field', array($this, 'getCaptionField')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCaptionField(RecordInterface $record, $field, $value)
|
||||||
|
{
|
||||||
|
if ($record instanceof ElasticsearchRecord) {
|
||||||
|
$highlightKey = sprintf('caption.%s', $field);
|
||||||
|
|
||||||
|
if (false === $record->getHighlight()->containsKey($highlightKey)) {
|
||||||
|
return implode('; ', (array) $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
$highlightValue = $record->getHighlight()->get($highlightKey);
|
||||||
|
|
||||||
|
// if field is multivalued, merge highlighted values with captions ones
|
||||||
|
if (is_array($value)) {
|
||||||
|
$highlightValue = array_merge($highlightValue, array_diff($value, array_map(function($value) {
|
||||||
|
return str_replace(array('[[em]]', '[[/em]]'), array('', ''), $value);
|
||||||
|
}, $highlightValue)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode('; ', (array) $highlightValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode('; ', (array) $value);
|
||||||
|
}
|
||||||
|
|
||||||
public function getRecordFlags(RecordInterface $record)
|
public function getRecordFlags(RecordInterface $record)
|
||||||
{
|
{
|
||||||
$recordStatuses = [];
|
$recordStatuses = [];
|
||||||
|
@@ -763,6 +763,21 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
return new caption_record($this->app, $this, $this->get_databox());
|
return new caption_record($this->app, $this, $this->get_databox());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCaption()
|
||||||
|
{
|
||||||
|
$collection = new ArrayCollection();
|
||||||
|
|
||||||
|
foreach ($this->get_caption()->get_fields() as $field) {
|
||||||
|
$values = array_map(function($fieldValue) {
|
||||||
|
return $fieldValue->getValue();
|
||||||
|
}, $field->get_values());
|
||||||
|
|
||||||
|
$collection->set($field->get_name(), $values);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $collection;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
|
@@ -1,20 +1,21 @@
|
|||||||
{% import 'common/macros.html.twig' as macro %}
|
{% import 'common/macros.html.twig' as macro %}
|
||||||
|
|
||||||
{% set business = false %}
|
{% set business = granted_on_collection(record.baseId, 'canmodifrecord') %}
|
||||||
{% if app['authentication'].getUser() is not none %}
|
{% set display_exif = true %}
|
||||||
{% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(record.get_base_id(), 'canmodifrecord') %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if view == 'answer' %}
|
{% if view == 'answer' %}
|
||||||
{{ macro.format_caption(record, highlight|default(''), searchEngine|default(null), business, false, true) }}
|
{{ macro.caption(record, business, display_exif) }}
|
||||||
{% elseif view == 'lazaret' %}
|
{% elseif view == 'lazaret' %}
|
||||||
{{ macro.format_caption(record, highlight|default(''), searchEngine|default(null), business, true, true) }}
|
{{ macro.caption(record, business, display_exif) }}
|
||||||
{% elseif view == 'preview' %}
|
{% elseif view == 'preview' %}
|
||||||
{{ macro.format_caption(record, highlight|default(''), searchEngine|default(null), business, true, false) }}
|
{% set display_exif = false %}
|
||||||
|
{{ macro.caption(record, business, display_exif) }}
|
||||||
{% elseif view == 'basket' %}
|
{% elseif view == 'basket' %}
|
||||||
{{ macro.format_caption(record, highlight|default(''), searchEngine|default(null), business, true, false) }}
|
{% set display_exif = false %}
|
||||||
|
{{ macro.caption(record, business, display_exif) }}
|
||||||
{% elseif view == 'overview' %}
|
{% elseif view == 'overview' %}
|
||||||
{{ macro.format_caption(record, highlight|default(''), searchEngine|default(null), business, false, false) }}
|
{% set display_exif = false %}
|
||||||
|
{{ macro.caption(record, business, display_exif) }}
|
||||||
{% elseif view == 'publi' %}
|
{% elseif view == 'publi' %}
|
||||||
{{ macro.format_caption(record, '', null, business, true, true) }}
|
{{ macro.caption(record, business, display_exif) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@@ -116,19 +116,15 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro caption(record, business, technical) %}
|
{% macro caption(record, can_see_business, display_exif) %}
|
||||||
{# @todo handle business fields #}
|
{# @todo handle business fields #}
|
||||||
{% for name, value in record.caption %}
|
{% for name, value in record.caption %}
|
||||||
<div class="desc {{ loop.index is odd ? 'impair' : 'pair' }}">
|
<div class="desc">
|
||||||
<b>{{ name }}</b> :
|
<b>{{ name }}</b> :
|
||||||
{% if value is iterable %}
|
{{ caption_field(record, name, value)|e|highlight }}
|
||||||
{{ value | join(' ; ') }}
|
|
||||||
{% else %}
|
|
||||||
{{ value }}
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if technical|default(true) and app['authentication'].user is not none and user_setting('technical_display') == 'group' %}
|
{% if display_exif|default(true) and app['authentication'].user is not none and user_setting('technical_display') == 'group' %}
|
||||||
<hr/>
|
<hr/>
|
||||||
{% include 'common/technical_datas.html.twig' %}
|
{% include 'common/technical_datas.html.twig' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@@ -83,7 +83,7 @@
|
|||||||
<div class="lightbox_container">
|
<div class="lightbox_container">
|
||||||
{% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(first_item.getRecord(app).get_base_id(), 'canmodifrecord') %}
|
{% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(first_item.getRecord(app).get_base_id(), 'canmodifrecord') %}
|
||||||
{% if first_item %}
|
{% if first_item %}
|
||||||
{{macro.format_caption(first_item.getRecord(app), '', null, business, false, false)}}
|
{{macro.caption(first_item.getRecord(app), business, false)}}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -94,7 +94,7 @@
|
|||||||
<div class="lightbox_container">
|
<div class="lightbox_container">
|
||||||
{% if basket_element %}
|
{% if basket_element %}
|
||||||
{% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(basket_element.getRecord(app).get_base_id(), 'canmodifrecord') %}
|
{% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(basket_element.getRecord(app).get_base_id(), 'canmodifrecord') %}
|
||||||
{{macro.format_caption(basket_element.getRecord(app), '', null, business, false, false)}}
|
{{macro.caption(basket_element.getRecord(app), business, false)}}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -81,7 +81,7 @@
|
|||||||
<div class="lightbox_container PNB">
|
<div class="lightbox_container PNB">
|
||||||
{% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(first_item.getRecord(app).get_base_id(), 'canmodifrecord') %}
|
{% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(first_item.getRecord(app).get_base_id(), 'canmodifrecord') %}
|
||||||
{% if first_item %}
|
{% if first_item %}
|
||||||
{{macro.format_caption(first_item.getRecord(app), '', null, business, false, false)}}
|
{{macro.caption(first_item.getRecord(app), business, false)}}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -95,7 +95,7 @@
|
|||||||
<div class="lightbox_container PNB">
|
<div class="lightbox_container PNB">
|
||||||
{% if basket_element %}
|
{% if basket_element %}
|
||||||
{% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(basket_element.getRecord(app).get_base_id(), 'canmodifrecord') %}
|
{% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(basket_element.getRecord(app).get_base_id(), 'canmodifrecord') %}
|
||||||
{{macro.format_caption(basket_element.getRecord(app), '', null, business, false, false)}}
|
{{macro.caption(basket_element.getRecord(app), business, false)}}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
{% import 'common/macros.html.twig' as macro %}
|
{% import 'common/macros.html.twig' as macro %}
|
||||||
|
|
||||||
{% if app['acl'].get(app['authentication'].getUser()).has_right_on_base(record.get_base_id, 'canmodifrecord') %}
|
{% set can_edit = granted_on_collection(record.baseId, 'canmodifrecord') %}
|
||||||
|
{% set can_see_business = can_edit %}
|
||||||
|
|
||||||
|
{% if can_edit %}
|
||||||
<div class="edit_button" style="text-align:right">
|
<div class="edit_button" style="text-align:right">
|
||||||
<a href="#" onclick="editThis('IMGT','{{record.get_serialize_key()}}');">
|
<a href="#" onclick="editThis('IMGT','{{ record.get_serialize_key }}');">
|
||||||
<img style="vertical-align:middle" src="/skins/prod/000000/images/ppen_history.png" width="16"/>
|
<img style="vertical-align:middle" src="/skins/prod/000000/images/ppen_history.png" width="16"/>
|
||||||
{{ 'action : editer' | trans }}
|
{{ 'action : editer' | trans }}
|
||||||
</a>
|
</a>
|
||||||
@@ -13,9 +16,9 @@
|
|||||||
<img src="{{ flag.path }}" title="{{ attribute(flag.labels, app.locale) }}" />
|
<img src="{{ flag.path }}" title="{{ attribute(flag.labels, app.locale) }}" />
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% set business = app['acl'].get(app['authentication'].getUser()).has_right_on_base(record.get_base_id(), 'canmodifrecord') %}
|
|
||||||
{% if record.is_from_reg() %}
|
{% if record.is_from_reg() %}
|
||||||
{{macro.format_caption(record, '', null, null, business, false, true)}}
|
{{macro.caption(record, can_see_business)}}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{macro.format_caption(record, null, null, business, false, true)}}
|
{{macro.caption(record, can_see_business)}}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@@ -13,8 +13,8 @@
|
|||||||
<td valign="middle">
|
<td valign="middle">
|
||||||
<div class='desc' style='max-height:{{ settings.images_size + 70 }}px;overflow-y:auto;'>
|
<div class='desc' style='max-height:{{ settings.images_size + 70 }}px;overflow-y:auto;'>
|
||||||
<div class="fixeddesc">
|
<div class="fixeddesc">
|
||||||
{% set business = granted_on_collection(record.baseId, 'canmodifrecord') %}
|
{% set can_see_business = granted_on_collection(record.baseId, 'canmodifrecord') %}
|
||||||
{{ macro.caption(record, business) }}
|
{{ macro.caption(record, can_see_business) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
{% import 'prod/results/macro.html.twig' as result_macro %}
|
{% import 'prod/results/macro.html.twig' as result_macro %}
|
||||||
|
{% import 'common/macros.html.twig' as macro %}
|
||||||
|
|
||||||
<div style="width:{{ settings.images_size + 30}}px;"
|
<div style="width:{{ settings.images_size + 30}}px;"
|
||||||
sbas="{{ record.databoxId }}"
|
sbas="{{ record.databoxId }}"
|
||||||
@@ -7,9 +8,8 @@
|
|||||||
onDblClick="openPreview('{{ record.story ? 'REG' : 'RESULT' }}', '{{ record.position|default(0) }}', '{{ record.id }}');">
|
onDblClick="openPreview('{{ record.story ? 'REG' : 'RESULT' }}', '{{ record.position|default(0) }}', '{{ record.id }}');">
|
||||||
<div style="padding: 4px;">
|
<div style="padding: 4px;">
|
||||||
<div style="height:40px; position: relative; z-index: 95;margin-bottom:0;border-bottom:none;">
|
<div style="height:40px; position: relative; z-index: 95;margin-bottom:0;border-bottom:none;">
|
||||||
{# @todo title should be localized #}
|
<div class="title" style="max-height:100%" title="{{ record.title(app.locale) }}">
|
||||||
<div class="title" style="max-height:100%" title="{{ record.title }}">
|
{{ record.title(app.locale)|highlight }}
|
||||||
{{ record.title }}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="status">
|
<div class="status">
|
||||||
{% for flag in record_flags(record) %}
|
{% for flag in record_flags(record) %}
|
||||||
@@ -18,13 +18,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if settings.rollover_thumbnail == 'caption' %}
|
{% set can_see_business = granted_on_collection(record.baseId, 'canmodifrecord') %}
|
||||||
{% set tooltip = path('prod_tooltip_caption', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId, 'context' : 'answer', 'number' : record.position|default(0) }) %}
|
|
||||||
{% elseif settings.rollover_thumbnail == 'preview' %}
|
|
||||||
{% set tooltip = path('prod_tooltip_preview', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId }) %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<div class="thumb captionTips" tooltipsrc="{{ tooltip }}" style="height:{{ settings.images_size }}px; z-index:90;">
|
<div class="thumb captionTips"
|
||||||
|
{% if settings.rollover_thumbnail == 'caption' %}title="{{ macro.caption(record, can_see_business, false) | e }}"{% endif %}
|
||||||
|
{% if settings.rollover_thumbnail == 'preview' %}tooltipsrc="{{ path('prod_tooltip_preview', { 'sbas_id' : record.databoxId, 'record_id' : record.recordId }) }}"{% endif %}
|
||||||
|
style="height:{{ settings.images_size }}px; z-index:90;">
|
||||||
<div class="doc_infos">
|
<div class="doc_infos">
|
||||||
{% if settings.doctype_display == '1' %}
|
{% if settings.doctype_display == '1' %}
|
||||||
{{ record_doctype_icon(record) }}
|
{{ record_doctype_icon(record) }}
|
||||||
|
@@ -3005,7 +3005,6 @@ function set_up_feed_box(data) {
|
|||||||
var $form = $('form.main_form', dialog.getDomElement());
|
var $form = $('form.main_form', dialog.getDomElement());
|
||||||
|
|
||||||
$feeds_item.bind('click',function () {
|
$feeds_item.bind('click',function () {
|
||||||
console.log("clcik");
|
|
||||||
$feeds_item.removeClass('selected');
|
$feeds_item.removeClass('selected');
|
||||||
$(this).addClass('selected');
|
$(this).addClass('selected');
|
||||||
$('input[name="feed_id"]', $form).val($('input', this).val());
|
$('input[name="feed_id"]', $form).val($('input', this).val());
|
||||||
|
Reference in New Issue
Block a user