Commit 76ec6bb6 authored by Thomas Löffler's avatar Thomas Löffler
Browse files

Add facets to solr search and remove upper pagination

parent 273b617e
Pipeline #10337 passed with stages
in 4 minutes and 39 seconds
<?php
namespace T3o\T3orgLayout\Slot;
class SolrSlot
{
public function addResultsWithoutFacets(array $values): array
{
if ($values['resultSet']->getUsedQuery()) {
$filterQueries = $values['resultSet']->getUsedQuery()->getFilterQueries();
unset($filterQueries['type']);
$values['resultSet']->getUsedQuery()->setFilterQueries($filterQueries);
$allValuesFoundWithoutFacet = (int)$values['resultSet']->getUsedSearch()
->search($values['resultSet']->getUsedQuery())
->getParsedData()->response->numFound;
$values['allResultCountWithoutFacets'] = $values['resultSet']->getAllResultCount();
if ($allValuesFoundWithoutFacet > 0) {
$values['allResultCountWithoutFacets'] = $allValuesFoundWithoutFacet;
}
}
return [$values];
}
}
......@@ -3,11 +3,9 @@ plugin.tx_solr {
templateRootPaths {
10 = EXT:t3org_layout/Resources/Private/Templates/Solr
}
partialRootPaths {
10 = EXT:t3org_layout/Resources/Private/Partials/Solr
}
layoutRootPaths {
10 = EXT:t3org_layout/Resources/Private/Layouts/Solr
}
......@@ -25,6 +23,38 @@ plugin.tx_solr {
}
boostQuery = (type:tx_sfeventmgt_domain_model_event)^200
}
faceting >
faceting = 1
faceting {
keepAllFacetsOnSelection = 1
facets {
type {
field = type
label = Type
partialName = Tabs
renderingInstruction = CASE
renderingInstruction {
key.field = optionValue
pages = TEXT
pages {
value = Pages
}
tx_news_domain_model_news = TEXT
tx_news_domain_model_news {
value = News
}
tx_sfeventmgt_domain_model_event = TEXT
tx_sfeventmgt_domain_model_event {
value = Events
}
}
}
}
}
}
index {
......
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:f="http://typo3.org/ns/TYPO3/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true"
>
<f:for each="{facet.options}" as="option" iteration="iteration">
<li class="nav-item">
<a class="facet solr-ajaxified nav-link{f:if(condition:option.selected,then: ' active')}" href="{s:uri.facet.setFacetItem(facet: facet, facetItem: option)}">{option.label}
<span>({option.documentCount})</span>
</a>
</li>
</f:for>
</html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:f="http://typo3.org/ns/TYPO3/Fluid/ViewHelpers"
xmlns:s="http://typo3.org/ns/ApacheSolrForTypo3/Solr/ViewHelpers">
<f:section name="Facets">
<s:facet.area.group groupName="main" facets="{resultSet.facets.available}">
<f:for each="{areaFacets}" as="facet">
<f:render partial="Facets/{facet.partialName}" arguments="{resultSet:resultSet, facet:facet}" />
</f:for>
</s:facet.area.group>
</f:section>
......@@ -49,8 +49,32 @@
</f:if>
<f:if condition="{resultSet.hasSearched}">
<s:widget.resultPaginate resultSet="{resultSet}" configuration="{templatePath:'EXT:t3org_layout/Resources/Private/Templates/ViewHelpers/Widget/ResultPaginate/Index.html'}">
<ol start="{pagination.displayRangeStart}" class="results-list">
<div class="container search-filter mb-4">
<div class="row">
<div class="col-12">
<f:variable name="facetUsed" value="0" />
<f:for each="{resultSet.facets}" as="facet">
<f:if condition="{facet.isUsed}">
<f:variable name="facetUsed" value="1" />
</f:if>
</f:for>
<ul class="nav nav-tabs">
<li class="nav-item">
<a href="{s:uri.facet.removeAllFacets()}" class="nav-link{f:if(condition:'{facetUsed}', else:' active')}"">
All
<span>({allResultCountWithoutFacets})</span>
</a>
</li>
<f:if condition="{resultSet.hasSearched}">
<f:if condition="{resultSet.usedSearchRequest.contextTypoScriptConfiguration.searchFaceting}">
<f:render partial="Result/Facets" section="Facets" arguments="{resultSet:resultSet}" />
</f:if>
</f:if>
</ul>
</div>
</div>
<s:widget.resultPaginate resultSet="{resultSet}" configuration="{insertAbove: 0, templatePath:'EXT:t3org_layout/Resources/Private/Templates/ViewHelpers/Widget/ResultPaginate/Index.html'}">
<ol start="{pagination.displayRangeStart}" class="results-list">
<f:for each="{documents}" as="document">
<f:render partial="Result/Document" section="Document" arguments="{resultSet:resultSet, document:document}" />
</f:for>
......
......@@ -14,3 +14,12 @@ $GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['SolrSuggest'] = \T3o\T3orgLayo
$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['classes']['Domain/Model/News'][] = 't3org_layout';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['t3org_layout'] = \T3o\T3orgLayout\Hook\DataHandlerHook::class;
// Solr slot
$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
$signalSlotDispatcher->connect(
\ApacheSolrForTypo3\Solr\Controller\SearchController::class,
'resultsAction',
\T3o\T3orgLayout\Slot\SolrSlot::class,
'addResultsWithoutFacets'
);
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