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

    - Could you give me your site page character set (UTF-8 ?) and your $database_connection_charset variable defined in your config file (utf8 ?)

    That was it! My $database_connection_charset variable was not set. The interesting thing is that it was not set on my home machine either and it worked. The hosting server is running version: 4.1.22 MySQL and my home computer I am running version: 5.0.41


    <script type="text/javascript">
    <!--
    as_opacity = ’1’;
    stripHtml = 1;
    stripSnip = 1;
    stripSnippets = 1;
    useAllWords = 0;
    searchStyle = ’partial’;
    minChars = 4;
    maxResults = 6;
    showMoreResults = 0;
    moreResultsPage = 0;
    as_language = ’english’;
    extract = 1;
    liveSearch = 0;
    docgrp = ’’;
    highlightResult = 1;
    listIDs = ’17,15,18,16,32,31,30’;
    -->
    </script>

    mb_internal_encoding() was returning ISO-8859-1

    the error was on line 90 of AjaxSearch.php -- "if ($needsConvert) $result = mb_convert_encoding($result,"UTF-8",$pgEncoding);"
      DropboxUploader -- Upload files to a Dropbox account.
      DIG -- Dynamic Image Generator
      gus -- Google URL Shortener
      makeQR -- Uses google chart api to make QR codes.
      MODxTweeter -- Update your twitter status on publish.
      • 5811
      • 1,717 Posts
      Hi Bwente,

      That was it! My $database_connection_charset variable was not set. The interesting thing is that it was not set on my home machine either and it worked.
      The hosting server is running version: 4.1.22 MySQL and my home computer I am running version: 5.0.41

      the error was on line 90 of AjaxSearch.php -- "if ($needsConvert) $result = mb_convert_encoding($result,"UTF-8",$pgEncoding);"


      Please download this fix. A new version of AjaxSearch.php file and tell me what are the results.

      I have improved the code to check the value of database_connection_charset.
      Now if the $database_connection_charset is unset or null you should get an error message.
        • 25663 MODX Staff
        • 12,272 Posts
        Hello coroico,

        Got this in from an email over night and it’s a good catch if it’s not already been addressed:

        Dear authors of AjaxSearch.

        Some of the users of MODx CMS that I manage try to put html code
        within the longtitle field sometimes (even if I tell them that it’s
        bad idea). When AjaxSearch returns results, it places the longtitle
        field within an attribute:

        <a href= ... title="[+longtitle+]"> ...

        This breaks the webpage. Is there a way to incorporate a php
        strip_tags into the template so that if they do, it wont break the
        results page? (This goes for any other attributes within the template
        that incorporate document/template variables too.)

        For the moment I have simply removed the title attribute from the ’a’
        element in the template altogether.

        Thanks,

        Paul
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 30552
          • 75 Posts
          AjaxSearch works fine for me most of the time, however, I just noticed that it fails if I do a search while logged in as a web user.

          Not logged in, everything works, but when logged in as any web user, I get the following javascript error:

          "The URI to be decoded is not a valid encoding"

          I know this refers to line 140 of AjaxSearch.js, but beyond that, I don’t know what’s wrong, because I don’t know how the URI changes between when someone is logged in and when someone is not logged in. Anyone run into this issue, or have any ideas about how to resolve it?

          Thanks!

          *edit*

          I did some very light debugging (keep in mind, I don’t know anything abotu javascript), and I found that this is being generated, and thus causing the "The URI to be decoded is not a valid encoding" error:

          Cannot query the database (SELECT DISTINCT sc.id, sc.pagetitle, sc.description, sc.content, sc.introtext, sc.longtitle FROM `modx_site_content` sc LEFT JOIN `modx_site_tmplvar_contentvalues` stc ON sc.id = stc.contentid LEFT JOIN `modx_document_groups` dg ON sc.id = dg.document WHERE ((sc.pagetitle LIKE ’%client%’ OR sc.description LIKE ’%client%’ OR sc.content LIKE ’%client%’ OR sc.introtext LIKE ’%client%’ OR stc.value LIKE ’%client%’)) AND (ISNULL(dg.document_group) OR dg.document_group IN (2%2C6%2C7%2C8%2C9%2C10%2C11%2C12%2C13%2C14%2C15%2C16%2C17%2C18%2C19%2C20%2C21%2C22%2C23%2C24%2C25%2C26%2C27%2C28)) AND sc.published = 1 AND sc.searchable=1 AND sc.deleted=0;)

          This doesn’t actually help me any, but I thought it might help someone here to know how to fix this problem. Thanks!
            • 5811
            • 1,717 Posts
            Hello,

            1/ Could you give me the list of the document groups allowed for the web user ?

            The query seems a little strange : dg.document_group IN (2%2C6%2C7%2C8%2C9%2C10%2C11%2C12%2C13%2C14%2C15%2C16%2C17%2C18%2C19%2C20%2C21%2C22%2C23%2C24%2C25%2C26%2C27%2C28))

            2/ And look at the page source code (right button of your browser) and catch the init of the value docgrp. You should find something like :

            <script type="text/javascript">
            <!--
            as_opacity = ’0.8’;
            stripHtml = 1;
            ...
            docgrp = ’’;
            highlightResult = 1;
            listIDs = ’1,3,4,5,6,28,47,32,33,48,8,9,2,35,41,42’;
            -->
            </script>

            And in the AjaxSearch.js file could you add the temporary following line:
            	alert("docgrp="+docgrp);
            just before the code block (near the line 133):
              var ajaxSearchReq = new Ajax('index-ajax.php', {postBody: pars, onComplete: doSearchResponse});

            3/ What is the output of the alert message ?

            4/ Which version of AjaxSearch do you use it ?
              • 5811
              • 1,717 Posts
              Hello again,

              I confirm your bug !
              On my site I add 2 document groups and I do a test. So i get :
              1/
              	<script type="text/javascript">
              		<!--
              		as_opacity = '1';
               		stripHtml = 1;
              ...
              		docgrp = '2,3';
              		highlightResult = 1;
              		listIDs = '22,29,26,27,21,34,24,25,13,12,38,36,37,10,20,19,18,17,11,35';
              		-->
              	</script>

              Where 2 and 3 are the IDs of my two document groups.
              2/ The Alert window give me "docgrp=2,3
              3/ I catch the SQL statement in the doSearch Function of AjaxSearch.inc.php (directory include) and i get :
              SELECT DISTINCT sc.id, sc.pagetitle, sc.description, sc.content, sc.introtext, sc.longtitle FROM `modx_site_content` sc LEFT JOIN `modx_site_tmplvar_contentvalues` stc ON sc.id = stc.contentid LEFT JOIN `modx_document_groups` dg ON sc.id = dg.document WHERE ((sc.pagetitle LIKE '%chine%' OR sc.description LIKE '%chine%' OR sc.content LIKE '%chine%' OR sc.introtext LIKE '%chine%' OR stc.value LIKE '%chine%')) AND sc.id IN (22,29,26,27,21,34,24,25,13,12,38,36,37,10,20,19,18,17,11,35) AND  (ISNULL(dg.document_group) OR dg.document_group IN (2%2C3)) AND sc.published = 1 AND sc.searchable=1 AND sc.deleted=0;


              When i run this sql statement under phpMyAdmin (as a single request) i get :
              Erreur
              
              requête SQL: Documentation
              
              SELECT DISTINCT sc.id, sc.pagetitle, sc.description, sc.content, sc.introtext, sc.longtitle
              FROM `modx_site_content` sc
              LEFT JOIN `modx_site_tmplvar_contentvalues` stc ON sc.id = stc.contentid
              LEFT JOIN `modx_document_groups` dg ON sc.id = dg.document
              WHERE (
              (
              sc.pagetitle LIKE '%chine%'
              OR sc.description LIKE '%chine%'
              OR sc.content LIKE '%chine%'
              OR sc.introtext LIKE '%chine%'
              OR stc.value LIKE '%chine%'
              )
              )
              AND sc.id
              IN ( 22, 29, 26, 27, 21, 34, 24, 25, 13, 12, 38, 36, 37, 10, 20, 19, 18, 17, 11, 35 )
              AND (
              ISNULL( dg.document_group )
              OR dg.document_group
              IN ( 2 % 2C3 )
              )
              AND sc.published =1
              AND sc.searchable =1
              AND sc.deleted =0
              LIMIT 0 , 30
              
              MySQL a répondu:Documentation
              #1054 - Unknown column '2C3' in 'where clause' 


              So you are right, the docgrp option doesn’t work once we have two or more document groups !!!
              I do the same test with only one. It’s ok.

              docgrp: escape(docgrp),
              in AjaxSearch.js (near line 128) is the reason of these parasit characters like ’2C3’
              Replace this line by
              		docgrp: docgrp,
              and it will run correctly grin

              The reason is probably that the escape function works only for ISO-8859-1 not with UTF-8 encoding.

              I will look at the javascript documentation to know which is the best function instead of escape() : encodeURI() or encodeURIComponent(). But first let me know if it is ok for you.
                • 30552
                • 75 Posts
                It is okay for me! Thanks so much for your help! It now works perfectly.
                  • 5811
                  • 1,717 Posts
                  Since Javascript 1.5 the function escape() is unsuitable and replaced by encodeURI().
                  So find attached a new version of the ajaxSearch.js file. This new AjaxSearch-fix162d will be taken into account of the next release of the AjaxSearch version. For the moment, to correct this issue, simply overwrite the ajaxSearch.js file.

                  Transeffect, thanks for this feedback. Each new fix improve the next release smiley
                    • 7231
                    • 4,205 Posts
                    I have the same issue but since I don’t use the ajax part of AjaxSerach the javascript changes did not make a difference.
                      [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                      Something is happening here, but you don&#39;t know what it is.
                      Do you, Mr. Jones? - [bob dylan]
                      • 30441
                      • 10 Posts
                      Hi,

                      I have some problems with multiword-searches where the different parts stored in different TVs. Is there a switch I can set to find them too?

                      by the way a featurerequest: To give the value of a selected TV back in the return-array. Bild this by myself, but is an urgly hack. Would be nice to see it in the releaseversion.

                      cu
                      Toranaga

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