first commit

This commit is contained in:
Sven Wappler
2021-04-17 00:26:33 +02:00
commit 866c63cc63
813 changed files with 100696 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
<?php
namespace WapplerSystems\Meilisearch\FieldProcessor;
/***************************************************************
* Copyright notice
*
* (c) 2014-2015 Ingo Renner <ingo@typo3.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Provides common methods for field processors creating a hierarchy.
*
* @author Ingo Renner <ingo@typo3.org>
*/
abstract class AbstractHierarchyProcessor
{
/**
* Builds a Solr hierarchy from an array of uids that make up a rootline.
*
* @param array $idRootline Array of Ids representing a rootline
* @return array Solr hierarchy
* @see http://wiki.apache.org/solr/HierarchicalFaceting
*/
protected function buildSolrHierarchyFromIdRootline(array $idRootline)
{
$hierarchy = [];
$depth = 0;
$currentPath = array_shift($idRootline);
if (is_null($currentPath)) {
return $hierarchy;
}
foreach ($idRootline as $uid) {
$hierarchy[] = $depth . '-' . $currentPath . '/';
$depth++;
$currentPath .= '/' . $uid;
}
$hierarchy[] = $depth . '-' . $currentPath . '/';
return $hierarchy;
}
}

View File

@@ -0,0 +1,128 @@
<?php
namespace WapplerSystems\Meilisearch\FieldProcessor;
/***************************************************************
* Copyright notice
*
* (c) 2013-2015 Steffen Ritter <steffen.ritter@typo3.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use WapplerSystems\Meilisearch\System\Records\SystemCategory\SystemCategoryRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* This Processor takes a UID of sys_category, and resolves its rootline in solr notation.
*
* Format of this field corresponds to http://wiki.apache.org/solr/HierarchicalFaceting
*
* Let's say we have a category with uid 111 which is a sub category like shown in this tree:
*
* 1
* |-10
* |-100
* |-111
*
* then we get a rootline 1/10/100/111
*
* In Solr hierarchy notation, we get
*
* 0-1
* 1-1/10
* 2-1/10/100
* 3-1/10/100/11
*
* which is finally saved in a multi-value field.
*
* @author Steffen Ritter <steffen.ritter@typo3.org>
*/
class CategoryUidToHierarchy extends AbstractHierarchyProcessor implements FieldProcessor
{
/**
* @var SystemCategoryRepository
*/
protected $systemCategoryRepository;
/**
* CategoryUidToHierarchy constructor.
*
* @param SystemCategoryRepository|null $systemCategoryRepository
*/
public function __construct(SystemCategoryRepository $systemCategoryRepository = null)
{
$this->systemCategoryRepository = $systemCategoryRepository ?? GeneralUtility::makeInstance(SystemCategoryRepository::class);
}
/**
* Expects a uid ID of a category. Returns a Solr hierarchy notation for the
* rootline of the category ID.
*
* @param array $values Array of values, an array because of multivalued fields
* @return array Modified array of values
*/
public function process(array $values)
{
$results = [];
foreach ($values as $value) {
$results = array_merge($results,
$this->getSolrRootlineForCategoryId($value));
}
return $results;
}
/**
* Returns a Solr hierarchy notation string for rootline of given category uid.
*
* @param int $categoryId Category ID to get a rootline as Solr hierarchy for
* @return array Rootline as Solr hierarchy array
*/
protected function getSolrRootlineForCategoryId($categoryId)
{
$categoryIdRootline = $this->buildCategoryIdRootline($categoryId);
$solrRootline = $this->buildSolrHierarchyFromIdRootline($categoryIdRootline);
return $solrRootline;
}
/**
* Builds a category's rootline of parent category Ids
*
* @param int $uid The category ID to build the rootline for
* @return array Category ID rootline as array
*/
protected function buildCategoryIdRootline($uid)
{
$rootlineIds = [];
$parentCategory = intval($uid);
while ($parentCategory !== 0) {
$rootlineIds[] = $parentCategory;
$childCategory = $this->systemCategoryRepository->findOneByUid($parentCategory);
if ($childCategory === null) {
$parentCategory = 0;
} else {
$parentCategory = intval($childCategory['parent']);
}
}
krsort($rootlineIds);
return array_values($rootlineIds);
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace WapplerSystems\Meilisearch\FieldProcessor;
/***************************************************************
* Copyright notice
*
* (c) 2009-2015 Ingo Renner <ingo@typo3.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Field Processor interface
*
* @author Ingo Renner <ingo@typo3.org>
*/
interface FieldProcessor
{
/**
* process method
*
* @param array $values Array of values, an array because of multivalued fields
* @return array Modified array of values
*/
public function process(array $values);
}

View File

@@ -0,0 +1,125 @@
<?php
namespace WapplerSystems\Meilisearch\FieldProcessor;
/***************************************************************
* Copyright notice
*
* (c) 2011-2015 Michael Knoll <knoll@punkt.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use WapplerSystems\Meilisearch\Domain\Site\Site;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\RootlineUtility;
/**
* This Processor takes a PID, and resolves its rootline in solr notation.
*
* Format of this field corresponds to http://wiki.apache.org/solr/HierarchicalFaceting
*
* Let's say we have a record indexed on page 111 which is a sub page like shown in this page tree:
*
* 1
* |-10
* |-100
* |-111
*
* then we get a rootline 1/10/100/111
*
* In Solr hierarchy notation, we get
*
* 0-1/
* 1-1/10/
* 2-1/10/100/
* 3-1/10/100/11/
*
* which is finally saved in a multi-value field.
*
* @author Michael Knoll <knoll@punkt.de>
*/
class PageUidToHierarchy extends AbstractHierarchyProcessor implements FieldProcessor
{
/**
* Expects a page ID of a page. Returns a Solr hierarchy notation for the
* rootline of the page ID.
*
* @param array $values Array of values, an array because of multivalued fields
* @return array Modified array of values
*/
public function process(array $values)
{
$results = [];
foreach ($values as $value) {
list($rootPageUid, $mountPoint) = GeneralUtility::trimExplode(',',
$value, true, 2);
$results[] = $this->getSolrRootlineForPageId($rootPageUid,
$mountPoint);
}
return $results;
}
/**
* Returns a Solr hierarchy notation string for rootline of given PID.
*
* @param int $pageId Page ID to get a rootline as Solr hierarchy for
* @param string $mountPoint The mount point parameter that will be used for building the rootline.
* @return array Rootline as Solr hierarchy array
*/
protected function getSolrRootlineForPageId($pageId, $mountPoint = '')
{
$pageIdRootline = $this->buildPageIdRootline($pageId, $mountPoint);
$solrRootline = $this->buildSolrHierarchyFromIdRootline($pageIdRootline);
return $solrRootline;
}
/**
* Builds a page's rootline of parent page Ids
*
* @param int $pageId The page Id to build the rootline for
* @param string $mountPoint The mount point parameter that will be passed to getRootline().
* @return array Page Id rootline as array
*/
protected function buildPageIdRootline($pageId, $mountPoint = '')
{
$rootlinePageIds = [];
$rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $pageId, $mountPoint);
try {
$rootline = $rootlineUtility->get();
} catch (\RuntimeException $e) {
$rootline = [];
}
foreach ($rootline as $page) {
if (Site::isRootPage($page)) {
break;
}
array_unshift($rootlinePageIds, $page['pid']);
}
$rootlinePageIds[] = $pageId;
return $rootlinePageIds;
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace WapplerSystems\Meilisearch\FieldProcessor;
/***************************************************************
* Copyright notice
*
* (c) 2009-2015 Daniel Poetzinger <poetzinger@aoemedia.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\OptionBased\Hierarchy\HierarchyTool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Processes a value that may appear as field value in documents
*
* @author Daniel Poetzinger <poetzinger@aoemedia.de>
*/
class PathToHierarchy implements FieldProcessor
{
/**
* Expects a value like "some/hierarchy/value"
*
* @param array $values Array of values, an array because of multivalued fields
* @return array Modified array of values
*/
public function process(array $values)
{
$results = [];
foreach ($values as $value) {
$valueResults = $this->buildSolrHierarchyFromPath($value);
$results = array_merge($results, $valueResults);
}
return array_unique($results);
}
/**
* Builds a Solr hierarchy from path string.
*
* @param string $path path string
* @return array Solr hierarchy
* @see http://wiki.apache.org/solr/HierarchicalFaceting
*/
protected function buildSolrHierarchyFromPath($path)
{
$hierarchy = [];
$path = HierarchyTool::substituteSlashes($path);
$treeParts = GeneralUtility::trimExplode('/', $path, true);
$currentTreeParts = [];
foreach ($treeParts as $i => $part) {
$currentTreeParts[] = $part;
$hierarchyString = $i . '-' . implode('/', $currentTreeParts) . '/';
$hierarchyString = HierarchyTool::unSubstituteSlashes($hierarchyString);
$hierarchy[] = $hierarchyString;
}
return $hierarchy;
}
}

View File

@@ -0,0 +1,114 @@
<?php
namespace WapplerSystems\Meilisearch\FieldProcessor;
/***************************************************************
* Copyright notice
*
* (c) 2009-2015 Daniel Poetzinger <poetzinger@aoemedia.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use WapplerSystems\Meilisearch\FieldProcessor\CategoryUidToHierarchy;
use WapplerSystems\Meilisearch\FieldProcessor\PageUidToHierarchy;
use WapplerSystems\Meilisearch\FieldProcessor\PathToHierarchy;
use WapplerSystems\Meilisearch\FieldProcessor\TimestampToIsoDate;
use WapplerSystems\Meilisearch\FieldProcessor\TimestampToUtcIsoDate;
use WapplerSystems\Meilisearch\System\Solr\Document\Document;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Service class that modifies fields in a Apache Solr Document, used for
* common field processing during indexing or resolving
*
* @author Daniel Poetzinger <poetzinger@aoemedia.de>
*/
class Service
{
/**
* Modifies a list of documents
*
* @param Document[] $documents
* @param array $processingConfiguration
*/
public function processDocuments(array $documents, array $processingConfiguration) {
foreach ($documents as $document) {
$this->processDocument($document, $processingConfiguration);
}
}
/**
* modifies a document according to the given configuration
*
* @param Document $document
* @param array $processingConfiguration
*/
public function processDocument(Document $document, array $processingConfiguration) {
foreach ($processingConfiguration as $fieldName => $instruction) {
$fieldValue = $document[$fieldName] ?? false;
$isSingleValueField = false;
if ($fieldValue !== false) {
if (!is_array($fieldValue)) {
// turn single value field into multi value field
$fieldValue = [$fieldValue];
$isSingleValueField = true;
}
switch ($instruction) {
case 'timestampToUtcIsoDate':
/** @var $processor TimestampToUtcIsoDate */
$processor = GeneralUtility::makeInstance(TimestampToUtcIsoDate::class);
$fieldValue = $processor->process($fieldValue);
break;
case 'timestampToIsoDate':
/** @var $processor TimestampToIsoDate */
$processor = GeneralUtility::makeInstance(TimestampToIsoDate::class);
$fieldValue = $processor->process($fieldValue);
break;
case 'pathToHierarchy':
/** @var $processor PathToHierarchy */
$processor = GeneralUtility::makeInstance(PathToHierarchy::class);
$fieldValue = $processor->process($fieldValue);
break;
case 'pageUidToHierarchy':
/** @var $processor PageUidToHierarchy */
$processor = GeneralUtility::makeInstance(PageUidToHierarchy::class);
$fieldValue = $processor->process($fieldValue);
break;
case 'categoryUidToHierarchy':
/** @var $processor CategoryUidToHierarchy */
$processor = GeneralUtility::makeInstance(CategoryUidToHierarchy::class);
$fieldValue = $processor->process($fieldValue);
break;
case 'uppercase':
$fieldValue = array_map('mb_strtoupper', $fieldValue);
break;
}
if ($isSingleValueField) {
// turn multi value field back into single value field
$fieldValue = $fieldValue[0];
}
$document->setField($fieldName, $fieldValue);
}
}
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace WapplerSystems\Meilisearch\FieldProcessor;
/***************************************************************
* Copyright notice
*
* (c) 2009-2015 Ingo Renner <ingo@typo3.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use WapplerSystems\Meilisearch\System\DateTime\FormatService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* A field processor that converts timestamps to ISO dates as needed by Solr
*
* @author Ingo Renner <ingo@typo3.org>
*/
class TimestampToIsoDate implements FieldProcessor
{
/**
* Expects a timestamp and converts it to an ISO 8601 date as needed by Solr.
*
* Example date output format: 1995-12-31T23:59:59Z
* The trailing "Z" designates UTC time and is mandatory
*
* @param array $values Array of values, an array because of multivalued fields
* @return array Modified array of values
*/
public function process(array $values)
{
$results = [];
$formatService = GeneralUtility::makeInstance(FormatService::class);
foreach ($values as $timestamp) {
$results[] = $formatService->timestampToIso($timestamp);
}
return $results;
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace WapplerSystems\Meilisearch\FieldProcessor;
/***************************************************************
* Copyright notice
*
* (c) 2009-2015 Andreas Allacher <andreas.allacher@cyberhouse.at>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use WapplerSystems\Meilisearch\System\DateTime\FormatService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* A field processor that converts timestamps to ISO dates as needed by Solr
*
* @author Andreas Allacher <andreas.allacher@cyberhouse.at>
*/
class TimestampToUtcIsoDate implements FieldProcessor
{
/**
* Expects a timestamp and converts it to an ISO 8601 date in UTC as needed by Solr.
*
* Example date output format: 1995-12-31T23:59:59Z
* The trailing "Z" designates UTC time and is mandatory
*
* @param array $values Array of values, an array because of multivalued fields
* @return array Modified array of values
*/
public function process(array $values)
{
$results = [];
$formatService = GeneralUtility::makeInstance(FormatService::class);
foreach ($values as $timestamp) {
$results[] = $formatService->timestampToUtcIso($timestamp);
}
return $results;
}
}