From 218d8d728992daf49c8d30ccaf0360ee49fad5c1 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 15 Mar 2018 08:29:44 +0100 Subject: [PATCH 1/4] FEATURE: Make content fields configurable Allows integrators to configure which fields should be used to produce field "content" for indexed pages. Before only "bodytext" was used. This is now configurable and "header" was added to defaults. Resolves: #134 --- .../Domain/Index/TcaIndexer/PagesIndexer.php | 21 ++++++++++++++++++- Configuration/TypoScript/constants.txt | 3 ++- Configuration/TypoScript/setup.txt | 1 + Documentation/source/changelog.rst | 1 + ...15-134-make-conent-fields-configurable.rst | 13 ++++++++++++ .../source/configuration/indexing.rst | 17 +++++++++++++++ Tests/Functional/Fixtures/BasicSetup.ts | 3 ++- .../Functional/Indexing/PagesIndexerTest.php | 4 +++- 8 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 Documentation/source/changelog/20180415-134-make-conent-fields-configurable.rst diff --git a/Classes/Domain/Index/TcaIndexer/PagesIndexer.php b/Classes/Domain/Index/TcaIndexer/PagesIndexer.php index 7124ca1..7c6f8cc 100644 --- a/Classes/Domain/Index/TcaIndexer/PagesIndexer.php +++ b/Classes/Domain/Index/TcaIndexer/PagesIndexer.php @@ -24,6 +24,7 @@ use Codappix\SearchCore\Configuration\ConfigurationContainerInterface; use Codappix\SearchCore\Connection\ConnectionInterface; use Codappix\SearchCore\Domain\Index\TcaIndexer; use Codappix\SearchCore\Domain\Index\TcaIndexer\TcaTableService; +use TYPO3\CMS\Core\Utility\GeneralUtility; /** * Specific indexer for Pages, will basically add content of page. @@ -103,7 +104,7 @@ class PagesIndexer extends TcaIndexer $images, $this->getContentElementImages($contentElement['uid']) ); - $content[] = $contentElement['bodytext']; + $content[] = $this->getContentFromContentElement($contentElement); } return [ @@ -136,4 +137,22 @@ class PagesIndexer extends TcaIndexer return $imageRelationUids; } + + protected function getContentFromContentElement(array $contentElement) : string + { + $content = ''; + + $fieldsWithContent = GeneralUtility::trimExplode( + ',', + $this->configuration->get('indexing.' . $this->identifier . '.contentFields'), + true + ); + foreach ($fieldsWithContent as $fieldWithContent) { + if (isset($contentElement[$fieldWithContent]) && trim($contentElement[$fieldWithContent])) { + $content .= trim($contentElement[$fieldWithContent]) . ' '; + } + } + + return trim($content); + } } diff --git a/Configuration/TypoScript/constants.txt b/Configuration/TypoScript/constants.txt index 1a39851..b818471 100644 --- a/Configuration/TypoScript/constants.txt +++ b/Configuration/TypoScript/constants.txt @@ -10,12 +10,13 @@ plugin { indexing { tt_content { - additionalWhereClause = tt_content.CType NOT IN ('gridelements_pi1', 'list', 'div', 'menu', 'shortcut', 'search', 'login') AND tt_content.bodytext != '' + additionalWhereClause = tt_content.CType NOT IN ('gridelements_pi1', 'list', 'div', 'menu', 'shortcut', 'search', 'login') AND (tt_content.bodytext != '' OR tt_content.header != '') } pages { additionalWhereClause = pages.doktype NOT IN (3, 199, 6, 254, 255) abstractFields = abstract, description, bodytext + contentFields = header, bodytext } } } diff --git a/Configuration/TypoScript/setup.txt b/Configuration/TypoScript/setup.txt index 1a1577f..2749904 100644 --- a/Configuration/TypoScript/setup.txt +++ b/Configuration/TypoScript/setup.txt @@ -19,6 +19,7 @@ plugin { indexer = Codappix\SearchCore\Domain\Index\TcaIndexer\PagesIndexer additionalWhereClause = {$plugin.tx_searchcore.settings.indexing.pages.additionalWhereClause} abstractFields = {$plugin.tx_searchcore.settings.indexing.pages.abstractFields} + contentFields = {$plugin.tx_searchcore.settings.indexing.pages.abstractFields} } } diff --git a/Documentation/source/changelog.rst b/Documentation/source/changelog.rst index 4917e1b..8b1c649 100644 --- a/Documentation/source/changelog.rst +++ b/Documentation/source/changelog.rst @@ -5,6 +5,7 @@ Changelog :maxdepth: 1 :glob: + changelog/20180415-134-make-conent-fields-configurable changelog/20180409-25-provide-sys-language-uid changelog/20180408-131-respect-page-cache-clear changelog/20180408-introduce-php70-type-hints diff --git a/Documentation/source/changelog/20180415-134-make-conent-fields-configurable.rst b/Documentation/source/changelog/20180415-134-make-conent-fields-configurable.rst new file mode 100644 index 0000000..7068119 --- /dev/null +++ b/Documentation/source/changelog/20180415-134-make-conent-fields-configurable.rst @@ -0,0 +1,13 @@ +FEATURE 134 "Enable indexing of tt_content records of CType Header" +=================================================================== + +Before, only ``bodytext`` was used to generate content while indexing pages. + +As there are content elements like ``header`` where this field is empty, but content is still +available, it's now possible to configure the fields. +This makes it also possible to configure further custom content elements with new columns. + +A new TypoScript option is now available, and ``header`` is added by default, see +:ref:`contentFields`. + +See :issue:`134`. diff --git a/Documentation/source/configuration/indexing.rst b/Documentation/source/configuration/indexing.rst index 050f0ab..ec342fc 100644 --- a/Documentation/source/configuration/indexing.rst +++ b/Documentation/source/configuration/indexing.rst @@ -86,6 +86,23 @@ Default:: abstract, description, bodytext +.. _contentFields: + +contentFields +------------- + +Used by: :ref:`PagesIndexer`. + +Define which fields should be used to provide the auto generated field "content". + +Example:: + + plugin.tx_searchcore.settings.indexing.pages.contentFields := addToList(table_caption) + +Default:: + + header, bodytext + .. _mapping: mapping diff --git a/Tests/Functional/Fixtures/BasicSetup.ts b/Tests/Functional/Fixtures/BasicSetup.ts index 4129362..840a7b8 100644 --- a/Tests/Functional/Fixtures/BasicSetup.ts +++ b/Tests/Functional/Fixtures/BasicSetup.ts @@ -14,7 +14,7 @@ plugin { additionalWhereClause ( tt_content.CType NOT IN ('gridelements_pi1', 'list', 'div', 'menu', 'shortcut', 'search', 'login') - AND tt_content.bodytext != '' + AND (tt_content.bodytext != '' OR tt_content.header != '') ) mapping { @@ -27,6 +27,7 @@ plugin { pages { indexer = Codappix\SearchCore\Domain\Index\TcaIndexer\PagesIndexer abstractFields = abstract, description, bodytext + contentFields = header, bodytext mapping { CType { diff --git a/Tests/Functional/Indexing/PagesIndexerTest.php b/Tests/Functional/Indexing/PagesIndexerTest.php index 244413d..61df297 100644 --- a/Tests/Functional/Indexing/PagesIndexerTest.php +++ b/Tests/Functional/Indexing/PagesIndexerTest.php @@ -50,7 +50,9 @@ class PagesIndexerTest extends AbstractFunctionalTestCase $this->callback(function ($documents) { return count($documents) === 1 && isset($documents[0]['content']) && $documents[0]['content'] === - 'this is the content of header content element that should get indexed Some text in paragraph' + 'indexed content element' . + ' this is the content of header content element that should get indexed' . + ' Indexed without html tags Some text in paragraph' && isset($documents[0]['search_abstract']) && $documents[0]['search_abstract'] === 'Used as abstract as no abstract is defined.' ; From 8ed477501c7c612ad44b5cc1f0d0ed739304e579 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Fri, 16 Mar 2018 17:28:08 +0100 Subject: [PATCH 2/4] BUGFIX: Use contentFields constant in setup.txt --- Configuration/TypoScript/setup.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Configuration/TypoScript/setup.txt b/Configuration/TypoScript/setup.txt index 2749904..751e47c 100644 --- a/Configuration/TypoScript/setup.txt +++ b/Configuration/TypoScript/setup.txt @@ -19,7 +19,7 @@ plugin { indexer = Codappix\SearchCore\Domain\Index\TcaIndexer\PagesIndexer additionalWhereClause = {$plugin.tx_searchcore.settings.indexing.pages.additionalWhereClause} abstractFields = {$plugin.tx_searchcore.settings.indexing.pages.abstractFields} - contentFields = {$plugin.tx_searchcore.settings.indexing.pages.abstractFields} + contentFields = {$plugin.tx_searchcore.settings.indexing.pages.contentFields} } } From 32df6ff8ec6b6a61a59ebc12ab56ac74e784b579 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 20 Mar 2018 10:19:45 +0100 Subject: [PATCH 3/4] BUGFIX: Allow multiple instances with different configurations In order to use the plugin with different configurations on same site, we can not use ConfigurationContainerInterface as a Singleton. This would prevents us from using different configuration setups. --- Classes/Configuration/ConfigurationContainerInterface.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Classes/Configuration/ConfigurationContainerInterface.php b/Classes/Configuration/ConfigurationContainerInterface.php index 1978453..a5cb961 100644 --- a/Classes/Configuration/ConfigurationContainerInterface.php +++ b/Classes/Configuration/ConfigurationContainerInterface.php @@ -20,13 +20,11 @@ namespace Codappix\SearchCore\Configuration; * 02110-1301, USA. */ -use TYPO3\CMS\Core\SingletonInterface as Singleton; - /** * Container of all configurations for extension. - * Always inject this to have a single place for configuration and parsing only once. + * Always inject this to have a single place for configuration. */ -interface ConfigurationContainerInterface extends Singleton +interface ConfigurationContainerInterface { /** * Returns the option defined by section and key. From 30aa8ed10bebc4793cac722f5f9b8fd7241b56af Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 20 Mar 2018 11:02:43 +0100 Subject: [PATCH 4/4] TASK: Remove codacy from travis As we are no longer using codacy, we do not need to send any information. --- Makefile | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Makefile b/Makefile index b1f4af0..21f6c31 100644 --- a/Makefile +++ b/Makefile @@ -41,16 +41,11 @@ unitTests: .Build/bin/phpunit --colors --debug -v \ -c Tests/Unit/UnitTests.xml -uploadCodeCoverage: uploadCodeCoverageToScrutinizer uploadCodeCoverageToCodacy +uploadCodeCoverage: uploadCodeCoverageToScrutinizer uploadCodeCoverageToScrutinizer: wget https://scrutinizer-ci.com/ocular.phar && \ php ocular.phar code-coverage:upload --format=php-clover .Build/report/functional/clover/coverage -uploadCodeCoverageToCodacy: - composer require -vv --dev codacy/coverage && \ - git checkout composer.json && \ - php .Build/bin/codacycoverage clover .Build/report/functional/clover/coverage - clean: rm -rf .Build composer.lock