We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 121
    • 36 Posts
    Many thanks for the update coroico, nice work!

    I’m more of an xhtml/css man, so apologise in advance. I downloaded the 1.8 zip and followed the instructions in ajaxSearch_readme.txt. You may remember that I posted http://modxcms.com/forums/index.php/topic,26455.0.html as I wanted to display images only in the results. I also looked at the Result with images demo http://www.modx.wangba.fr/index.php?id=174 and used the snipped call on that page, but I still only get the title of the page which the image is on in the results..

    Is there something else I need to do with image.config.txt?

    Even better, is there a step by step guide on exactly what to do to get images to display in the results? I’ve looked around the wike etc, but am still stuck  >:(

    Any help would be greatly appreciated.

    Thanks in advance.

    Neil.
      • 5811
      • 1,717 Posts
      @endyser
      The &minChars doesn’t work for values smaller than 4 (like &minChars=`3`).
      It could run but I have added a check about the &minChars initialized by the user (class/ajaxSearch.class.inc line 218) :
          if ($this->cfg['minChars'] < 4) $this->cfg['minChars'] = 4;
      Here $this->cfg[’minChars’] is the value set by the user. To allow 3 characters, replace 4 by 3.
      2 characters seems to me to short to be relevant, but 3 characters, yes it could be possible. I will correct this for the release of the repository.

      Regarding the use of the parameter &tplLayout, the version_180.txt documentation is may be really not very clear
      &tplLayout by defaut is initialized with /templates/layout.tpl.html (simple search)

      These templates could be modified and use throught a chunk or a template file.
      As a chunck you need to create a chunk (for instance optionSearch) andc copy/paste (and may be adapt) one the example of tplLayout provided inside the folders :

      - simpleSearch : In tplLayout, [+as.advSearch+] is available as hidden input parameter to propagate the advSearch parameter to the landing/more results page or to the highlighting pluggin.

      - optionSearch : allow the user to choose himself the value of the advSearch parameter (oneword,allwords,exactphrase,nowords)
      on the demo site http://www.modx.wangba.fr/index.php?id=144, I use a chunk named "optionSearch"

      - multipleInputList : choose your search term from a predefined search word list (should be used in conjonction with &searchWordList parameter)

      - optionMultipleList : To combine search word list and use of &advSearch from front end
      on the demo site http://www.modx.wangba.fr/index.php?id=173a chunk named optionMultipleList is used.

      But you could also use a template file rather a chunk, in this case use : &tplLayout=`@FILE:assets/snippets/ajaxSearch180/templates/optionSearch/layout.tpl.html`


        • 5811
        • 1,717 Posts
        @4hero

        In fact, the "Results with images" demo had a typo error: &highlightResults=`0` instead of &highlightResult=`0`.
        This probably explain why you didn’t get the results.

        But let me try to explain how is set up this demo.

        The snippet call:

        [!AjaxSearch? &extract=`99` &extractLength=`120` &ajaxMax=`3` &showMoreResults=`1` &moreResultsPage=`176` &config=`image` &searchWordList=`enSearchWordList` &highlightResult=`0` &tplLayout=`optionMultipleList`!]


        &extract=`99` : means that for a document where you found a search term you allow to display a maximum of 99 extracts. I put 99 to be upper of 9 but here 9 is largely enought. By default, extract is here a concatenation of the content and tv values of document. So &extract=`99` = &extract=`99:content,tv_content`

        &extractLength=`120` : we limit the size of the extract to 120 characters

        &ajaxMax=`3` &showMoreResults=`1`&moreResultsPage=`176` : means you want a maximum of 3 results and a link "show more results" to go to the moreResultsPage (#176).

        &config=`image` : instead of use the "defaut" configuration file, you specify the use of a file named "image.config.php. This file is located into the ajaxSearch/configs folder

        &searchWordList=`enSearchWordList` : here you indicate that the list of search terms will be provided by the function "enSearchWordList". This function shoud be defined in the configuration file (image.config.php).

        &highlightResult=`0` : you don’t want highlight the results.

        The "image.configuration.php" file is the following:

        <?php
        
        $__stripOutput = 'saveImage';
        
        // StripOutput user function
        // Uncomment and complete the core function and choose your own function name
        // string functionName(string results)
        // functionName : name of stripOutput function passed as &stripOutput parameter
        // results : string php variable name as results
        // return the filtered results
        
        function saveImage($results){ 
        
          // replace line Breaking by space
          $results = stripLineBreaking($results);
          // strip other html tags
          $results = stripHtmlExceptImage($results);
          // strip javascript tags
          $results = stripJscripts($results);
          
          return $results;
        }
        
        // searchWordList user function
        // Uncomment and complete the core function and choose your own function name
        // string functionName()
        // functionName : name of searchWordList function passed as &searchWordList parameter
        // return a comma separated list of words
        
        function enSearchWordList(){ 
        
          $list = "guatemala,samassekou,equateur,cromer,zatreanu,burnett";
          return $list;
        }
        
        ?>
        
        I have kept the comments for stripOutput and searchWordList (the lines beguin by //)

        the first relevant line is:
        $__stripOutput = 'saveImage';
        that means that the default stripOutput function to use will be the "saveImage" function.
        The "saveImage" function is defined in the configuration as follow:
        function saveImage($results){ 
        
          // replace line Breaking by space
          $results = stripLineBreaking($results);
          // strip other html tags
          $results = stripHtmlExceptImage($results);
          // strip javascript tags
          $results = stripJscripts($results);
          
          return $results;
        }

        $results = stripLineBreaking($results); : first all the line breaking characters inside the results are replaced by a space character. the stripLineBreaking is provided by ajaxSearch and could be use in any user function.

        $results = stripHtmlExceptImage($results); : then we strip all the html tags except the <img .... > tag. stripHtmlExceptImage($results); as stripLineBreaking function could be called in any custom stripOutput user function

        $results = stripJscripts($results); : and finally we strip all potentials javascript call, by calling the stripJscripts function.

        With this stripOutput function we have filtered all the unwanted characters and tags and only save the image tags.
        Nevertheless, we are obliged to forbid the highlighting otherwise we will break the <img ... > tag by adding the necessary tag to highlight the results.

        the enSearchWordList defined in the image.configuration.php simply return a list of words that will be use to do a search. These word are labels of image like for instance :

        <img alt="equateur01_250.jpg" src="assets/images/uc2007/n10/equateur01_250.jpg" width="250" />

        I hope that these explanations help you to understand how runs this first draft of "results with images" demo.
          • 121
          • 36 Posts
          Thanks a lot for the reply, much appreciate.

          I am still having problems though.. I’ll show you what I have in my pages. I only have three pages just now, one homepage with the search, and one search results page, and one page containing some keywords in the summary and an image in the content.

          I inserted the following into my homepage template and the search form did not show. I removed the &tplLayout=`optionMultipleList` and the form shows ok? Do I need to do something with the any of the templates in snippets/AjaxSearch/templates folder?

          [!AjaxSearch? &extract=`99` &extractLength=`120` &ajaxMax=`3` &showMoreResults=`1` &moreResultsPage=`176` &config=`image`  &searchWordList=`enSearchWordList` &highlightResult=`0` &tplLayout=`optionMultipleList`!]


          I do not want an ajaxsearch, and would like the results on another page (page id 6). I tried the following, which shows the results on page 6, but still no image. All I get in the results is the title of the page (which is a link to that page).

          [!AjaxSearch? &ajaxSearch=`0` &AS_landing=`6` &extract=`99:content,tv_content` &extractLength=`120` &config=`image` &searchWordList=`enSearchWordList` &highlightResult=`0`!]


          I also included the following call into my search results template, I’m not 100% sure what should go in here?

          [!AjaxSearch? &ajaxSearch=`0` &AS_showForm=`0` &grabMax=`10` &extract=`0` &extract=`99:content,tv_content` &extractLength=`120` &config=`image`  &searchWordList=`enSearchWordList` &highlightResult=`0`!]


          I also created a file called image.configuration.php and placed that in the configs folder, is this correct? Should I do anything else with this?

          I have copied all of the 1.8 zip file, and followed the instructions in ajaxSearch_readme.txt

          Please can someone help, I’ve spent 4 hours on this and am no further forward at all  sad

          Thaks in advance,

          modx noob wink
            • 5811
            • 1,717 Posts
            @4hero

            I inserted the following into my homepage template and the search form did not show.

            [!AjaxSearch? &extract=`99` &extractLength=`120` &ajaxMax=`3` &showMoreResults=`1` &moreResultsPage=`176` &config=`image`  &searchWordList=`enSearchWordList` &highlightResult=`0` &tplLayout=`optionMultipleList`!]
            Have you defined a chunk named "optionMultipleList". If not, create a chunck with the name "optionMultipleList" by copy/past of the content of the file templates/optionMultipleList/tplLayout.tpl.html

            I tried the following, which shows the results on page 6, but still no image. All I get in the results is the title of the page (which is a link to that page).
            [!AjaxSearch? &ajaxSearch=`0` &AS_landing=`6` &extract=`99:content,tv_content` &extractLength=`120` &config=`image` &searchWordList=`enSearchWordList` &highlightResult=`0`!]

            Images are displayed on the landing page (#6), so your landing page should contain:

            [!AjaxSearch? &ajaxSearch=`0` &extract=`99` &highlightResult=`0` &config=`image` &AS_showForm=`0`!]

            &searchWordList=`enSearchWordList` is useless to display the results (usefull only to set up the search form with an input lits).
            Take care also with &highlightResult=`0` (without a s for Result)

            [!AjaxSearch? &ajaxSearch=`0` &AS_showForm=`0` &grabMax=`10` &extract=`0` &extract=`99:content,tv_content` &extractLength=`120` &config=`image` &searchWordList=`enSearchWordList` &highlightResult=`0`!]
            &extract=`0` is not coherent with &extract=`99:content,tv_content` (you want or not extract wink )

            I also created a file called image.configuration.php and placed that in the configs folder, is this correct? Should I do anything else with this?
            No it’s correct, if you declare a new config file, you should place it in the template folder.

              • 121
              • 36 Posts
              I didn’t want a multiple select list, and would prefer for the user to enter their own search term. I have now created a chunk called simpleSearch and have the following in my homepage template, is this the correct tpl for this?:

              [!AjaxSearch? &AS_landing=`6` &extract=`99` &extractLength=`120` &ajaxMax=`3` &showMoreResults=`1` &moreResultsPage=`176` &config=`image`  &searchWordList=`enSearchWordList` &highlightResult=`0` &tplLayout=`simpleSearch`!]


              This is the content of simpleSearch chunk:

              [+as.showForm:is=`1`:then=`
              <form [+as.formId+] action="[+as.formAction+]" method="post">
                  <fieldset>
                  <label for="ajaxSearch_input">
                    <input id="ajaxSearch_input" type="text" name="search" value="[+as.inputValue+]"[+as.inputOptions+] />
                  </label>
              		<input type="hidden" name="advSearch" value="[+as.advSearch+]" />
                  <label for="ajaxSearch_submit">
                    <input id="ajaxSearch_submit" type="submit" name="sub" value="[+as.submitText+]" />
                  </label>
                  </fieldset>
              </form>
              `+]
              [+as.showIntro:is=`1`:then=`
              <p class="ajaxSearch_intro" id="ajaxSearch_intro">[+as.introMessage+]</p>
              `+]
              [+as.showResults:is=`1`:then=`
              [+as.results+]
              `+]


              I also added the following to my results template (page 6)

              [!AjaxSearch? &ajaxSearch=`0` &extract=`99` &highlightResult=`0` &config=`image` &AS_showForm=`0`!]


              No it’s correct, if you declare a new config file, you should place it in the template folder.

              Where exactly should image.configuration.php go? I currently have it in snippets/AjaxSearch/configs. This is my config file, should the function enSearchWordList() be commented out as I’m not having a multiple select?

              <?php
              
              $__stripOutput = 'saveImage';
              
              // StripOutput user function
              // Uncomment and complete the core function and choose your own function name
              // string functionName(string results)
              // functionName : name of stripOutput function passed as &stripOutput parameter
              // results : string php variable name as results
              // return the filtered results
              
              function saveImage($results){ 
              
                // replace line Breaking by space
                $results = stripLineBreaking($results);
                // strip other html tags
                $results = stripHtmlExceptImage($results);
                // strip javascript tags
                $results = stripJscripts($results);
                
                return $results;
              }
              
              // searchWordList user function
              // Uncomment and complete the core function and choose your own function name
              // string functionName()
              // functionName : name of searchWordList function passed as &searchWordList parameter
              // return a comma separated list of words
              
              function enSearchWordList(){ 
              
                $list = "subaru,samassekou,equateur,cromer,zatreanu,burnett";
                return $list;
              }
              
              ?>


              as it stands just now, I have one page which contains some keywords in the content, along with an image. This is what’s in the content of that page:

              <p>subaru impreza car auto automobile black gold wheels rims STi "forth road bridge" lothian scotland processing processed</p>
              <img height="682" src="assets/images/Car%20Photos/subaru.jpg" width="1024" />
              


              And all that is being rendered in the search results page is:

              <div class="ajaxSearch_result">
              <a class="ajaxSearch_resultLink" href="/modx/index.php?id=3" title="">Subaru Impreza STi</a>
              <div class="ajaxSearch_resultExtract"><p>...subaru impreza car auto automobile black gold wheels rims STi "forth road bridge" lothian sco...</p></div>
              


              I really appreciate your help on this coroico.
                • 5811
                • 1,717 Posts
                [!AjaxSearch? &AS_landing=`6` &extract=`99` &extractLength=`120` &ajaxMax=`3` &showMoreResults=`1` &moreResultsPage=`176` &config=`image`  &searchWordList=`enSearchWordList` &highlightResult=`0` &tplLayout=`simpleSearch`!]
                If you don’t want select the search terms from a list, the &searchWordList=`enSearchWordList` is useless.
                Where exactly should image.configuration.php go? I currently have it in snippets/AjaxSearch/configs.
                This is correct.
                This is my config file, should the function enSearchWordList() be commented out as I’m not having a multiple select?
                Yes you could remove this function, if you use the simpleSearch/tplLayout as template

                And all that is being rendered in the search results page is:
                <div class="ajaxSearch_result">
                <a class="ajaxSearch_resultLink" href="/modx/index.php?id=3" title="">Subaru Impreza STi</a>
                <div class="ajaxSearch_resultExtract"><p>...subaru impreza car auto automobile black gold wheels rims STi "forth road bridge" lothian sco...</p></div>

                Which term do you search ? subaru ? if yes, if you don’t find the second extract (name of the image file), it could be due of the &extract parameter (limited to 1 by default) or from your saveHtml function (which erase the tag <img .... > Check your parameter and your function.
                  • 5811
                  • 1,717 Posts
                  Where exactly should image.configuration.php go? I currently have it in snippets/AjaxSearch/configs.
                  Sorry, but it’s false. Your file should be named image.config.php. Not image.configuration.php
                  This explain why your saveImage function is doesn’t called and why you can’t find the second extract. Change the name of your config file and try it again.
                    • 121
                    • 36 Posts
                    you, coroico, are a genuis wink

                    Many many many many many thanks for all your help on this, I will sleep tonight now!!!

                    It works! It was image.config.php that was the problem..

                    Thanks again,

                    Neil.
                      • 4749
                      • 623 Posts
                      Coroico,
                      I’m getting this error after installing 1.8:

                      Fatal error: Call to undefined function mb_strlen() in /home/altaair/public_html/assets/snippets/ajaxSearch/classes/ajaxSearch.class.inc.php on line 283


                      What is wrong with the snippet? I’ve changed the code in the snippets and in the assets folder. Here’s my snippet call:

                      [!AjaxSearch? &AS_showForm=`0` !]
                        The MODx has you...
                        Utah Web Design