Skip to content

Conversation

@straschek-io
Copy link

@straschek-io straschek-io commented May 2, 2025

What this pr does

The RelevanceCopmonent used a QueryBuilder with a differing TypoScript configuration from the original search request.

This PR tries to resolve this by using the given TypoScript within the (AfterSearchQueryHasBeenPreparedEvent).

How to test

Set a boostFonction or boostQuery within a page condition:

[page["uid"] == 22]
    plugin.tx_solr {
        search {
            query {
                boostFunction = myboostField_intS^2
...

Set an xdebug breakpoint in QueryBuilder->useBoostFunctionFromTypoScript() and analyze the boostFunction content of $searchConfiguration.

It now should be myboostField_intS^2

Fixes: #4351

@dkd-kaehm
Copy link
Collaborator

@straschek-io
Thanks for contribution.
Please see the broken tests: https://github.com/TYPO3-Solr/ext-solr/actions/runs/14794444933/job/41631278554?pr=4352

PHPStan:

Run PHPStan analysis
> phpstan analyze -c Build/Test/phpstan.neon '--no-progress'
Error: Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have a constructor and must be instantiated without any parameters.
Error: Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have a constructor and must be instantiated without any parameters.
Error: Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have a constructor and must be instantiated without any parameters.
Error: Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have a constructor and must be instantiated without any parameters.
Error: Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have a constructor and must be instantiated without any parameters.
Error: Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have a constructor and must be instantiated without any parameters.
Error: Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have a constructor and must be instantiated without any parameters.
Error: Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have a constructor and must be instantiated without any parameters.
Error: Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have a constructor and must be instantiated without any parameters.
Error: Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have a constructor and must be instantiated without any parameters.
Error: Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have a constructor and must be instantiated without any parameters.
Error: Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have a constructor and must be instantiated without any parameters.
Error: Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have a constructor and must be instantiated without any parameters.
Error: Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have a constructor and must be instantiated without any parameters.
Error: Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have a constructor and must be instantiated without any parameters.
 ------ ----------------------------------------------------------------------- 
  Line   Tests/Unit/Search/RelevanceComponentTest.php                           
 ------ ----------------------------------------------------------------------- 
  77     Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have  
         a constructor and must be instantiated without any parameters.         
  112    Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have  
         a constructor and must be instantiated without any parameters.         
  136    Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have  
         a constructor and must be instantiated without any parameters.         
  183    Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have  
         a constructor and must be instantiated without any parameters.         
  219    Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have  
         a constructor and must be instantiated without any parameters.         
  254    Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have  
         a constructor and must be instantiated without any parameters.         
  277    Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have  
         a constructor and must be instantiated without any parameters.         
  290    Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have  
         a constructor and must be instantiated without any parameters.         
  313    Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have  
         a constructor and must be instantiated without any parameters.         
  326    Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have  
         a constructor and must be instantiated without any parameters.         
  358    Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have  
         a constructor and must be instantiated without any parameters.         
  391    Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have  
         a constructor and must be instantiated without any parameters.         
  427    Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have  
         a constructor and must be instantiated without any parameters.         
  461    Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have  
         a constructor and must be instantiated without any parameters.         
  494    Class ApacheSolrForTypo3\Solr\Search\RelevanceComponent does not have  
         a constructor and must be instantiated without any parameters.         
 ------ ----------------------------------------------------------------------- 

Unit:

There were 13 errors:

1) ApacheSolrForTypo3\Solr\Tests\Unit\Search\RelevanceComponentTest::canSetQuerySlop
ArgumentCountError: Too few arguments to function ApacheSolrForTypo3\Solr\Domain\Site\SiteHashService::__construct(), 0 passed in /home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php on line 2847 and exactly 1 expected

/home/runner/work/ext-solr/ext-solr/Classes/Domain/Site/SiteHashService.php:33
/home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php:2847
/home/runner/work/ext-solr/ext-solr/Classes/Domain/Search/Query/QueryBuilder.php:67
/home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php:2847
/home/runner/work/ext-solr/ext-solr/Classes/Search/RelevanceComponent.php:35
/home/runner/work/ext-solr/ext-solr/Tests/Unit/Search/RelevanceComponentTest.php:78
/home/runner/work/ext-solr/ext-solr/.Build/bin/phpunit:122

2) ApacheSolrForTypo3\Solr\Tests\Unit\Search\RelevanceComponentTest::querySlopIsNotSetWhenPhraseIsDisabled
ArgumentCountError: Too few arguments to function ApacheSolrForTypo3\Solr\Domain\Site\SiteHashService::__construct(), 0 passed in /home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php on line 2847 and exactly 1 expected

/home/runner/work/ext-solr/ext-solr/Classes/Domain/Site/SiteHashService.php:33
/home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php:2847
/home/runner/work/ext-solr/ext-solr/Classes/Domain/Search/Query/QueryBuilder.php:67
/home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php:2847
/home/runner/work/ext-solr/ext-solr/Classes/Search/RelevanceComponent.php:35
/home/runner/work/ext-solr/ext-solr/Tests/Unit/Search/RelevanceComponentTest.php:113
/home/runner/work/ext-solr/ext-solr/.Build/bin/phpunit:122

3) ApacheSolrForTypo3\Solr\Tests\Unit\Search\RelevanceComponentTest::canSetSlop
ArgumentCountError: Too few arguments to function ApacheSolrForTypo3\Solr\Domain\Site\SiteHashService::__construct(), 0 passed in /home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php on line 2847 and exactly 1 expected

