mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
Merge pull request #1399 from mdarse/new-structure-regression-search-in
Fix IN search regression
This commit is contained in:
@@ -59,7 +59,6 @@ class SearchEngineServiceProvider implements ServiceProviderInterface
|
|||||||
$app['elasticsearch.client'],
|
$app['elasticsearch.client'],
|
||||||
$app['elasticsearch.options']['index'],
|
$app['elasticsearch.options']['index'],
|
||||||
$app['locales.available'],
|
$app['locales.available'],
|
||||||
$app['elasticsearch.record_helper'],
|
|
||||||
$app['elasticsearch.facets_response.factory']
|
$app['elasticsearch.facets_response.factory']
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@@ -41,15 +41,13 @@ class ElasticSearchEngine implements SearchEngineInterface
|
|||||||
private $indexName;
|
private $indexName;
|
||||||
private $configurationPanel;
|
private $configurationPanel;
|
||||||
private $locales;
|
private $locales;
|
||||||
private $recordHelper;
|
|
||||||
|
|
||||||
public function __construct(Application $app, Structure $structure, Client $client, $indexName, array $locales, RecordHelper $recordHelper, Closure $facetsResponseFactory)
|
public function __construct(Application $app, Structure $structure, Client $client, $indexName, array $locales, Closure $facetsResponseFactory)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
$this->structure = $structure;
|
$this->structure = $structure;
|
||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
$this->locales = array_keys($locales);
|
$this->locales = array_keys($locales);
|
||||||
$this->recordHelper = $recordHelper;
|
|
||||||
$this->facetsResponseFactory = $facetsResponseFactory;
|
$this->facetsResponseFactory = $facetsResponseFactory;
|
||||||
|
|
||||||
if ('' === trim($indexName)) {
|
if ('' === trim($indexName)) {
|
||||||
@@ -384,7 +382,7 @@ class ElasticSearchEngine implements SearchEngineInterface
|
|||||||
// 2015-05-26 (mdarse) Removed databox filtering.
|
// 2015-05-26 (mdarse) Removed databox filtering.
|
||||||
// It was already done by the ACL filter in the query scope, so no
|
// It was already done by the ACL filter in the query scope, so no
|
||||||
// document that shouldn't be displayed can go this far.
|
// document that shouldn't be displayed can go this far.
|
||||||
$field_name = RecordHelper::getIndexFieldName($field);
|
$field_name = $field->getIndexFieldName();
|
||||||
$aggs[$name]['terms']['field'] = sprintf('%s.raw', $field_name);
|
$aggs[$name]['terms']['field'] = sprintf('%s.raw', $field_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -85,13 +85,4 @@ class RecordHelper
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getIndexFieldName(Field $field)
|
|
||||||
{
|
|
||||||
return sprintf(
|
|
||||||
'%scaption.%s',
|
|
||||||
$field->isPrivate() ? 'private_' : '',
|
|
||||||
$field->getName()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -34,7 +34,7 @@ class QueryContext
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new static($this->locales, $this->queryLocale, $fields);
|
return new static($this->structure, $this->locales, $this->queryLocale, $fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRawFields()
|
public function getRawFields()
|
||||||
@@ -94,7 +94,7 @@ class QueryContext
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO Field label dereferencing (we only want names)
|
// TODO Field label dereferencing (we only want names)
|
||||||
return RecordIndexer::getIndexFieldName($field);
|
return $field->getIndexFieldName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFields()
|
public function getFields()
|
||||||
|
@@ -73,6 +73,15 @@ class Field
|
|||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getIndexFieldName()
|
||||||
|
{
|
||||||
|
return sprintf(
|
||||||
|
'%scaption.%s',
|
||||||
|
$this->is_private ? 'private_' : '',
|
||||||
|
$this->name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function getType()
|
public function getType()
|
||||||
{
|
{
|
||||||
return $this->type;
|
return $this->type;
|
||||||
|
@@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Alchemy\Tests\Phrasea\SearchEngine\Search;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
|
||||||
|
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
|
||||||
|
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field;
|
||||||
|
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Structure;
|
||||||
|
|
||||||
|
class QueryContextTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testFieldNarrowing()
|
||||||
|
{
|
||||||
|
$structure = $this->prophesize(Structure::class)->reveal();
|
||||||
|
$available_locales = ['ab', 'cd', 'ef'];
|
||||||
|
$context = new QueryContext($structure, $available_locales, 'fr');
|
||||||
|
$narrowed = $context->narrowToFields(['some_field']);
|
||||||
|
$this->assertEquals(['some_field'], $narrowed->getFields());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFieldNormalization()
|
||||||
|
{
|
||||||
|
$public_field = new Field('foo', Mapping::TYPE_STRING, true, false);
|
||||||
|
$restricted_field = new Field('bar', Mapping::TYPE_STRING, true, true);
|
||||||
|
$structure = $this->prophesize(Structure::class);
|
||||||
|
$structure->get('foo')->willReturn($public_field);
|
||||||
|
$structure->get('bar')->willReturn($restricted_field);
|
||||||
|
|
||||||
|
$context = new QueryContext($structure->reveal(), [], 'fr');
|
||||||
|
$this->assertEquals('caption.foo', $context->normalizeField('foo'));
|
||||||
|
$this->assertEquals('private_caption.bar', $context->normalizeField('bar'));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user