first commit
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\Domain\Search\ApacheMeilisearchDocument;
|
||||
namespace WapplerSystems\Meilisearch\Domain\Search\MeilisearchDocument;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
@@ -35,7 +35,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
|
||||
|
||||
/**
|
||||
* Builder class to build an ApacheMeilisearchDocument
|
||||
* Builder class to build an MeilisearchDocument
|
||||
*
|
||||
* Responsible to build \WapplerSystems\Meilisearch\System\Meilisearch\Document\Document
|
||||
*
|
||||
@@ -64,38 +64,37 @@ class Builder
|
||||
* @param string $url
|
||||
* @param Rootline $pageAccessRootline
|
||||
* @param string $mountPointParameter
|
||||
* @return Document|object
|
||||
* @return array
|
||||
*/
|
||||
public function fromPage(TypoScriptFrontendController $page, $url, Rootline $pageAccessRootline, $mountPointParameter): Document
|
||||
public function fromPage(TypoScriptFrontendController $page, $url, Rootline $pageAccessRootline, $mountPointParameter): array
|
||||
{
|
||||
/* @var $document Document */
|
||||
$document = GeneralUtility::makeInstance(Document::class);
|
||||
$document = [];
|
||||
$site = $this->getSiteByPageId($page->id);
|
||||
$pageRecord = $page->page;
|
||||
|
||||
$accessGroups = $this->getDocumentIdGroups($pageAccessRootline);
|
||||
$documentId = $this->getPageDocumentId($page, $accessGroups, $mountPointParameter);
|
||||
|
||||
$document->setField('id', $documentId);
|
||||
$document->setField('site', $site->getDomain());
|
||||
$document->setField('siteHash', $site->getSiteHash());
|
||||
$document->setField('appKey', 'EXT:meilisearch');
|
||||
$document->setField('type', 'pages');
|
||||
$document['id'] = $documentId;
|
||||
$document['site'] = $site->getDomain();
|
||||
$document['siteHash'] = $site->getSiteHash();
|
||||
$document['appKey'] = 'EXT:meilisearch';
|
||||
$document['type'] = 'pages';
|
||||
|
||||
// system fields
|
||||
$document->setField('uid', $page->id);
|
||||
$document->setField('pid', $pageRecord['pid']);
|
||||
$document['uid'] = $page->id;
|
||||
$document['pid'] = $pageRecord['pid'];
|
||||
|
||||
// variantId
|
||||
$variantId = $this->variantIdBuilder->buildFromTypeAndUid('pages', $page->id);
|
||||
$document->setField('variantId', $variantId);
|
||||
$document['variantId'] = $variantId;
|
||||
|
||||
$document->setField('typeNum', $page->type);
|
||||
$document->setField('created', $pageRecord['crdate']);
|
||||
$document->setField('changed', $pageRecord['SYS_LASTCHANGED']);
|
||||
$document['typeNum'] = $page->type;
|
||||
$document['created'] = $pageRecord['crdate'];
|
||||
$document['changed'] = $pageRecord['SYS_LASTCHANGED'];
|
||||
|
||||
$rootline = $this->getRootLineFieldValue($page->id, $mountPointParameter);
|
||||
$document->setField('rootline', $rootline);
|
||||
$document['rootline'] = $rootline;
|
||||
|
||||
// access
|
||||
$this->addAccessField($document, $pageAccessRootline);
|
||||
@@ -104,14 +103,14 @@ class Builder
|
||||
// content
|
||||
// @extensionScannerIgnoreLine
|
||||
$contentExtractor = $this->getExtractorForPageContent($page->content);
|
||||
$document->setField('title', $contentExtractor->getPageTitle());
|
||||
$document->setField('subTitle', $pageRecord['subtitle']);
|
||||
$document->setField('navTitle', $pageRecord['nav_title']);
|
||||
$document->setField('author', $pageRecord['author']);
|
||||
$document->setField('description', $pageRecord['description']);
|
||||
$document->setField('abstract', $pageRecord['abstract']);
|
||||
$document->setField('content', $contentExtractor->getIndexableContent());
|
||||
$document->setField('url', $url);
|
||||
$document['title'] = $contentExtractor->getPageTitle();
|
||||
$document['subTitle'] = $pageRecord['subtitle'];
|
||||
$document['navTitle'] = $pageRecord['nav_title'];
|
||||
$document['author'] = $pageRecord['author'];
|
||||
$document['description'] = $pageRecord['description'];
|
||||
$document['abstract'] = $pageRecord['abstract'];
|
||||
$document['content'] = $contentExtractor->getIndexableContent();
|
||||
$document['url'] = $url;
|
||||
|
||||
$this->addKeywordsField($document, $pageRecord);
|
||||
$this->addTagContentFields($document, $contentExtractor->getTagContent());
|
||||
@@ -127,9 +126,9 @@ class Builder
|
||||
* @param string $type
|
||||
* @param int $rootPageUid
|
||||
* @param string $accessRootLine
|
||||
* @return Document
|
||||
* @return array
|
||||
*/
|
||||
public function fromRecord(array $itemRecord, string $type, int $rootPageUid, string $accessRootLine): Document
|
||||
public function fromRecord(array $itemRecord, string $type, int $rootPageUid, string $accessRootLine): array
|
||||
{
|
||||
/* @var $document Document */
|
||||
$document = GeneralUtility::makeInstance(Document::class);
|
||||
@@ -139,36 +138,36 @@ class Builder
|
||||
$documentId = $this->getDocumentId($type, $site->getRootPageId(), $itemRecord['uid']);
|
||||
|
||||
// required fields
|
||||
$document->setField('id', $documentId);
|
||||
$document->setField('type', $type);
|
||||
$document->setField('appKey', 'EXT:meilisearch');
|
||||
$document['id'] = $documentId;
|
||||
$document['type'] = $type;
|
||||
$document['appKey'] = 'EXT:meilisearch';
|
||||
|
||||
// site, siteHash
|
||||
$document->setField('site', $site->getDomain());
|
||||
$document->setField('siteHash', $site->getSiteHash());
|
||||
$document['site'] = $site->getDomain();
|
||||
$document['siteHash'] = $site->getSiteHash();
|
||||
|
||||
// uid, pid
|
||||
$document->setField('uid', $itemRecord['uid']);
|
||||
$document->setField('pid', $itemRecord['pid']);
|
||||
$document['uid'] = $itemRecord['uid'];
|
||||
$document['pid'] = $itemRecord['pid'];
|
||||
|
||||
// variantId
|
||||
$variantId = $this->variantIdBuilder->buildFromTypeAndUid($type, $itemRecord['uid']);
|
||||
$document->setField('variantId', $variantId);
|
||||
$document['variantId'] = $variantId;
|
||||
|
||||
// created, changed
|
||||
if (!empty($GLOBALS['TCA'][$type]['ctrl']['crdate'])) {
|
||||
$document->setField('created', $itemRecord[$GLOBALS['TCA'][$type]['ctrl']['crdate']]);
|
||||
$document['created'] = $itemRecord[$GLOBALS['TCA'][$type]['ctrl']['crdate']];
|
||||
}
|
||||
if (!empty($GLOBALS['TCA'][$type]['ctrl']['tstamp'])) {
|
||||
$document->setField('changed', $itemRecord[$GLOBALS['TCA'][$type]['ctrl']['tstamp']]);
|
||||
$document['changed'] = $itemRecord[$GLOBALS['TCA'][$type]['ctrl']['tstamp']];
|
||||
}
|
||||
|
||||
// access, endtime
|
||||
$document->setField('access', $accessRootLine);
|
||||
$document['access'] = $accessRootLine;
|
||||
if (!empty($GLOBALS['TCA'][$type]['ctrl']['enablecolumns']['endtime'])
|
||||
&& $itemRecord[$GLOBALS['TCA'][$type]['ctrl']['enablecolumns']['endtime']] != 0
|
||||
) {
|
||||
$document->setField('endtime', $itemRecord[$GLOBALS['TCA'][$type]['ctrl']['enablecolumns']['endtime']]);
|
||||
$document['endtime'] = $itemRecord[$GLOBALS['TCA'][$type]['ctrl']['enablecolumns']['endtime']];
|
||||
}
|
||||
|
||||
return $document;
|
||||
@@ -255,37 +254,37 @@ class Builder
|
||||
/**
|
||||
* Adds the access field to the document if needed.
|
||||
*
|
||||
* @param Document $document
|
||||
* @param array $document
|
||||
* @param Rootline $pageAccessRootline
|
||||
*/
|
||||
protected function addAccessField(Document $document, Rootline $pageAccessRootline)
|
||||
protected function addAccessField(array &$document, Rootline $pageAccessRootline)
|
||||
{
|
||||
$access = (string)$pageAccessRootline;
|
||||
if (trim($access) !== '') {
|
||||
$document->setField('access', $access);
|
||||
$document['access'] = $access;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the endtime field value to the Document.
|
||||
*
|
||||
* @param Document $document
|
||||
* @param array $document
|
||||
* @param array $pageRecord
|
||||
*/
|
||||
protected function addEndtimeField(Document $document, $pageRecord)
|
||||
protected function addEndtimeField(array &$document, $pageRecord)
|
||||
{
|
||||
if ($pageRecord['endtime']) {
|
||||
$document->setField('endtime', $pageRecord['endtime']);
|
||||
$document['endtime'] = $pageRecord['endtime'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds keywords, multi valued.
|
||||
*
|
||||
* @param Document $document
|
||||
* @param array $document
|
||||
* @param array $pageRecord
|
||||
*/
|
||||
protected function addKeywordsField(Document $document, $pageRecord)
|
||||
protected function addKeywordsField(array &$document, $pageRecord)
|
||||
{
|
||||
if (!isset($pageRecord['keywords'])) {
|
||||
return;
|
||||
@@ -293,20 +292,20 @@ class Builder
|
||||
|
||||
$keywords = array_unique(GeneralUtility::trimExplode(',', $pageRecord['keywords'], true));
|
||||
foreach ($keywords as $keyword) {
|
||||
$document->addField('keywords', $keyword);
|
||||
$document['keywords'] = $keyword;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add content from several tags like headers, anchors, ...
|
||||
*
|
||||
* @param Document $document
|
||||
* @param array $document
|
||||
* @param array $tagContent
|
||||
*/
|
||||
protected function addTagContentFields(Document $document, $tagContent = [])
|
||||
protected function addTagContentFields(array &$document, $tagContent = [])
|
||||
{
|
||||
foreach ($tagContent as $fieldName => $fieldValue) {
|
||||
$document->setField($fieldName, $fieldValue);
|
||||
$document[$fieldName] = $fieldValue;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\Domain\Search\ApacheMeilisearchDocument;
|
||||
namespace WapplerSystems\Meilisearch\Domain\Search\MeilisearchDocument;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\Domain\Search\Query;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2010-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 Solarium\QueryType\Extract\Query as SolariumExtractQuery;
|
||||
|
||||
/**
|
||||
* Specialized query for content extraction using Meilisearch Cell
|
||||
*
|
||||
*/
|
||||
class ExtractingQuery extends SolariumExtractQuery
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $file Absolute path to the file to extract content and meta data from.
|
||||
*/
|
||||
public function __construct($file)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->setFile($file);
|
||||
$this->addParam('extractFormat', 'text');
|
||||
}
|
||||
|
||||
}
|
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\Domain\Search\Query;
|
||||
|
||||
/***************************************************************
|
||||
* 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 Solarium\QueryType\Select\Query\Query as SolariumQuery;
|
||||
|
||||
class Query extends SolariumQuery {
|
||||
|
||||
/**
|
||||
* Returns the query parameters that should be used.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getQueryParameters() {
|
||||
return $this->getParams();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getQuery();
|
||||
}
|
||||
}
|
@@ -62,7 +62,7 @@ class DefaultResultParser extends AbstractResultParser {
|
||||
}
|
||||
|
||||
foreach ($documents as $searchResult) {
|
||||
$searchResultObject = $this->searchResultBuilder->fromApacheMeilisearchDocument($searchResult);
|
||||
$searchResultObject = $this->searchResultBuilder->fromMeilisearchDocument($searchResult);
|
||||
$searchResults[] = $searchResultObject;
|
||||
}
|
||||
|
||||
|
@@ -42,7 +42,7 @@ class SearchResultBuilder {
|
||||
* @throws \InvalidArgumentException
|
||||
* @return SearchResult
|
||||
*/
|
||||
public function fromApacheMeilisearchDocument(Document $originalDocument)
|
||||
public function fromMeilisearchDocument(Document $originalDocument)
|
||||
{
|
||||
|
||||
$searchResultClassName = $this->getResultClassName();
|
||||
|
@@ -431,7 +431,7 @@ class SearchResultSetService
|
||||
throw new \UnexpectedValueException("Response did not contain a valid Document object");
|
||||
}
|
||||
|
||||
return $this->searchResultBuilder->fromApacheMeilisearchDocument($resultDocument);
|
||||
return $this->searchResultBuilder->fromMeilisearchDocument($resultDocument);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user