We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10190
    • 187 Posts
    Hi,

    is there a placeholder without the highlight parameters even if highlighting is enabled in the snippet call?

    I’d like to give the user two links in the search results, one showing the longtitle pointing to as.resultLink (this is with highlight params),

    and one showing the URL of the document found but without highlight params.

    How could this be achieved?

    Cheers
    Frisco
      • 5811
      • 1,717 Posts
      To get this do as follow:

      1/ add a new placeholder named [+as.resultLink2+] in the result template:
        <a class="[+as.resultLinkClass+]" href="[+as.resultLink+]" title="[+as.longtitle+]">[+as.pagetitle+]</a>
        <a class="[+as.resultLinkClass+]" href="[+as.resultLink2+]" title="[+as.longtitle+]">[+as.pagetitle+]</a>


      2/ change the lines #179-180 of class/ajaxSearch.class.inc.php
                  // set result link as PHx
                  $this->setResultLink($this->searchResults[$i]);

      by:
                  // set result link as PHx
                  $this->setResultLink($this->searchResults[$i],'');
                  $this->setResultLink($this->searchResults[$i],'2');


      And replace the lines #1522-1538 of class/search.class.inc.php
        function setResultLink($row){
      
          global $modx;
      
          $id = $this->main['id']; 
          $hClass = $this->asClass['highlight'];
          
          if ($this->cfg['highlightResult'] && $hClass) {
            $resultLink = $modx->makeUrl($row[$id],'','searched='.urlencode($this->searchString).'&advsearch='.urlencode($this->advSearch).'&highlight='.urlencode($hClass));
          } else {
            $resultLink = $modx->makeUrl($row[$id]);
          }
      
          $this->varResult['resultClass'] = $this->asClass['prefix'];
          $this->varResult['resultLinkClass'] = $this->asClass['prefix'].'Link';
          $this->varResult['resultLink'] = $resultLink;
        }
      by
        function setResultLink($row,$mode){
      
          global $modx;
      
          $id = $this->main['id']; 
          $hClass = $this->asClass['highlight'];
          
          if (($this->cfg['highlightResult'] && $hClass) && (!$mode)) {
            $resultLink = $modx->makeUrl($row[$id],'','searched='.urlencode($this->searchString).'&advsearch='.urlencode($this->advSearch).'&highlight='.urlencode($hClass));
          } else {
            $resultLink = $modx->makeUrl($row[$id]);
          }
      
          $this->varResult['resultClass'] = $this->asClass['prefix'];
          $this->varResult['resultLinkClass'] = $this->asClass['prefix'].'Link';
          $this->varResult['resultLink'.$mode] = $resultLink;
        }


      Not tested, but the idea is here.


        • 10190
        • 187 Posts
        Wow, thanx!

        I’ll try that - the only thing I don’t like is that I’ll loose the functionality with every update.

        Could you think of another solution, maybe by a custom snippet call in the chunk to preg_replace the highlight params? Could that be made?

        Cheers
        Frisco
          • 5811
          • 1,717 Posts
          In this case use the stripOutput parameter :
          ---- &stripOutput user function (optional)
          to transform on fly the result output
          by default: defaultStripOutut

          StripOutput user function should be define in the config file as follow :

          // string functionName(string $text)
          // functionName : name of stripOutput function passed as &stripOutput parameter
          // $text : string php variable name as results
          // return the filtered results
          /*
          function myStripOutput($text){

          Any Php code which filter the results
          The following internal functions could be called:
          $text = stripTags($text); // strip all the MODx tags
          $text = stripJscript($text); // strip jscript
          $text = stripLineBreaking($text); // replace line breaking tags with whitespace
          $text = stripHtml($text); // strip all the html tags

          You could also developp you own filter based on regular expressions.
          See http://fr.php.net/manual/en/intro.pcre.php

          return $text;
          }
          */

          By default : defaultStripOutput function will be used if &stripOutput parameter
          is not set or if the function is not defined :

          function defaultStripOutput($text){

          // replace line breaking tags with whitespace
          $text = stripLineBreaking($text);
          // strip modx sensitive tags
          $text = stripTags($text);
          // strip Jscript
          $text = stripJscripts($text);
          // strip html tags. Tags should be correctly ended
          $text = stripHTML($text);

          return $text;
          }
          Define your own php function with the appropriate preg-replace.
          Catch the line between <a class="ajaxSearch_resultLink" and </a> and get the href part limited to the document id.