We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5811
    • 1,717 Posts
    A version 1.7.0.2 of ajaxSearch has been delivered in the repository. See http://modxcms.com/forums/index.php/topic,22843.0.html for the changes.
      • 30562
      • 99 Posts
      Hi corocico!
      Sorry, but there is version 1.7.0. AS in a repository ( http://modxcms.com/AjaxSearch-490.html ).
      Under your link ( http://modxcms.com/forums/index.php/topic,22843.0.html ) the message stands out:
      An Error Has Occurred!
      The topic or board you are looking for appears to be either missing or off limits to you.
      Where can I find 1.7.0.2 ?
        • 30562
        • 99 Posts
        All is OK. It is written 1.7 in the name ( http://modxcms.com/AjaxSearch-490.html ).
        But it is inside contains 1.7.0.2. I will look.
          • 30562
          • 99 Posts
          In a plugin plugin.searchHighlight.tpl it is done following changes.
          Before line 62:
          foreach ($searchArray as $word) {

          we insert
          usort ($searchArray, "cmp");

          Before line 40:
          if (isset ($ _GET [' searched ']) && isset ($ _GET [' highlight '])) {

          we insert
          function cmp($a, $b) {
              if (mb_strlen($a) == mb_strlen($b)) {
                  return 0;
              }
              return (mb_strlen($a) < mb_strlen($b)) ? 1 : -1;
          }

          I use UTF-8 coding on the site. Works as well function "strlen".

          We receive the partial decision of a highlighting problem what about I spoke on the previous page. Short terms are imposed on longer terms. It i s ugly, but it works.
          Look picture.
            • 30562
            • 99 Posts
            And here so the initial order of terms in inquiry will be kept. The full text of the plugin which works for me.
            /*
              ------------------------------------------------------------------------
              Plugin: Search_Highlight v1.2.0.1
              ------------------------------------------------------------------------
              Changes:
              10/02/08 - Strip_tags added to avoid sql injection and XSS
              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
              ------------------------------------------------------------------------
            */
            
            function cmp($a, $b) {
                if (mb_strlen($a) == mb_strlen($b)) {
                    return 0;
                }
                return (mb_strlen($a) < mb_strlen($b)) ? 1 : -1;
            }
            
            if(isset($_GET['searched']) && isset($_GET['highlight'])) {
            
              // Set these to customize the text for the highlighting key
              // --------------------------------------------------------
                 $termText = '<div class="searchTerms">Запрос: ';
                 $removeText = 'Отменить подсветку';
              // --------------------------------------------------------
            
              $highlightText = $termText;
            
              $searched = strip_tags(urldecode($_GET['searched']));
              $highlight = strip_tags(urldecode($_GET['highlight']));
              $output = $modx->documentOutput; // get the parsed document
            
              $body = explode("<!--highlight-->", $output); // break out the head
            
              $searchArray = explode(' ', $searched); // break apart the search terms
            
              $highlightClass = explode(' ',$highlight); // break out the highlight classes
            
              $j = 0; // store initial order of terms
              $initOrder = array();
              foreach($searchArray as $word) {
                $j++;
                $initOrder[$word] = $j;
                $class = $highlightClass[0].' '.$highlightClass[$j];
                $highlightText .= ($j > 1) ? ', ' : '';
                $highlightText .= '<span class="'.$class.'">'.$word.'</span>';
              }
            
              // sorting of terms according to decrease of their length
              usort($searchArray, "cmp");
            
              $i = 0; // for individual class names
            
              foreach($searchArray as $word) {
                $i++;
                $j = $initOrder[$word];
                $class = $highlightClass[0].' '.$highlightClass[$j];
            
                $pattern = '/' . preg_quote($word) . '(?=[^>]*<)/iu';
                $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;
            }
              • 30562
              • 99 Posts
              Here is one more improvement in search inquiry.
              It cuts signs on a punctuation from search terms.

              In the module ajaxSearch.inc.php before line (around a line 100)
                      $cleansedWords. = $word. ' ';

              it is necessary to insert
                      //to remove a punctuation
                      $word = ereg_replace ("[[:blank:] [:punct:]] +", "", $word);
                • 30562
                • 99 Posts
                It is my last sentence on improvement of convenience of search. This offer limits quantity of searched terms. Because the inquiry can appear very long when we restore string of searched terms by means of copy-paste. On the other hand, the long string of searched terms can destroy page make-up.

                In ajaxSearch.inc.php beginning the following code is inserted:

                define (MAX_TERMS, '10'); 


                Further, since string around number 100 it is brought in a cycle "foreach" following corrections:
                    $maxCount = 0;
                    foreach($searchWords as $word){
                      if ($word != '' &&
                          !in_array(strtolower($word),$snippetNameArray) &&
                            ((!$useAllWords) && (strlen($word) >= $minChars) ||
                            ($searchStyle == 'partial') && (strlen($word) >= $minChars) ||
                            (strlen($word) >= $minChars && $useAllWords && $searchStyle == 'relevance'))
                         ){
                        // to remove a punctuation
                        $word = ereg_replace("[[:blank:][:punct:]]+", "", $word);
                
                        $cleansedWords .= $word.' ';
                        $maxCount++;
                      }
                      if ($maxCount == MAX_TERMS) break;
                    }

                As a result the quantity of required terms will be limited by constant MAX_TERMS. Everyone will set it on the taste.
                  • 5811
                  • 1,717 Posts
                  Hi Traveller
                  Incorrect highlighting of results

                  Shortly. The superfluous is highlighted. The necessary is not highlighted.

                  At first to highlight the terms having the big length. At the subsequent highlightings of shorter terms it is necessary to check, whether they enter in longer already highlighted. If yes, highlighting of short words to cancel.
                  AjaxSearch runs as "partial" search which means that when you search for example china wall, you search the first extract which contains "china" and then the first extract which contains "wall". Not the extract "china wall". And you will get the same extract with "china" highligthed and a second one (the same) with "wall" highligthed.
                  To get "china wall" the "relevant" mode using the MYSQL LIKE mechanism is probably a better way to implement this kind of search. But It doesn’t run for the moment. Look at the dosearch function in includes/ajaxSearch.inc.php to understand my thoughts.

                  Othewise I have improved the extract mechanism of ajaxSearch with a better extract algorithm (without cutting of words and merging of words which are near in the text) but I prefer delivered this algoritm in a beta 1.8 version in order to get lot of feedbacks, rather to include this algoritm in the version 1.7 which is planned to be included in the incoming MODX 1.6.2. Once I have finished, i will publish this beta version and get your improvements but for the moment I would like stabilize the 1.7 version. In the same way, I am open to include improvements made by you and akots regarding the Russian language. But all these improvements need testing and testing before a large delivery wink
                    • 30562
                    • 99 Posts
                    Quote from: coroico at Feb 18, 2008, 08:07 AM

                    AjaxSearch runs as "partial" search which means that when you search for example china wall, you search the first extract which contains "china" and then the first extract which contains "wall". Not the extract "china wall". And you will get the same extract with "china" highligthed and a second one (the same) with "wall" highligthed...
                    I perfectly understand what about you speak. But on my site I do a little in another way.

                    To the ordinary user it is difficult, and it is not necessary to explain, that means "partial", and that such "relevant" search on a site. Stemmer (i.e. heuristic algorithm) allows to make more powerful search on the basis of existing one "AS 1.7" today.
                    I mean, certainly, Russian. The ordinary user can not think about at input. He (she) enters some full words with suffixes and the terminations. He (she) enters words how he (she) represents them to himself. Then stemmer itself will cut off words to their basis.

                    And the highlighting of result of search finished in appropriate way will output various word forms. It is the separate and simple task. imho.

                    As a result the search engine reminds "relevant" semantic one (with the dictionary). But it is MUCH LIGHTWEIGHT and FAST.

                    Good luck!
                      • 30562
                      • 99 Posts
                      There is one more very serious idea.

                      This idea is not applied in search on modern sites widely, as far as I know. It is characteristic for heavier search engine.

                      It is necessary to enter one more parameter into search - DISTANCE BETWEEN REQUIRED TERMS - for very qualitative relevant search.
                      Agree, that words "china" and "wall" within the limits of one paragraph and the same words "china" in top of page and "wall" in page ending are absolutely different two results of search.

                      But it is already other theme...

                      This discussion is closed to further replies. Keep calm and carry on.