I have created several tags, e.g. “Führung” and “eigene Gesprächsführung”. If I filter for “Führung”, the results for “eigene Gesprächsführung” are also displayed.
Where can I set that only exact words or word pairs are filtered?
Target page:
[[!getResourcesTag:default=`<div class="uk-width-1-1"><p><strong>Leider keine Seminare mit dieser Auswahl vorhanden!<strong></p></div>`?
&tpl=`tplSeminare22`
&sortby=`menuindex`
&sortdir=`ASC`
&sortdirTV=`ASC`
&limit=`99999`
&parents=`[[*id]]`
&includeContent=`1`
&includeTVs=`1`
&showHidden=`1`
&processTVs=`1`
&tvPrefix=``
&tagKey=`tags`
]]
ModX 2.8.3
PHP 7.4
bruno17
January 24, 2022, 4:27pm
#2
I think getResourcesTag searches with LIKE:%tag% within the TV values
maybe better use the Tagger Extra
There is a property tagSearchType
. If you set that to 'exact'
it should only return exact matches.
$tagSearchType = $modx->getOption('tagSearchType',$scriptProperties,'exact');
if ($tagSearchType == 'contains') {
$scriptProperties['tvFilters'] = $tagKey.'==%'.$tag.'%';
} else if ($tagSearchType == 'beginswith') {
$scriptProperties['tvFilters'] = $tagKey.'==%'.$tag.'';
} else if ($tagSearchType == 'endswith') {
$scriptProperties['tvFilters'] = $tagKey.'=='.$tag.'%';
} else if ($tagSearchType == 'within') {
$scriptProperties['tvFilters'] = $tagKey.'(IN)'.$tag.'';
} else {
$scriptProperties['tvFilters'] = $tagKey.'=='.$tag.'';
}
This does not work if there is more than one tag to an item.
bruno17
January 24, 2022, 7:09pm
#5
Like said, using Tagger will solve that issue
You’re correct.
The way tagLister saves the data in the database (as a comma-separated string) makes it hard to query.
As Bruno said, you should use Tagger instead.
If you really need to use tagLister , then you have to change the snippet getResourcesTag
and write your own subquery.
This may (or may not) work. (If your TV has a default value, this won’t work.)
Duplicate the snippet “getResourcesTag”
Change these lines to something like this:
$mywhere = array("EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tv.id = tvr.tmplvarid WHERE tv.name = '" . $tagKey . "' AND tvr.contentid = modResource.id AND FIND_IN_SET('" . $tag . "',tvr.value) > 0)");
$scriptProperties['where'] = $modx->toJson($mywhere);
halftrainedharry:
$mywhere = array("EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tv.id = tvr.tmplvarid WHERE tv.name = '" . $tagKey . "' AND tvr.contentid = modResource.id AND FIND_IN_SET('" . $tag . "',tvr.value) > 0)");
$scriptProperties['where'] = $modx->toJson($mywhere);
Thank you, this work for me!
I will use Tagger for future projects.