We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    Well then, it’s easy enough...
    $thisText = isset($thisText) ? $thisText : 'defalult for this text';
    $thatText = isset($thatText) ? $thatText : 'default for that text';
    

    fix it all up, post it, and maybe it’ll get incorporated into the main version!

    Even better, set it up to use variables (or constants) from a language file, and check for $lang from the snippet call and include the lang file or the default if none is specified in the snippet call.
    $lang = isset($lang) ? $lang : 'default_lang';
    include $path .'/lang/'.$lang.'.php';
    $thisText = $ajaxsearchLang['thisText'];
    $thatText = $ajaxsearchLang['thatText'];
    
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 23050
      • 1,842 Posts
      Very nice snippet ! wink Thanks for it

      To pass W3C validation, you should replace & with & on lines 485 and 535 with
      - &AS_offset
      - &AS_search
      - &searched
      - &highlight



      Idea : add a parameter to choose how many characters to display in extracts

      It seems that Ajax Search doesn’t search into summary doc. Is it possible to add this possibility (with a parameter or changing the code ) ?



      I’m going to see if I can prevent TinyMCE from changing é into é for example. So that I won’t see anymore a &eac in extract which doesn’t mean anything. But, how can I make Ajax Search to display é when I search e.
      For example, I search economique and I would like to get a result économique ?

      Thanks again for your help wink
        • 21000
        • 11 Posts
        Hi,

        TinyMCE replace the accent with the html entity... So, when you put the word "Genève" on a page, it is recorded as "Genève" in the database and AjaxSearch can’t find "Genève"... A big problem for french sites. Is it a solution?

        Thanks!
          • 23050
          • 1,842 Posts
          Quote from: nathan- at Nov 21, 2006, 03:11 PM

          TinyMCE replace the accent with the html entity... So, when you put the word "Genève" on a page, it is recorded as "Genève" in the database and AjaxSearch can’t find "Genève"... A big problem for french sites. Is it a solution?

          The solution would be to delete html entity function in TinyMCE... I wanted to look at this today, but I didn’t add time :/
            • 23050
            • 1,842 Posts
            Quote from: Perrine at Nov 20, 2006, 02:39 PM

            It seems that Ajax Search doesn’t search into summary doc. Is it possible to add this possibility (with a parameter or changing the code ) ?

            I was talking about introtext... not summary which is the term used in Ditto only wink

            For those who want to search in introtext, here are the changes I made :

            Open assets/snippets/AjaxSearch/AjaxSearch.inc.php

            Around line 138
            Replace
            $sql = "SELECT DISTINCT sc.id, sc.pagetitle, sc.description, sc.content ";

            with
            $sql = "SELECT DISTINCT sc.id, sc.pagetitle, sc.description, sc.introtext, sc.content ";


            Around line 142
            Replace
            $sql .= "(sc.pagetitle LIKE '%$searchString%' OR sc.description LIKE '%$searchString%' OR sc.content LIKE '%$searchTerm%') AND ";

            with
            $sql .= "(sc.pagetitle LIKE '%$searchString%' OR sc.introtext LIKE '%$searchString%' OR sc.description LIKE '%$searchString%' OR sc.content LIKE '%$searchTerm%') AND ";


            Around line 145
            Replace
            $sql .= "(sc.pagetitle LIKE '%$searchString%' OR sc.description LIKE '%$searchString%' OR sc.content LIKE '%$searchString%') AND ";

            with
            $sql .= "(sc.pagetitle LIKE '%$searchString%' OR sc.introtext LIKE '%$searchString%' OR sc.description LIKE '%$searchString%' OR sc.content LIKE '%$searchString%') AND ";


            Around line 149
            Replace
            $sql = "SELECT DISTINCT sc.id, sc.pagetitle, sc.description, sc.content ";

            with
            $sql = "SELECT DISTINCT sc.id, sc.pagetitle, sc.description, sc.introtext, sc.content ";
            
              • 23050
              • 1,842 Posts
              Quote from: nathan- at Nov 21, 2006, 03:11 PM

              TinyMCE replace the accent with the html entity... So, when you put the word "Genève" on a page, it is recorded as "Genève" in the database and AjaxSearch can’t find "Genève"... A big problem for french sites. Is it a solution?

              Thanks to Jeff, it’s now possible to not change characters with accents into html entitites.
              The only thing you need to do is :

              1- go to tinyMCE configuration tab
              2- Select raw for entity encoding
              3- save

              And you’re done !
              You should review all your previous document to save them again, in order tinyMCE replaces html entities wink
                • 21000
                • 11 Posts
                Thanks! ...worked for me!

                just replace:
                $tinymce_entity_encoding = isset($entity_encoding) ? $entity_encoding :"";

                by:
                $tinymce_entity_encoding = "raw";

                In:
                Ressources -> Plugins -> TinyMCE
                  • 23072
                  • 150 Posts
                  I haven’t seen this discussed elsewhere in this topic, but searching for more than one word returns no results whatsoever. Also, and this may just be on my install, I can do searches for words of less than 4 characters (which I thought was prevented in the snippet code?).

                  Any ideas how to get both of these things working?

                  Also, could this snippet support situations such as searching for "bottle OR bubble" and "bottle AND bubble"? I presume it’s already supposed to be able to take comma separated values such as "bottle, bubble" which is the first problem I’m having.

                  Other than that, the snippet is working excellently. I skipped the whole AJAX part, put a search form at the top of my page and had it show results on my specially created search page (loving the search highlighting too! wink).
                    Notanotherdotcom Ltd

                    Web | Print | Marketing
                    • 19522
                    • 17 Posts
                    For me it returns a hit if I my term is "times square" and I have a document containing for example "On Times Square the great ..." but no hit in "The square root of two times ..."
                      • 19522
                      • 17 Posts
                      *** EDIT: Please see the optimization two posts down ***
                      Replacing line 145 in AjaxSearch.inc.php (modx ver 0.95)
                      [tt]
                      $sql .= "(sc.pagetitle LIKE ’%$searchString%’ OR sc.description LIKE ’%$searchString%’ OR sc.content LIKE ’%$searchString%’) AND ";
                      [/tt]
                      with
                      [tt]
                      $sql .= "(";
                      foreach ($search as $searchTerm){
                      $sql .= "(sc.pagetitle LIKE ’%$searchString%’ OR sc.description LIKE ’%$searchString%’ OR sc.content LIKE ’%$searchTerm%’) OR ";
                      }
                      $sql = preg_replace(’/ OR \z/’, ’) AND ’, $sql);
                      [/tt]
                      makes AjaxSearch behave like I expect it to using the default ’partial’ searchStyle. using $useAllWords=true returns pages containing _all_ the terms like before, but using $useAllWords=false (the default) now returns pages with _any_ of the terms where using $useAllWords=false would only return pages containing the exact frase before. Not quite what I expected epsacially considering the comments in the file.
                      I guess it makes sense to only match titles and descriptions containing the exact frase in both cases.

                      Another thing. Returning hits on pages containing words like ’I’ or ’a’ is not what I want, so I added a check for $minChar to have it affect ’partial’ mode as well. I changed line 98-99 to:
                      ** Edit: code updated **
                      [tt]
                      ((!$useAllWords) && (strlen($word) >= $minChars) ||
                      ($searchStyle == ’partial’) && (strlen($word) >= $minChars)
                      [/tt]
                      Apart from those (in my opinion) small glitches I think AjaxSearch is great.

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