We have a TYPO3 project and use SOLR as search engine. I'm wondering how does an if-statement/conditional look like in the config files written in TypoScript?
TYPO3: 8.7 Apache Solr for TYPO3 - ES: 7.5.3
for example: we use
plugin.tx_solr.search.query.sortBy = data_datax_title_stringS asc
as sort setting for the following facet block:
plugin.tx_solr.search.faceting.facets {
but we only want that sorting if a certain part of the url query string is empty (q= or q=Searchtext)
so the sortBy should be applied if the query string looks like
http://localhost/?tx_solr%5Bq%5D=&L=0&id=2883
and should not be applied on
http://localhost/?tx_solr%5Bq%5D=Searchtext&L=0&id=2883
here is the actual block:
[globalVar = TSFE:id={$site.config.search_page_blasts}]
plugin.tx_solr.search.targetPage = {$site.config.search_page_blasts}
config.defaultGetVars {
tx_solr.filter.0 = result_type_filter:blast
}
plugin.tx_solr.search.query.sortBy = dynamic_field_A_stringS asc
plugin.tx_solr.search.faceting.facets {
facetX < lib.solr.facets.directBlast
facetX.field = dynamic_field_X_boolS
}
Any help is highly appreciated.
edit: I found
plugin.tx_solr.search.query.getParameter = q
but this only defines the name for the query get-parameter in case another service needs a specific name. But I would need the value of this parameter and condition the sortBy by its value.
edit:
after some research I'm now at this state: the sort works if a query string is set - but not if its empty
[globalVar = GP:q = ""]
plugin.tx_solr.search.query.sortBy = wine_winery_title_stringS asc
[else]
plugin.tx_solr.search.query.sortBy =
[end]
[globalVar = TSFE:id={$site.config.search_page_wineries}]
plugin.tx_solr.search.targetPage = {$site.config.search_page_wineries}
config.defaultGetVars {
tx_solr.filter.0 = result_type_filter:winery
}
plugin.tx_solr.search.faceting.facets {
direct_sale < lib.solr.facets.directSale
direct_sale.field = winery_direct_sale_boolS
I don't really know how to format this the right way - nested conditions are not supported right?
I ended up extending the outer condition and just having two blocks for that page - it feels redundant but works perfectly fine. The condition outside of the existing one was not working - and nested conditions were not possible.
So here is the solution:
With globalString
to use regex for comparison
[globalVar = TSFE:id={$site.config.search_page_x}] && [globalString = GP:tx_solr|q = /.+/]
And globalVar
for an empty parameter
[globalVar = TSFE:id={$site.config.search_page_x}] && [globalVar = GP:tx_solr|q =]
Hope I can save someone a little time researching - thanks to everyone for their input.