first commit
This commit is contained in:
@@ -16,7 +16,7 @@ namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\OptionBased\
|
||||
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\AbstractFacetParser;
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
|
||||
use WapplerSystems\Meilisearch\System\Solr\ParsingUtil;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\ParsingUtil;
|
||||
|
||||
/**
|
||||
* Class HierarchyFacetParser
|
||||
@@ -34,9 +34,9 @@ class HierarchyFacetParser extends AbstractFacetParser
|
||||
$response = $resultSet->getResponse();
|
||||
$fieldName = $facetConfiguration['field'];
|
||||
$label = $this->getPlainLabelOrApplyCObject($facetConfiguration);
|
||||
$optionsFromSolrResponse = isset($response->facet_counts->facet_fields->{$fieldName}) ? ParsingUtil::getMapArrayFromFlatArray($response->facet_counts->facet_fields->{$fieldName}) : [];
|
||||
$optionsFromMeilisearchResponse = isset($response->facet_counts->facet_fields->{$fieldName}) ? ParsingUtil::getMapArrayFromFlatArray($response->facet_counts->facet_fields->{$fieldName}) : [];
|
||||
$optionsFromRequest = $this->getActiveFacetValuesFromRequest($resultSet, $facetName);
|
||||
$hasOptionsInResponse = !empty($optionsFromSolrResponse);
|
||||
$hasOptionsInResponse = !empty($optionsFromMeilisearchResponse);
|
||||
$hasSelectedOptionsInRequest = count($optionsFromRequest) > 0;
|
||||
$hasNoOptionsToShow = !$hasOptionsInResponse && !$hasSelectedOptionsInRequest;
|
||||
$hideEmpty = !$resultSet->getUsedSearchRequest()->getContextTypoScriptConfiguration()->getSearchFacetingShowEmptyFacetsByName($facetName);
|
||||
@@ -53,7 +53,7 @@ class HierarchyFacetParser extends AbstractFacetParser
|
||||
|
||||
$facet->setIsAvailable($hasOptionsInResponse);
|
||||
|
||||
$nodesToCreate = $this->getMergedFacetValueFromSearchRequestAndSolrResponse($optionsFromSolrResponse, $optionsFromRequest);
|
||||
$nodesToCreate = $this->getMergedFacetValueFromSearchRequestAndMeilisearchResponse($optionsFromMeilisearchResponse, $optionsFromRequest);
|
||||
|
||||
if ($this->facetOptionsMustBeResorted($facetConfiguration)) {
|
||||
$nodesToCreate = $this->sortFacetOptionsInNaturalOrder($nodesToCreate);
|
||||
@@ -96,13 +96,13 @@ class HierarchyFacetParser extends AbstractFacetParser
|
||||
/**
|
||||
* Checks if options must be resorted.
|
||||
*
|
||||
* Apache Solr facet.sort can be set globally or per facet.
|
||||
* Meilisearch facet.sort can be set globally or per facet.
|
||||
* Relevant TypoScript paths:
|
||||
* plugin.tx_meilisearch.search.faceting.sortBy causes facet.sort Apache Solr parameter
|
||||
* plugin.tx_meilisearch.search.faceting.sortBy causes facet.sort Meilisearch parameter
|
||||
* plugin.tx_meilisearch.search.faceting.facets.[facetName].sortBy causes f.<fieldname>.facet.sort parameter
|
||||
*
|
||||
* see: https://lucene.apache.org/solr/guide/6_6/faceting.html#Faceting-Thefacet.sortParameter
|
||||
* see: https://wiki.apache.org/solr/SimpleFacetParameters#facet.sort : "This parameter can be specified on a per field basis."
|
||||
* see: https://lucene.apache.org/meilisearch/guide/6_6/faceting.html#Faceting-Thefacet.sortParameter
|
||||
* see: https://wiki.apache.org/meilisearch/SimpleFacetParameters#facet.sort : "This parameter can be specified on a per field basis."
|
||||
*
|
||||
* @param array $facetConfiguration
|
||||
* @return bool
|
||||
|
@@ -29,7 +29,7 @@ class HierarchyTool
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces @@@slash@@@ with \/ to have the path usable for solr again.
|
||||
* Replaces @@@slash@@@ with \/ to have the path usable for meilisearch again.
|
||||
*
|
||||
* @param string $pathWithReplacedContentSlashes
|
||||
* @return string
|
||||
|
@@ -27,7 +27,7 @@ namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\OptionBased\
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\FacetUrlDecoderInterface;
|
||||
|
||||
/**
|
||||
* Filter encoder to build Solr hierarchy queries from tx_meilisearch[filter]
|
||||
* Filter encoder to build Meilisearch hierarchy queries from tx_meilisearch[filter]
|
||||
*
|
||||
* @author Ingo Renner <ingo@typo3.org>
|
||||
*/
|
||||
@@ -42,11 +42,11 @@ class HierarchyUrlDecoder implements FacetUrlDecoderInterface
|
||||
const DELIMITER = '/';
|
||||
|
||||
/**
|
||||
* Parses the given hierarchy filter and returns a Solr filter query.
|
||||
* Parses the given hierarchy filter and returns a Meilisearch filter query.
|
||||
*
|
||||
* @param string $hierarchy The hierarchy filter query.
|
||||
* @param array $configuration Facet configuration
|
||||
* @return string Lucene query language filter to be used for querying Solr
|
||||
* @return string Lucene query language filter to be used for querying Meilisearch
|
||||
*/
|
||||
public function decode($hierarchy, array $configuration = [])
|
||||
{
|
||||
|
@@ -16,7 +16,7 @@ namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\OptionBased\
|
||||
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\AbstractFacetParser;
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
|
||||
use WapplerSystems\Meilisearch\System\Solr\ResponseAdapter;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
|
||||
|
||||
@@ -49,10 +49,10 @@ class OptionsFacetParser extends AbstractFacetParser
|
||||
$response = $resultSet->getResponse();
|
||||
$fieldName = $facetConfiguration['field'];
|
||||
$label = $this->getPlainLabelOrApplyCObject($facetConfiguration);
|
||||
$optionsFromSolrResponse = $this->getOptionsFromSolrResponse($facetName, $response);
|
||||
$metricsFromSolrResponse = $this->getMetricsFromSolrResponse($facetName, $response);
|
||||
$optionsFromMeilisearchResponse = $this->getOptionsFromMeilisearchResponse($facetName, $response);
|
||||
$metricsFromMeilisearchResponse = $this->getMetricsFromMeilisearchResponse($facetName, $response);
|
||||
$optionsFromRequest = $this->getActiveFacetValuesFromRequest($resultSet, $facetName);
|
||||
$hasOptionsInResponse = !empty($optionsFromSolrResponse);
|
||||
$hasOptionsInResponse = !empty($optionsFromMeilisearchResponse);
|
||||
$hasSelectedOptionsInRequest = count($optionsFromRequest) > 0;
|
||||
$hasNoOptionsToShow = !$hasOptionsInResponse && !$hasSelectedOptionsInRequest;
|
||||
$hideEmpty = !$resultSet->getUsedSearchRequest()->getContextTypoScriptConfiguration()->getSearchFacetingShowEmptyFacetsByName($facetName);
|
||||
@@ -75,7 +75,7 @@ class OptionsFacetParser extends AbstractFacetParser
|
||||
$facet->setIsUsed($hasActiveOptions);
|
||||
$facet->setIsAvailable($hasOptionsInResponse);
|
||||
|
||||
$optionsToCreate = $this->getMergedFacetValueFromSearchRequestAndSolrResponse($optionsFromSolrResponse, $optionsFromRequest);
|
||||
$optionsToCreate = $this->getMergedFacetValueFromSearchRequestAndMeilisearchResponse($optionsFromMeilisearchResponse, $optionsFromRequest);
|
||||
foreach ($optionsToCreate as $optionsValue => $count) {
|
||||
if ($this->getIsExcludedFacetValue($optionsValue, $facetConfiguration)) {
|
||||
continue;
|
||||
@@ -83,11 +83,11 @@ class OptionsFacetParser extends AbstractFacetParser
|
||||
|
||||
$isOptionsActive = in_array($optionsValue, $optionsFromRequest);
|
||||
$label = $this->getLabelFromRenderingInstructions($optionsValue, $count, $facetName, $facetConfiguration);
|
||||
$facet->addOption($this->objectManager->get(Option::class, $facet, $label, $optionsValue, $count, $isOptionsActive, $metricsFromSolrResponse[$optionsValue]));
|
||||
$facet->addOption($this->objectManager->get(Option::class, $facet, $label, $optionsValue, $count, $isOptionsActive, $metricsFromMeilisearchResponse[$optionsValue]));
|
||||
}
|
||||
|
||||
// after all options have been created we apply a manualSortOrder if configured
|
||||
// the sortBy (lex,..) is done by the solr server and triggered by the query, therefore it does not
|
||||
// the sortBy (lex,..) is done by the meilisearch server and triggered by the query, therefore it does not
|
||||
// need to be handled in the frontend.
|
||||
$this->applyManualSortOrder($facet, $facetConfiguration);
|
||||
$this->applyReverseOrder($facet, $facetConfiguration);
|
||||
@@ -104,20 +104,20 @@ class OptionsFacetParser extends AbstractFacetParser
|
||||
* @param ResponseAdapter $response
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptionsFromSolrResponse($facetName, ResponseAdapter $response)
|
||||
protected function getOptionsFromMeilisearchResponse($facetName, ResponseAdapter $response)
|
||||
{
|
||||
$optionsFromSolrResponse = [];
|
||||
$optionsFromMeilisearchResponse = [];
|
||||
if (!isset($response->facets->{$facetName})) {
|
||||
return $optionsFromSolrResponse;
|
||||
return $optionsFromMeilisearchResponse;
|
||||
}
|
||||
|
||||
foreach ($response->facets->{$facetName}->buckets as $bucket) {
|
||||
$optionValue = $bucket->val;
|
||||
$optionCount = $bucket->count;
|
||||
$optionsFromSolrResponse[$optionValue] = $optionCount;
|
||||
$optionsFromMeilisearchResponse[$optionValue] = $optionCount;
|
||||
}
|
||||
|
||||
return $optionsFromSolrResponse;
|
||||
return $optionsFromMeilisearchResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,9 +125,9 @@ class OptionsFacetParser extends AbstractFacetParser
|
||||
* @param ResponseAdapter $response
|
||||
* @return array
|
||||
*/
|
||||
protected function getMetricsFromSolrResponse($facetName, ResponseAdapter $response)
|
||||
protected function getMetricsFromMeilisearchResponse($facetName, ResponseAdapter $response)
|
||||
{
|
||||
$metricsFromSolrResponse = [];
|
||||
$metricsFromMeilisearchResponse = [];
|
||||
|
||||
if (!isset($response->facets->{$facetName}->buckets)) {
|
||||
return [];
|
||||
@@ -138,11 +138,11 @@ class OptionsFacetParser extends AbstractFacetParser
|
||||
foreach ($bucketVariables as $key => $value) {
|
||||
if (strpos($key, 'metrics_') === 0) {
|
||||
$metricsKey = str_replace('metrics_', '', $key);
|
||||
$metricsFromSolrResponse[$bucket->val][$metricsKey] = $value;
|
||||
$metricsFromMeilisearchResponse[$bucket->val][$metricsKey] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $metricsFromSolrResponse;
|
||||
return $metricsFromMeilisearchResponse;
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ namespace WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\OptionBased\
|
||||
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\AbstractFacetParser;
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
|
||||
use WapplerSystems\Meilisearch\System\Solr\ResponseAdapter;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter;
|
||||
|
||||
/**
|
||||
* Class QueryGroupFacetParser
|
||||
@@ -86,7 +86,7 @@ class QueryGroupFacetParser extends AbstractFacetParser
|
||||
|
||||
|
||||
// after all options have been created we apply a manualSortOrder if configured
|
||||
// the sortBy (lex,..) is done by the solr server and triggered by the query, therefore it does not
|
||||
// the sortBy (lex,..) is done by the meilisearch server and triggered by the query, therefore it does not
|
||||
// need to be handled in the frontend.
|
||||
$this->applyManualSortOrder($facet, $facetConfiguration);
|
||||
$this->applyReverseOrder($facet, $facetConfiguration);
|
||||
@@ -112,7 +112,7 @@ class QueryGroupFacetParser extends AbstractFacetParser
|
||||
|
||||
// todo: add test cases to check if this is needed https://forge.typo3.org/issues/45440
|
||||
// remove tags from the facet.query response, for facet.field
|
||||
// and facet.range Solr does that on its own automatically
|
||||
// and facet.range Meilisearch does that on its own automatically
|
||||
$rawValue = preg_replace('/^\{!ex=[^\}]*\}(.*)/', '\\1', $rawValue);
|
||||
|
||||
list($field, $query) = explode(':', $rawValue, 2);
|
||||
|
Reference in New Issue
Block a user