TYPO3-Solr / ext-solr

A TYPO3 extension that integrates the Apache Solr search server with TYPO3 CMS. dkd Internet Service GmbH is developing the extension. Community contributions are welcome. See CONTRIBUTING.md for details.
GNU General Public License v3.0
137 stars 252 forks source link

[FEATURE] Add option to completely remove query-string from SearchRequest #4135

Closed rr-it closed 3 weeks ago

rr-it commented 3 months ago

Is your feature request related to a problem? Please describe. Removing the query-string from a SearchRequest might be used to keep e.g. the category selections while not limiting the result by a search query string anymore.

In solr v11.2 it was possible to completely remove the query-string from a SearchRequest by setting it to null.

E.g. using a custom ViewHelper:

class RemoveQueryViewHelper extends AbstractUriViewHelper
{

    /**
     * @param array $arguments
     * @param \Closure $renderChildrenClosure
     * @param RenderingContextInterface $renderingContext
     * @return string
     */
    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
    {
        $newRequest = static::getUsedSearchRequestFromRenderingContext($renderingContext)
            ->getCopyForSubRequest()
            ->setRawQueryString(null);
        $uri = self::getSearchUriBuilder($renderingContext)->getCurrentSearchUri($newRequest);
        return $uri;
    }
}

Introduced in solr v11.5 by https://github.com/TYPO3-Solr/ext-solr/commit/61076e3ed99ba2c4b9f17d44c2e50f278218780d the method SearchRequest::setRawQueryString(string $rawQueryString = '') enforces a string. Thereby it is no longer possible to set the query-string to null.

https://github.com/TYPO3-Solr/ext-solr/blob/dfcdd98bbbac58678cdb9bb0e07eef28329c6556/Classes/Domain/Search/SearchRequest.php#L436-L439

Describe the solution you'd like Introduce a new method that removes the query-string from SearchRequest.

Describe alternatives you've considered Alternative A: Allow null as argument for the method:

    public function setRawQueryString(string|null $rawQueryString = ''): SearchRequest

Alternative B: Set query string to empty string …->setRawQueryString(''):

But this will result in an unnecessary empty query-string in the url: https://example.com/search/?tx_solr[filter][0]=altType%3ASomeCategory&tx_solr[q]=

Additional context Completely removing the SearchRequest is afaik only usefull with allowEmptyQuery set in TS-config:

plugin.tx_solr {
  search {
    query {
      allowEmptyQuery = 1
    }
}

Target versions