We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21419
    • 84 Posts
    I’m having a couple of significant issues with AjaxSearch, but the first problem I would like to solve is a problem with the links generated in the results.

    I am running AS 1.8.4 on a new MODx 1.0.2 installation. I’m running AjaxSearch in non-Ajax mode (currently). I enter my search words and submit which correctly takes me to the results page. All good, so far.

    When I click on a link from the results page, I get this error

    « MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource:
    « PHP Parse Error »
     
    PHP error debug
      Error: 	preg_replace() [function.preg-replace]: Compilation failed: lookbehind assertion is not fixed length at offset 11	 
      Error type/ Nr.: 	Warning - 2	 
      File: 	/mnt/target03/352910/354333/dev.hhiconcours.com/web/content/manager/includes/document.parser.class.inc.php(746) : eval()'d code	 
      Line: 	101	 
     
    Parser timing
      MySQL: 	0.0238 s	(42 Requests)
      PHP: 	0.1224 s	 
      Total: 	0.1462 s
    


    Every link on the results returns this.

    The link for the result is
    http://dev.hhiconcours.com/events/concours-delegance.php?searched=concours&advsearch=oneword&highlight=ajaxSearch_highlight+ajaxSearch_highlight1


    I have installed and successfully run AjaxSearch on other MODx sites before, but this is completely new. Does anyone have any ideas?
      • 5811
      • 1,717 Posts
      Look at this post : http://modxcms.com/forums/index.php/topic,37519.msg249028.html#msg249028

      Go back on the release 1.3 of SearchHighlight. This is probably the better way to solve your issue.
      Copy/paste the following code in place of the current version of SearchHiglight plugin:
      /*
        ------------------------------------------------------------------------
        Plugin: Search_Highlight v1.3
        ------------------------------------------------------------------------
        Changes:
        18/07/08 - advSearch parameter and pcre modifier added
        10/02/08 - Strip_tags added to avoid sql injection and XSS. Use of $_REQUEST 
        01/03/07 - Added fies/updates from forum from users mikkelwe/identity
        (better highlight replacement, additional div around term/removal message)
        ------------------------------------------------------------------------
        Description: When a user clicks on the link from the AjaxSearch results
          the target page will have the terms highlighted.
        ------------------------------------------------------------------------
        Created By:  Susan Ottwell ([email protected])
                     Kyle Jaebker ([email protected])
        ------------------------------------------------------------------------
        Based off the the code by Susan Ottwell (www.sottwell.com)
          http://modxcms.com/forums/index.php/topic,1237.0.html
        ------------------------------------------------------------------------
        CSS:
          The classes used for the highlighting are the same as the AjaxSearch
        ------------------------------------------------------------------------
        Notes:
          To add a link to remove the highlighting and to show the searchterms
          put the following on your page where you would like this to appear:
          
            <!--search_terms-->
          
          Example output for this:
          
            Search Terms: the, template
            Remove Highlighting
            
          Set the following variables to change the text:
          
            $termText - the text before the search terms
            $removeText - the text for the remove link
        ------------------------------------------------------------------------
      */
      
      if (isset($_REQUEST['searched']) && isset($_REQUEST['highlight'])) {
      
        // Set these to customize the text for the highlighting key
        // --------------------------------------------------------
           $termText = '<div class="searchTerms">Search Terms: ';
           $removeText = 'Remove Highlighting';
        // --------------------------------------------------------
      
        $highlightText = $termText;
      
        $searched = strip_tags(urldecode($_REQUEST['searched']));
        $highlight = strip_tags(urldecode($_REQUEST['highlight']));
      
        if (isset($_REQUEST['advsearch'])) $advsearch = strip_tags(urldecode($_REQUEST['advsearch']));
        else $advsearch = 'oneword'; 
      
        if ($advsearch != 'nowords') {
        
            $output = $modx->documentOutput; // get the parsed document
         
            $body = explode("<body>", $output); // break out the head
          
            $searchArray = array();      
            if ($advsearch == 'exactphrase') $searchArray[0] = $searched;
            else $searchArray = explode(' ', $searched);
          
            $highlightClass = explode(' ',$highlight); // break out the highlight classes
          
            $i = 0; // for individual class names
            $pcreModifier = ($database_connection_charset == 'utf8') ? 'iu' : 'i';
             
            foreach($searchArray as $word) {
              $i++;
              $class = $highlightClass[0].' '.$highlightClass[$i];
          
              $highlightText .= ($i > 1) ? ', ' : '';
              $highlightText .= '<span class="'.$class.'">'.$word.'</span>';
          
              $pattern = '/' . preg_quote($word, '/') . '(?=[^>]*<)/' . $pcreModifier;
              $replacement = '<span class="' . $class . '">${0}</span>';
              $body[1] = preg_replace($pattern, $replacement, $body[1]);
            }
          
            $output = implode("<body>", $body);
          
            $removeUrl = $modx->makeUrl($modx->documentIdentifier);
            $highlightText .= '<br /><a href="'.$removeUrl.'" class="ajaxSearch_removeHighlight">'.$removeText.'</a></div>';
          
            $output = str_replace('<!--search_terms-->',$highlightText,$output);
            $modx->documentOutput = $output;
        }
      
      }
        • 21419
        • 84 Posts
        That did it! Thanks, Coroico! Maybe this will fix some of the other problems I was having too.