Merge remote-tracking branch 'origin/develop' into feature/add-pagination

Conflicts:
    Classes/Domain/Search/QueryFactory.php
This commit is contained in:
Daniel Siepmann 2017-08-15 08:29:48 +02:00
commit bd8ed737e2
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
6 changed files with 49 additions and 41 deletions

View file

@ -26,6 +26,9 @@ env:
- typo3DatabasePassword=""
- TYPO3_VERSION="~7.6"
matrix:
fast_finish: true
services:
- mysql

View file

@ -61,7 +61,10 @@ class DocumentFactory implements Singleton
$identifier = $document['search_identifier'];
unset($document['search_identifier']);
$this->logger->debug('Convert document to document', [$identifier, $document]);
$this->logger->debug(
sprintf('Convert %s %u to document.', $documentType, $identifier),
[$identifier, $document]
);
return new \Elastica\Document($identifier, $document);
}

View file

@ -20,13 +20,10 @@ namespace Codappix\SearchCore\Domain\Index\TcaIndexer;
* 02110-1301, USA.
*/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\SingletonInterface as Singleton;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Backend\Form\FormDataCompiler;
use TYPO3\CMS\Backend\Form\FormDataGroup\TcaDatabaseRecord;
use TYPO3\CMS\Core\SingletonInterface as Singleton;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Resolves relations from TCA using TCA.
@ -81,7 +78,7 @@ class RelationResolver implements Singleton
protected function resolveValue($value, array $tcaColumn)
{
if ($value === '' || $value === '0') {
return '';
return [];
}
if ($tcaColumn['config']['type'] === 'select') {
return $this->resolveSelectValue($value, $tcaColumn);
@ -93,7 +90,7 @@ class RelationResolver implements Singleton
return $this->resolveInlineValue($tcaColumn);
}
return '';
return [];
}
/**

View file

@ -39,11 +39,6 @@ class QueryFactory
*/
protected $configuration;
/**
* @var array
*/
protected $query = [];
/**
* @param \TYPO3\CMS\Core\Log\LogManager $logManager
* @param ConfigurationContainerInterface $configuration
@ -77,26 +72,28 @@ class QueryFactory
*/
protected function createElasticaQuery(SearchRequestInterface $searchRequest)
{
$this->addSize($searchRequest);
$this->addSearch($searchRequest);
$this->addBoosts($searchRequest);
$this->addFilter($searchRequest);
$this->addFacets($searchRequest);
$query = [];
$this->addSize($searchRequest, $query);
$this->addSearch($searchRequest, $query);
$this->addBoosts($searchRequest, $query);
$this->addFilter($searchRequest, $query);
$this->addFacets($searchRequest, $query);
// Use last, as it might change structure of query.
// Better approach would be something like DQL to generate query and build result in the end.
$this->addFactorBoost();
$this->addFactorBoost($query);
$this->logger->debug('Generated elasticsearch query.', [$this->query]);
return new \Elastica\Query($this->query);
$this->logger->debug('Generated elasticsearch query.', [$query]);
return new \Elastica\Query($query);
}
/**
* @param SearchRequestInterface $searchRequest
* @param array &$query
*/
protected function addSize(SearchRequestInterface $searchRequest)
protected function addSize(SearchRequestInterface $searchRequest, array &$query)
{
$this->query = ArrayUtility::arrayMergeRecursiveOverrule($this->query, [
$query = ArrayUtility::arrayMergeRecursiveOverrule($this->query, [
'from' => $searchRequest->getOffset(),
'size' => $searchRequest->getLimit(),
]);
@ -104,19 +101,20 @@ class QueryFactory
/**
* @param SearchRequestInterface $searchRequest
* @param array &$query
*/
protected function addSearch(SearchRequestInterface $searchRequest)
protected function addSearch(SearchRequestInterface $searchRequest, array &$query)
{
$this->query = ArrayUtility::setValueByPath(
$this->query,
$query = ArrayUtility::setValueByPath(
$query,
'query.bool.must.0.match._all.query',
$searchRequest->getSearchTerm()
);
$minimumShouldMatch = $this->configuration->getIfExists('searching.minimumShouldMatch');
if ($minimumShouldMatch) {
$this->query = ArrayUtility::setValueByPath(
$this->query,
$query = ArrayUtility::setValueByPath(
$query,
'query.bool.must.0.match._all.minimum_should_match',
$minimumShouldMatch
);
@ -125,8 +123,9 @@ class QueryFactory
/**
* @param SearchRequestInterface $searchRequest
* @param array &$query
*/
protected function addBoosts(SearchRequestInterface $searchRequest)
protected function addBoosts(SearchRequestInterface $searchRequest, array &$query)
{
try {
$fields = $this->configuration->get('searching.boost');
@ -147,7 +146,7 @@ class QueryFactory
];
}
$this->query = ArrayUtility::arrayMergeRecursiveOverrule($this->query, [
$query = ArrayUtility::arrayMergeRecursiveOverrule($query, [
'query' => [
'bool' => [
'should' => $boostQueryParts,
@ -156,12 +155,15 @@ class QueryFactory
]);
}
protected function addFactorBoost()
/**
* @param array &$query
*/
protected function addFactorBoost(array &$query)
{
try {
$this->query['query'] = [
$query['query'] = [
'function_score' => [
'query' => $this->query['query'],
'query' => $query['query'],
'field_value_factor' => $this->configuration->get('searching.fieldValueFactor'),
],
];
@ -172,8 +174,9 @@ class QueryFactory
/**
* @param SearchRequestInterface $searchRequest
* @param array &$query
*/
protected function addFilter(SearchRequestInterface $searchRequest)
protected function addFilter(SearchRequestInterface $searchRequest, array &$query)
{
if (! $searchRequest->hasFilter()) {
return;
@ -188,7 +191,7 @@ class QueryFactory
];
}
$this->query = ArrayUtility::arrayMergeRecursiveOverrule($this->query, [
$query = ArrayUtility::arrayMergeRecursiveOverrule($query, [
'query' => [
'bool' => [
'filter' => $terms,
@ -199,11 +202,12 @@ class QueryFactory
/**
* @param SearchRequestInterface $searchRequest
* @param array &$query
*/
protected function addFacets(SearchRequestInterface $searchRequest)
protected function addFacets(SearchRequestInterface $searchRequest, array &$query)
{
foreach ($searchRequest->getFacets() as $facet) {
$this->query = ArrayUtility::arrayMergeRecursiveOverrule($this->query, [
$query = ArrayUtility::arrayMergeRecursiveOverrule($query, [
'aggs' => [
$facet->getIdentifier() => [
'terms' => [

View file

@ -9,6 +9,10 @@ plugin {
}
indexing {
tt_content {
additionalWhereClause = tt_content.CType NOT IN ('gridelements_pi1', 'list', 'div', 'menu', 'shortcut', 'search', 'login') AND tt_content.bodytext != ''
}
pages {
additionalWhereClause = pages.doktype NOT IN (3, 199, 6, 254, 255)
abstractFields = abstract, description, bodytext

View file

@ -12,10 +12,7 @@ plugin {
# Not for direct indexing therefore no indexer.
# Used to configure tt_content fetching while indexing pages
tt_content {
additionalWhereClause (
tt_content.CType NOT IN ('gridelements_pi1', 'list', 'div', 'menu', 'shortcut', 'search', 'login')
AND tt_content.bodytext != ''
)
additionalWhereClause = {$plugin.tx_searchcore.settings.indexing.tt_content.additionalWhereClause}
}
pages {