[TYPO3-Solr] Problem with cross domain links

Jigal van Hemert jigal.van.hemert at typo3.org
Tue Mar 29 17:00:16 CEST 2016


Hi,

On 29/03/2016 12:06, Stefan Stuck wrote:
> How do I get EXT:solr to add the appropriate domain record to each
> search result link?

The problem is that when the scheduler task is executed by the cron job 
the $_SERVER variables that are used by TYPO3 to determine the URL and 
domain are not present (domain cannot be calculated correctly). Also the 
dispatch script is mostly called from the root of the filesystem (the 
entire path in the filesystem is used for absolute URLs)

There seem to be two ways.

1. Use the information stored in the solr index

In the field 'site' the domain (without protocol) is already stored for 
each document.
In the search.results.fieldRenderingInstructions you can use that to 
build an absolute link.

For pages you can build a link based on the uid in the 
fieldRenderingInstructions. The search results are rendered in Frontend 
context and thus the correct absolute URL can be calculated (provided 
you enabled config.typolinkEnableLinksAcrossDomains)

plugin.tx_solr.search.results.fieldRenderingInstructions.url {
   pages = TEXT
   pages {
     typolink {
       parameter.field = uid
       returnLast = url
       forceAbsoluteUrl = 1
     }
   }
   default = TEXT
   default {
     field = url
     dataWrap = http://{field:site}/|
     htmlSpecialChars = 1
     htmlSpecialChars.preserveEntities = 1
   }
   [.. and for other types ..]
}

[.. use something identical for the fieldRenderingInstructions of the 
link ..]

The disadvantage is that there is extra processing while rendering the 
results and that you can either use http or https (or you must store the 
desired protocol in a field too).

2. provide the information to the server during indexing

Lienhart Woitok reported that using a special line for the cronjob will 
run it from the document root of the site and set the host name: (example)

[ -f /var/www/foo/typo3/cli_dispatch.phpsh ] && cd /var/www/foo && 
HTTP_HOST=www.example.com /usr/bin/php5 typo3/cli_dispatch.phpsh scheduler

(haven't tried this myself and possibly problematic with multi-domain 
installations)

-- 
Jigal van Hemert
TYPO3 CMS Active Contributor

TYPO3 .... inspiring people to share!
Get involved: typo3.org


More information about the TYPO3-project-solr mailing list