Commit f2404db8 authored by Thomas Löffler's avatar Thomas Löffler

Build search suggest

parent 90e7970c
Pipeline #8905 failed with stages
in 46 seconds
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "31e66d49bf64e5ff423c3bb0c0979100",
"content-hash": "6118a648e180b6e22c4701a0041526d9",
"packages": [
{
"name": "adoy/fastcgi-client",
......@@ -45,29 +45,30 @@
},
{
"name": "apache-solr-for-typo3/solr",
"version": "dev-master",
"version": "11.0.1",
"source": {
"type": "git",
"url": "https://github.com/TYPO3-Solr/ext-solr.git",
"reference": "e50b6af7afdf6241f933f3437ac293cb46196b80"
"reference": "9ed695e4430b21b788bcbf3a04bc73663f54f47a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/TYPO3-Solr/ext-solr/zipball/e50b6af7afdf6241f933f3437ac293cb46196b80",
"reference": "e50b6af7afdf6241f933f3437ac293cb46196b80",
"url": "https://api.github.com/repos/TYPO3-Solr/ext-solr/zipball/9ed695e4430b21b788bcbf3a04bc73663f54f47a",
"reference": "9ed695e4430b21b788bcbf3a04bc73663f54f47a",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": ">=7.2.0",
"solarium/solarium": "~4.2.0",
"typo3/cms-backend": "^9.5.0 || ^10.0",
"typo3/cms-core": "^9.5.0 || ^10.0",
"typo3/cms-extbase": "^9.5.0 || ^10.0",
"typo3/cms-fluid": "^9.5.0 || ^10.0",
"typo3/cms-frontend": "^9.5.0 || ^10.0",
"typo3/cms-reports": "^9.5.0 || ^10.0",
"typo3/cms-scheduler": "^9.5.0 || ^10.0",
"typo3/cms-tstemplate": "^9.5.0 || ^10.0"
"typo3/cms-backend": "^9.5.16 || ^10.4.0",
"typo3/cms-core": "^9.5.16 || ^10.4.0",
"typo3/cms-extbase": "^9.5.16 || ^10.4.0",
"typo3/cms-fluid": "^9.5.16 || ^10.4.0",
"typo3/cms-frontend": "^9.5.16 || ^10.4.0",
"typo3/cms-reports": "^9.5.16 || ^10.4.0",
"typo3/cms-scheduler": "^9.5.16 || ^10.4.0",
"typo3/cms-tstemplate": "^9.5.16 || ^10.4.0"
},
"replace": {
"apache-solr-for-typo3/solrfluid": "*",
......@@ -80,7 +81,7 @@
"type": "typo3-cms-extension",
"extra": {
"branch-alias": {
"dev-master": "10.0.x-dev"
"dev-master": "11.0.x-dev"
},
"typo3/cms": {
"extension-key": "solr",
......@@ -115,7 +116,13 @@
"solr",
"typo3"
],
"time": "2020-04-22T05:14:38+00:00"
"funding": [
{
"url": "https://www.typo3-solr.com/",
"type": "custom"
}
],
"time": "2020-05-08T10:39:45+00:00"
},
{
"name": "causal/ig_ldap_sso_auth",
......@@ -4743,16 +4750,16 @@
},
{
"name": "typo3/class-alias-loader",
"version": "v1.1.1",
"version": "v1.1.2",
"source": {
"type": "git",
"url": "https://github.com/TYPO3/class-alias-loader.git",
"reference": "ee417366a289871460910ae1703976e9903a5e80"
"reference": "ead04a4d7bc215ca1faa895977c5ea349f0b7383"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/TYPO3/class-alias-loader/zipball/ee417366a289871460910ae1703976e9903a5e80",
"reference": "ee417366a289871460910ae1703976e9903a5e80",
"url": "https://api.github.com/repos/TYPO3/class-alias-loader/zipball/ead04a4d7bc215ca1faa895977c5ea349f0b7383",
"reference": "ead04a4d7bc215ca1faa895977c5ea349f0b7383",
"shasum": ""
},
"require": {
......@@ -4797,7 +4804,7 @@
"classloader",
"composer"
],
"time": "2020-04-30T10:13:10+00:00"
"time": "2020-05-07T12:46:20+00:00"
},
{
"name": "typo3/cms-backend",
......@@ -5006,16 +5013,16 @@
},
{
"name": "typo3/cms-composer-installers",
"version": "v3.0.0",
"version": "v3.0.1",
"source": {
"type": "git",
"url": "https://github.com/TYPO3/CmsComposerInstallers.git",
"reference": "814917daedd65ee98334e7528e1a6f845f542db6"
"reference": "cde93ec5dbfb115e4d47c5f9b6d8822adeeac290"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/TYPO3/CmsComposerInstallers/zipball/814917daedd65ee98334e7528e1a6f845f542db6",
"reference": "814917daedd65ee98334e7528e1a6f845f542db6",
"url": "https://api.github.com/repos/TYPO3/CmsComposerInstallers/zipball/cde93ec5dbfb115e4d47c5f9b6d8822adeeac290",
"reference": "cde93ec5dbfb115e4d47c5f9b6d8822adeeac290",
"shasum": ""
},
"require": {
......@@ -5069,7 +5076,7 @@
"installer",
"typo3"
],
"time": "2020-04-27T13:09:34+00:00"
"time": "2020-05-04T18:03:13+00:00"
},
{
"name": "typo3/cms-core",
......@@ -6877,7 +6884,6 @@
"aliases": [],
"minimum-stability": "dev",
"stability-flags": {
"apache-solr-for-typo3/solr": 20,
"t3o/t3org_layout": 20
},
"prefer-stable": true,
......
<?php
namespace T3o\T3orgLayout\Middleware;
/*
* This file is part of a TYPO3 extension.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use ApacheSolrForTypo3\Solr\ConnectionManager;
use ApacheSolrForTypo3\Solr\Domain\Search\Query\QueryBuilder;
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Result\SearchResultBuilder;
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetService;
use ApacheSolrForTypo3\Solr\Domain\Search\SearchRequestBuilder;
use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException;
use ApacheSolrForTypo3\Solr\Search;
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class SolrSearch implements MiddlewareInterface
{
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$response = $handler->handle($request);
if (!isset($request->getQueryParams()['ajaxsearch'], $request->getQueryParams()['q'])) {
return $response;
}
if ($request->getQueryParams()['type']) {
$GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['search.']['query.']['filter.']['typeFilter'] = 'type:' . $request->getQueryParams()['type'];
}
$typoscriptConfiguration = GeneralUtility::makeInstance(
TypoScriptConfiguration::class,
$GLOBALS['TSFE']->tmpl->setup,
$request->getAttribute('site')->getRootpageId()
);
$searchRequestBuilder = new SearchRequestBuilder($typoscriptConfiguration);
$queryParams = $request->getQueryParams();
$queryParams['q'] .= '*';
$searchRequest = $searchRequestBuilder->buildForSearch(
$queryParams,
$request->getAttribute('site')->getRootpageId(),
$request->getAttribute('language')->getLanguageId()
);
try {
$solrConnection = GeneralUtility::makeInstance(ConnectionManager::class)->getConnectionByPageId(
$request->getAttribute('site')->getRootpageId(),
$request->getAttribute('language')->getLanguageId()
);
$search = GeneralUtility::makeInstance(Search::class, $solrConnection);
} catch (NoSolrConnectionFoundException $e) {
$response->getBody()->write('No Solr connection available.');
return $response;
}
$searchResultSetService = GeneralUtility::makeInstance(SearchResultSetService::class, $typoscriptConfiguration, $search);
$searchResultSetService->injectObjectManager(GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class));
$searchResultSet = $searchResultSetService->search($searchRequest);
if ($request->getQueryParams()['ajaxsearch'] === 'raw') {
$results = [];
foreach ($searchResultSet->getSearchResults()->getArrayCopy() as $result) {
/** @var \ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\Result\SearchResult $result */
$results[] = $result->getFields();
}
return new JsonResponse($results);
}
$template = GeneralUtility::makeInstance(\TYPO3\CMS\Fluid\View\StandaloneView::class);
$template->setTemplatePathAndFilename('EXT:t3org_layout/Resources/Private/Templates/Solr/SolrResults.html');
$template->assign('documents', $searchResultSet->getSearchResults()->getArrayCopy());
return new HtmlResponse($template->render());
}
}
......@@ -7,6 +7,12 @@ return [
'before' => [
'typo3/cms-frontend/timetracker'
]
],
't3org-search' => [
'target' => \T3o\T3orgLayout\Middleware\SolrSearch::class,
'after' => [
'typo3/cms-frontend/prepare-tsfe-rendering'
]
]
]
];
......@@ -133,3 +133,5 @@ plugin.tx_solr {
}
}
}
page.includeJSFooter.search = EXT:t3org_layout/Resources/Public/JavaScript/search.js
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:render section="{documents.0.type}" arguments="{_all}" />
<f:section name="pages">
<h5>Pages</h5>
</f:section>
<f:section name="tx_news_domain_model_news">
<h5>News</h5>
<f:for each="{documents}" as="document">
<div class="media mb-3">
<div class="media-body">
<h5 class="mb-0">{document.title}</h5>
{document.content -> f:format.raw() -> f:format.crop(maxCharacters:"30", respectWordBoundaries:"true", respectHtml:"true", append:"..." )}
</div>
</div>
</f:for>
</f:section>
<f:section name="tx_sfeventmgt_domain_model_event">
<h5>Events</h5>
<f:for each="{documents}" as="document">
<div class="media">
<div class="media-body">
<h5 class="mt-0">{document.title}</h5>
{document.content -> f:format.raw() -> f:format.crop(maxCharacters:"30", respectWordBoundaries:"true", respectHtml:"true", append:"..." )}
</div>
</div>
</f:for>
</f:section>
</html>
$(document).ready(function () {
$('.js__full-width-dropdown__search').html('<div class="mt-4 mb-4 row"><div class="col-md-4 results-list-insert-pages"></div><div class="col-md-4 results-list-insert-news"></div><div class="col-md-4 results-list-insert-events"></div></div>')
let _searchPages = null;
let _searchNews = null;
let _searchEvents = null;
$(".js__main-nav__solr-form_input").keyup(function (e) {
var search = $(this).val();
if (search.length > 2) {
if (_searchPages) {
_searchPages.abort();
}
if (_searchNews) {
_searchNews.abort();
}
if (_searchEvents) {
_searchEvents.abort();
}
$('.main-nav__solr-form').submit()
} else {
if (_searchPages) {
_searchPages.abort();
}
if (_searchNews) {
_searchNews.abort();
}
if (_searchEvents) {
_searchEvents.abort();
}
('.results-list-insert-pages').html('');
('.results-list-insert-news').html('');
('.results-list-insert-events').html('');
}
});
$('.main-nav__solr-form').on('submit', function (e) {
e.preventDefault();
_searchPages = $.ajax(
{
type: "GET",
url: "/",
data: {
"q": $(this).find(".js__main-nav__solr-form_input").val(),
"ajaxsearch": 1,
"type": "pages"
},
success: function (response) {
$('.results-list-insert-pages').html(response);
}
}
)
_searchNews = $.ajax(
{
type: "GET",
url: "/",
data: {
"q": $(this).find(".js__main-nav__solr-form_input").val(),
"ajaxsearch": 1,
"type": "tx_news_domain_model_news"
},
success: function (response) {
$('.results-list-insert-news').html(response);
}
}
)
_searchEvents = $.ajax(
{
type: "GET",
url: "/",
data: {
"q": $(this).find(".js__main-nav__solr-form_input").val(),
"ajaxsearch": 1,
"type": "tx_sfeventmgt_domain_model_event"
},
success: function (response) {
$('.results-list-insert-events').html(response);
}
}
)
});
//
// $('.js__main-nav__solr-form_input').typeahead({
// minLength: 2,
// group: true,
// maxItem: 5,
// maxItemPerGroup: 5,
// hint: true,
// dynamic: true,
// delay: 500,
// searchOnFocus: true,
// // cache: true,
// emptyTemplate: 'No result for "{{query}}"',
// // mustSelectItem: true,
// href: '{{link}}',
// selector: {
// list: 'typeahead__list list-unstyled',
// cancelButton: 'typeahead__search-icon fas fa-times'
// },
// source: {
// pages: {
// display: ['title', 'abstract'],
// template: `
// <div class="media">
// <i class="far fa-2x fa-file-alt d-flex mr-4" aria-hidden="true"></i>
// <div class="media-body">
// <h5 class="mt-0">{{title}}</h5>
// <p>{{abstract}}</p>
// </div>
// </div>
// `,
// ajax: {
// url: '/typo3conf/ext/t3olayout/Resources/Public/JavaScript/searchResultsNews.json'
// }
// },
// news: {
// display: ['title', 'abstract'],
// template: `
// <div class="media">
// <img class="img-fluid d-flex mr-4" src="{{image}}" />
// <div class="media-body">
// <span>{{date}}</span>
// <h5 class="mt-0">{{title}}</h5>
// <p>{{abstract}}</p>
// </div>
// </div>
// `,
// ajax: {
// url: '/?ajaxsearch=raw&q={{query}}&type=tx_news_domain_model_news'
// }
// },
// events: {
// display: ['title', 'abstract'],
// template: `
// <div class="media">
// <img class="img-fluid d-flex mr-4" src="{{image}}" />
// <div class="media-body">
// <span>{{date}}</span>
// <h5 class="mt-0">{{title}}</h5>
// <p>{{abstract}}</p>
// </div>
// <div class="d-flex ml-5">
// <a class="btn btn-secondary btn-lg" href="{{signUpLink}}">Sigh up</a>
// </div>
// </div>
// `,
// ajax: {
// url: '/?ajaxsearch=raw&q={{query}}&type=tx_sfeventmgt_domain_model_event'
// }
// }
// },
// resultContainer: $('.js__full-width-dropdown__search'),
// callback: {
// onClickBefore: function (node, a, item, event) {
// event.preventDefault;
// window.location.href = item.href;
// window.location.reload(true);
// }
// },
// });
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment