From 7ef8e2c0371e9b4fe5a99c486a8db90f1d32e303 Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Wed, 3 Jun 2015 18:44:18 +0200 Subject: [PATCH 1/2] wip --- .../SearchEngine/Elastic/ElasticSearchEngine.php | 5 +++++ .../Elastic/Search/FacetsResponse.php | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php index dcb2b60cc8..dff0d31cfe 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php @@ -378,6 +378,11 @@ class ElasticSearchEngine implements SearchEngineInterface $collection_facet_agg['terms']['field'] = 'collection_name'; $aggs['Collection'] = $collection_facet_agg; + // We always want a base facet right now + $base_facet_agg = array(); + $base_facet_agg['terms']['field'] = 'databox_name'; + $aggs['Base'] = $base_facet_agg; + foreach ($this->structure->getFacetFields() as $name => $field) { // 2015-05-26 (mdarse) Removed databox filtering. // It was already done by the ACL filter in the query scope, so no diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Search/FacetsResponse.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Search/FacetsResponse.php index 299e3f2bbe..b6a63e9b71 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Search/FacetsResponse.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Search/FacetsResponse.php @@ -50,9 +50,18 @@ class FacetsResponse implements JsonSerializable private function buildQuery($name, $value) { - return ($name === 'Collection') ? - sprintf('collection:%s', $this->escaper->escapeWord($value)) : - sprintf('r"%s" IN %s', $this->escaper->escapeRaw($value), $name); + switch($name) { + case 'Collection': + $r = sprintf('collection:%s', $this->escaper->escapeWord($value)); + break; + case "Base": + $r = sprintf('base:%s', $this->escaper->escapeWord($value)); + break; + default: + $r = sprintf('r"%s" IN %s', $this->escaper->escapeRaw($value), $name); + break; + } + return $r; } private function throwAggregationResponseError() From 90ae2f24749ed99fcb26accd0356edc0d14edc74 Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Mon, 22 Jun 2015 17:06:26 +0200 Subject: [PATCH 2/2] PHRAS-454 #time 4h --- .../Elastic/Indexer/Record/Hydrator/CoreHydrator.php | 5 ++++- .../Phrasea/SearchEngine/Elastic/Indexer/RecordIndexer.php | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Hydrator/CoreHydrator.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Hydrator/CoreHydrator.php index d72c608f52..cc9306785e 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Hydrator/CoreHydrator.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/Record/Hydrator/CoreHydrator.php @@ -17,11 +17,13 @@ use Alchemy\Phrasea\SearchEngine\SearchEngineInterface; class CoreHydrator implements HydratorInterface { private $databox_id; + private $databox_name; private $helper; - public function __construct($databox_id, RecordHelper $helper) + public function __construct($databox_id, $databox_name, RecordHelper $helper) { $this->databox_id = $databox_id; + $this->databox_name = $databox_name; $this->helper = $helper; } @@ -41,6 +43,7 @@ class CoreHydrator implements HydratorInterface $record['id'] = $this->helper->getUniqueRecordId($this->databox_id, $record['record_id']); $record['base_id'] = $this->helper->getUniqueCollectionId($this->databox_id, $record['collection_id']); $record['databox_id'] = $this->databox_id; + $record['databox_name'] = $this->databox_name; $record['record_type'] = ((int) $record['parent_record_id'] === 1) ? SearchEngineInterface::GEM_TYPE_STORY diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndexer.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndexer.php index 0ec855bfe8..205d15523d 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndexer.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/Indexer/RecordIndexer.php @@ -140,7 +140,7 @@ class RecordIndexer $connection = $databox->get_connection(); $candidateTerms = new CandidateTerms($databox); $fetcher = new Fetcher($connection, array( - new CoreHydrator($databox->get_sbas_id(), $this->helper), + new CoreHydrator($databox->get_sbas_id(), $databox->get_viewname(), $this->helper), new TitleHydrator($connection), new MetadataHydrator($connection, $this->structure, $this->helper), new ThesaurusHydrator($this->structure, $this->thesaurus, $candidateTerms), @@ -186,6 +186,7 @@ class RecordIndexer // Identifiers ->add('record_id', 'integer') // Compound primary key ->add('databox_id', 'integer') // Compound primary key + ->add('databox_name', 'string')->notAnalyzed() // database name (still indexed for facets) ->add('base_id', 'integer') // Unique collection ID ->add('collection_id', 'integer')->notIndexed() // Useless collection ID (local to databox) ->add('collection_name', 'string')->notAnalyzed() // Collection name (still indexed for facets)