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="" - typo3DatabasePassword=""
- TYPO3_VERSION="~7.6" - TYPO3_VERSION="~7.6"
matrix:
fast_finish: true
services: services:
- mysql - mysql

View file

@ -61,7 +61,10 @@ class DocumentFactory implements Singleton
$identifier = $document['search_identifier']; $identifier = $document['search_identifier'];
unset($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); return new \Elastica\Document($identifier, $document);
} }

View file

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

View file

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

View file

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

View file

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