/home/runner/work/ext-solr/ext-solr/Classes/Domain/Site/SiteHashService.php:33
/home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php:2847
/home/runner/work/ext-solr/ext-solr/Classes/Domain/Search/Query/QueryBuilder.php:67
/home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php:2847
/home/runner/work/ext-solr/ext-solr/Classes/Search/RelevanceComponent.php:35
/home/runner/work/ext-solr/ext-solr/Tests/Unit/Search/RelevanceComponentTest.php:149
/home/runner/work/ext-solr/ext-solr/.Build/bin/phpunit:122

4) ApacheSolrForTypo3\Solr\Tests\Unit\Search\RelevanceComponentTest::slopIsNullWhenPhraseIsDisabled
ArgumentCountError: Too few arguments to function ApacheSolrForTypo3\Solr\Domain\Site\SiteHashService::__construct(), 0 passed in /home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php on line 2847 and exactly 1 expected

/home/runner/work/ext-solr/ext-solr/Classes/Domain/Site/SiteHashService.php:33
/home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php:2847
/home/runner/work/ext-solr/ext-solr/Classes/Domain/Search/Query/QueryBuilder.php:67
/home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php:2847
/home/runner/work/ext-solr/ext-solr/Classes/Search/RelevanceComponent.php:35
/home/runner/work/ext-solr/ext-solr/Tests/Unit/Search/RelevanceComponentTest.php:184
/home/runner/work/ext-solr/ext-solr/.Build/bin/phpunit:122

5) ApacheSolrForTypo3\Solr\Tests\Unit\Search\RelevanceComponentTest::canSetBigramPhraseSlop
ArgumentCountError: Too few arguments to function ApacheSolrForTypo3\Solr\Domain\Site\SiteHashService::__construct(), 0 passed in /home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php on line 2847 and exactly 1 expected

/home/runner/work/ext-solr/ext-solr/Classes/Domain/Site/SiteHashService.php:33

10) ApacheSolrForTypo3\Solr\Tests\Unit\Search\RelevanceComponentTest::canSetBoostQuery
ArgumentCountError: Too few arguments to function ApacheSolrForTypo3\Solr\Domain\Site\SiteHashService::__construct(), 0 passed in /home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php on line 2847 and exactly 1 expected

/home/runner/work/ext-solr/ext-solr/Classes/Domain/Site/SiteHashService.php:33
/home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php:2847
/home/runner/work/ext-solr/ext-solr/Classes/Domain/Search/Query/QueryBuilder.php:67
/home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php:2847
/home/runner/work/ext-solr/ext-solr/Classes/Search/RelevanceComponent.php:35
/home/runner/work/ext-solr/ext-solr/Tests/Unit/Search/RelevanceComponentTest.php:392
/home/runner/work/ext-solr/ext-solr/.Build/bin/phpunit:122

11) ApacheSolrForTypo3\Solr\Tests\Unit\Search\RelevanceComponentTest::canSetBoostQueries
ArgumentCountError: Too few arguments to function ApacheSolrForTypo3\Solr\Domain\Site\SiteHashService::__construct(), 0 passed in /home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php on line 2847 and exactly 1 expected

/home/runner/work/ext-solr/ext-solr/Classes/Domain/Site/SiteHashService.php:33
/home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php:2847
/home/runner/work/ext-solr/ext-solr/Classes/Domain/Search/Query/QueryBuilder.php:67
/home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php:2847
/home/runner/work/ext-solr/ext-solr/Classes/Search/RelevanceComponent.php:35
/home/runner/work/ext-solr/ext-solr/Tests/Unit/Search/RelevanceComponentTest.php:428
/home/runner/work/ext-solr/ext-solr/.Build/bin/phpunit:122

12) ApacheSolrForTypo3\Solr\Tests\Unit\Search\RelevanceComponentTest::canSetBoostFunction
ArgumentCountError: Too few arguments to function ApacheSolrForTypo3\Solr\Domain\Site\SiteHashService::__construct(), 0 passed in /home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php on line 2847 and exactly 1 expected

/home/runner/work/ext-solr/ext-solr/Classes/Domain/Site/SiteHashService.php:33
/home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php:2847
/home/runner/work/ext-solr/ext-solr/Classes/Domain/Search/Query/QueryBuilder.php:67
/home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php:2847
/home/runner/work/ext-solr/ext-solr/Classes/Search/RelevanceComponent.php:35
/home/runner/work/ext-solr/ext-solr/Tests/Unit/Search/RelevanceComponentTest.php:462
/home/runner/work/ext-solr/ext-solr/.Build/bin/phpunit:122

13) ApacheSolrForTypo3\Solr\Tests\Unit\Search\RelevanceComponentTest::canSetMinimumMatch
ArgumentCountError: Too few arguments to function ApacheSolrForTypo3\Solr\Domain\Site\SiteHashService::__construct(), 0 passed in /home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php on line 2847 and exactly 1 expected

/home/runner/work/ext-solr/ext-solr/Classes/Domain/Site/SiteHashService.php:33
/home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php:2847
/home/runner/work/ext-solr/ext-solr/Classes/Domain/Search/Query/QueryBuilder.php:67
/home/runner/work/ext-solr/ext-solr/.Build/vendor/typo3/cms-core/Classes/Utility/GeneralUtility.php:2847
/home/runner/work/ext-solr/ext-solr/Classes/Search/RelevanceComponent.php:35
/home/runner/work/ext-solr/ext-solr/Tests/Unit/Search/RelevanceComponentTest.php:495
/home/runner/work/ext-solr/ext-solr/.Build/bin/phpunit:122

ERRORS!
Tests: 933, Assertions: 2342, Errors: 13, Incomplete: 1.
Script phpunit --config=Build/Test/UnitTests.xml handling the tests:unit event returned with error code 2
Error during running the unit tests please check and fix them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Relevance component fails on evaluating TypoScript inside condition

2 participants