mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Add Facet labels
This commit is contained in:
@@ -184,7 +184,30 @@ class QueryController extends Controller
|
|||||||
$json['parsed_query'] = $result->getQuery();
|
$json['parsed_query'] = $result->getQuery();
|
||||||
/** End debug */
|
/** End debug */
|
||||||
|
|
||||||
$json['facets'] = $result->getFacets();
|
$fieldLabels = [
|
||||||
|
'Base_Name' => $this->app->trans('prod::facet:base_label'),
|
||||||
|
'Collection_Name' => $this->app->trans('prod::facet:collection_label'),
|
||||||
|
'Type_Name' => $this->app->trans('prod::facet:doctype_label'),
|
||||||
|
];
|
||||||
|
foreach ($this->app->getDataboxes() as $databox) {
|
||||||
|
foreach ($databox->get_meta_structure() as $field) {
|
||||||
|
if (!isset($fieldLabels[$field->get_name()])) {
|
||||||
|
$fieldLabels[$field->get_name()] = $field->get_label($this->app['locale']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$facets = [];
|
||||||
|
|
||||||
|
foreach ($result->getFacets() as $facet) {
|
||||||
|
$facetName = $facet['name'];
|
||||||
|
|
||||||
|
$facet['label'] = isset($fieldLabels[$facetName]) ? $fieldLabels[$facetName] : $facetName;
|
||||||
|
|
||||||
|
$facets[] = $facet;
|
||||||
|
}
|
||||||
|
|
||||||
|
$json['facets'] = $facets;
|
||||||
$json['phrasea_props'] = $proposals;
|
$json['phrasea_props'] = $proposals;
|
||||||
$json['total_answers'] = (int) $result->getAvailable();
|
$json['total_answers'] = (int) $result->getAvailable();
|
||||||
$json['next_page'] = ($page < $npages && $result->getAvailable() > 0) ? ($page + 1) : false;
|
$json['next_page'] = ($page < $npages && $result->getAvailable() > 0) ? ($page + 1) : false;
|
||||||
|
@@ -70,13 +70,13 @@ class SearchEngineServiceProvider implements ServiceProviderInterface
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
$app['search_engine.structure'] = $app->share(function ($app) {
|
$app['search_engine.structure'] = $app->share(function (\Alchemy\Phrasea\Application $app) {
|
||||||
$databoxes = $app->getDataboxes();
|
$databoxes = $app->getDataboxes();
|
||||||
return GlobalStructure::createFromDataboxes($databoxes);
|
return GlobalStructure::createFromDataboxes($databoxes);
|
||||||
});
|
});
|
||||||
|
|
||||||
$app['elasticsearch.facets_response.factory'] = $app->protect(function (array $response) use ($app) {
|
$app['elasticsearch.facets_response.factory'] = $app->protect(function (array $response) use ($app) {
|
||||||
return new FacetsResponse(new Escaper(), $response);
|
return new FacetsResponse(new Escaper(), $response, $app['search_engine.structure']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@@ -422,17 +422,17 @@ class ElasticSearchEngine implements SearchEngineInterface
|
|||||||
// We always want a collection facet right now
|
// We always want a collection facet right now
|
||||||
$collection_facet_agg = array();
|
$collection_facet_agg = array();
|
||||||
$collection_facet_agg['terms']['field'] = 'collection_name';
|
$collection_facet_agg['terms']['field'] = 'collection_name';
|
||||||
$aggs['Collection'] = $collection_facet_agg;
|
$aggs['Collection_Name'] = $collection_facet_agg;
|
||||||
|
|
||||||
// We always want a base facet right now
|
// We always want a base facet right now
|
||||||
$base_facet_agg = array();
|
$base_facet_agg = array();
|
||||||
$base_facet_agg['terms']['field'] = 'databox_name';
|
$base_facet_agg['terms']['field'] = 'databox_name';
|
||||||
$aggs['Base'] = $base_facet_agg;
|
$aggs['Base_Name'] = $base_facet_agg;
|
||||||
|
|
||||||
// We always want a type facet right now
|
// We always want a type facet right now
|
||||||
$base_facet_agg = array();
|
$base_facet_agg = array();
|
||||||
$base_facet_agg['terms']['field'] = 'type';
|
$base_facet_agg['terms']['field'] = 'type';
|
||||||
$aggs['Type'] = $base_facet_agg;
|
$aggs['Type_Name'] = $base_facet_agg;
|
||||||
|
|
||||||
$structure = $this->context_factory->getLimitedStructure($options);
|
$structure = $this->context_factory->getLimitedStructure($options);
|
||||||
foreach ($structure->getFacetFields() as $name => $field) {
|
foreach ($structure->getFacetFields() as $name => $field) {
|
||||||
|
@@ -3,11 +3,11 @@
|
|||||||
namespace Alchemy\Phrasea\SearchEngine\Elastic\Search;
|
namespace Alchemy\Phrasea\SearchEngine\Elastic\Search;
|
||||||
|
|
||||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||||
|
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Structure;
|
||||||
use Alchemy\Phrasea\SearchEngine\SearchEngineSuggestion;
|
use Alchemy\Phrasea\SearchEngine\SearchEngineSuggestion;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use JsonSerializable;
|
|
||||||
|
|
||||||
class FacetsResponse implements JsonSerializable
|
class FacetsResponse
|
||||||
{
|
{
|
||||||
private $escaper;
|
private $escaper;
|
||||||
private $facets = array();
|
private $facets = array();
|
||||||
@@ -71,14 +71,14 @@ class FacetsResponse implements JsonSerializable
|
|||||||
private function buildQuery($name, $value)
|
private function buildQuery($name, $value)
|
||||||
{
|
{
|
||||||
switch($name) {
|
switch($name) {
|
||||||
case 'Collection':
|
case 'Collection_Name':
|
||||||
return sprintf('collection:%s', $this->escaper->escapeWord($value));
|
return sprintf('collection:%s', $this->escaper->escapeWord($value));
|
||||||
case 'Base':
|
case 'Base_Name':
|
||||||
return sprintf('database:%s', $this->escaper->escapeWord($value));
|
return sprintf('database:%s', $this->escaper->escapeWord($value));
|
||||||
case 'Type':
|
case 'Type_Name':
|
||||||
return sprintf('type:%s', $this->escaper->escapeWord($value));
|
return sprintf('type:%s', $this->escaper->escapeWord($value));
|
||||||
default:
|
default:
|
||||||
return sprintf('%s = %s',
|
return sprintf('field.%s = %s',
|
||||||
$this->escaper->escapeWord($name),
|
$this->escaper->escapeWord($name),
|
||||||
$this->escaper->escapeWord($value));
|
$this->escaper->escapeWord($value));
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,10 @@ class FacetsResponse implements JsonSerializable
|
|||||||
throw new RuntimeException('Invalid aggregation response');
|
throw new RuntimeException('Invalid aggregation response');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function jsonSerialize()
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray()
|
||||||
{
|
{
|
||||||
return $this->facets;
|
return $this->facets;
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,7 @@ class SearchEngineResult
|
|||||||
protected $suggestions;
|
protected $suggestions;
|
||||||
protected $propositions;
|
protected $propositions;
|
||||||
protected $indexes;
|
protected $indexes;
|
||||||
|
/** @var FacetsResponse */
|
||||||
protected $facets;
|
protected $facets;
|
||||||
|
|
||||||
public function __construct(ArrayCollection $results, $query, $duration, $offsetStart, $available, $total, $error,
|
public function __construct(ArrayCollection $results, $query, $duration, $offsetStart, $available, $total, $error,
|
||||||
@@ -182,6 +183,6 @@ class SearchEngineResult
|
|||||||
*/
|
*/
|
||||||
public function getFacets()
|
public function getFacets()
|
||||||
{
|
{
|
||||||
return $this->facets;
|
return $this->facets->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,14 +1,14 @@
|
|||||||
<?xml version='1.0' encoding='utf-8'?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
|
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
|
||||||
<file date="2015-11-19T12:47:12Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
|
<file date="2015-11-23T15:43:56Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
|
||||||
<header>
|
<header>
|
||||||
<tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
|
<tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
|
||||||
<note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
|
<note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
|
||||||
</header>
|
</header>
|
||||||
<body>
|
<body>
|
||||||
<trans-unit id="da39a3ee5e6b4b0d3255bfef95601890afd80709" resname="">
|
<trans-unit id="da39a3ee5e6b4b0d3255bfef95601890afd80709" resname="">
|
||||||
<source/>
|
<source></source>
|
||||||
<target state="new"/>
|
<target state="new"></target>
|
||||||
<jms:reference-file line="47">Form/Configuration/EmailFormType.php</jms:reference-file>
|
<jms:reference-file line="47">Form/Configuration/EmailFormType.php</jms:reference-file>
|
||||||
<jms:reference-file line="60">Form/Login/PhraseaAuthenticationForm.php</jms:reference-file>
|
<jms:reference-file line="60">Form/Login/PhraseaAuthenticationForm.php</jms:reference-file>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
@@ -136,7 +136,7 @@
|
|||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="de0804eb70c10b14d71df74292e45c6daa13d672" resname="%number% documents<br/>selectionnes" approved="yes">
|
<trans-unit id="de0804eb70c10b14d71df74292e45c6daa13d672" resname="%number% documents<br/>selectionnes" approved="yes">
|
||||||
<source><![CDATA[%number% documents<br/>selectionnes]]></source>
|
<source><![CDATA[%number% documents<br/>selectionnes]]></source>
|
||||||
<target state="translated">%number% documents<br/>selected</target>
|
<target state="translated"><![CDATA[%number% documents<br/>selected]]></target>
|
||||||
<jms:reference-file line="154">Controller/Prod/QueryController.php</jms:reference-file>
|
<jms:reference-file line="154">Controller/Prod/QueryController.php</jms:reference-file>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="ac5c6fe2979cfa2496c95dcb218f135fd916040d" resname="%quantity% Stories attached to the WorkZone" approved="yes">
|
<trans-unit id="ac5c6fe2979cfa2496c95dcb218f135fd916040d" resname="%quantity% Stories attached to the WorkZone" approved="yes">
|
||||||
@@ -10837,6 +10837,21 @@
|
|||||||
<target state="translated">Find</target>
|
<target state="translated">Find</target>
|
||||||
<jms:reference-file line="280">prod/actions/edit_default.html.twig</jms:reference-file>
|
<jms:reference-file line="280">prod/actions/edit_default.html.twig</jms:reference-file>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="cb08c63b1c016e31a255a38795c8e4cb66b0e66e" resname="prod::facet:base_label">
|
||||||
|
<source>prod::facet:base_label</source>
|
||||||
|
<target state="new">Base</target>
|
||||||
|
<jms:reference-file line="188">Controller/Prod/QueryController.php</jms:reference-file>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="36fa870bac03b1a7c83f2b7030bf93ed4718e0a7" resname="prod::facet:collection_label">
|
||||||
|
<source>prod::facet:collection_label</source>
|
||||||
|
<target state="new">Collection</target>
|
||||||
|
<jms:reference-file line="189">Controller/Prod/QueryController.php</jms:reference-file>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="12988153991e94fd6fc58934903504b0bf03c30a" resname="prod::facet:doctype_label">
|
||||||
|
<source>prod::facet:doctype_label</source>
|
||||||
|
<target state="new">Document Type</target>
|
||||||
|
<jms:reference-file line="190">Controller/Prod/QueryController.php</jms:reference-file>
|
||||||
|
</trans-unit>
|
||||||
<trans-unit id="2a4d65f9a1aaeec92617d3d5dc3ef0167a019e82" resname="prod::recherche: Attention : la liste des bases selectionnees pour la recherche a ete changee." approved="yes">
|
<trans-unit id="2a4d65f9a1aaeec92617d3d5dc3ef0167a019e82" resname="prod::recherche: Attention : la liste des bases selectionnees pour la recherche a ete changee." approved="yes">
|
||||||
<source>prod::recherche: Attention : la liste des bases selectionnees pour la recherche a ete changee.</source>
|
<source>prod::recherche: Attention : la liste des bases selectionnees pour la recherche a ete changee.</source>
|
||||||
<target state="translated">Warning, list of collections to search in has been changed</target>
|
<target state="translated">Warning, list of collections to search in has been changed</target>
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
|
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
|
||||||
<file date="2015-11-19T12:47:12Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
|
<file date="2015-11-23T15:43:56Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
|
||||||
<header>
|
<header>
|
||||||
<tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
|
<tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
|
||||||
<note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
|
<note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
|
||||||
|
@@ -620,7 +620,7 @@ function loadFacets(facets) {
|
|||||||
});
|
});
|
||||||
// Facet
|
// Facet
|
||||||
return {
|
return {
|
||||||
title: facet.name,
|
title: facet.label,
|
||||||
folder: true,
|
folder: true,
|
||||||
children: values,
|
children: values,
|
||||||
expanded: _.isUndefined(selectedFacetValues[facet.name])
|
expanded: _.isUndefined(selectedFacetValues[facet.name])
|
||||||
|
Reference in New Issue
Block a user