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

    I’m building a personal photo site for myself, and plan on tagging (adding keywords) in the summary and an image in the content. What I would like is my search to display images in the results, and these images would be found by the keywords mentioned. You will then be able to view the results as a slideshow (but that’s another story laugh)

    So far I have my search working, but I cannot get the image to show. How can I render the results as html rather than plain text, and is what I plan on doing possible in modx?

    Any help would be greatly appreciated.

    Thanks in advance,

    Neil.
      • 5811
      • 1,717 Posts
      Hi Neil,

      So far I have my search working, but I cannot get the image to show. How can I render the results as html rather than plain text, and is what I plan on doing possible in modx
      You cannot get the image to show because a stripHTML filter is applied on the output results.
      With AS 1.7.1 look at the line 175 of includes/ajaxSearch.inc.php. Comment the stripHTML call and let me know the results.

      But keep in mind, by disabling this filter you will display may be some others unecessary html tags.
      With the version 1.8 in preparation you will be able to define your own stripOutput filter to manage the output results. You could get more informations on this filter by downloading the 1.8 readme.txt on this post
        • 29076
        • 615 Posts
        I need the same function myself, and I’m really looking forward to the next version of AjaxSearch. smiley
          I think, thererfor I am! But what I am, and why...?
          • 121
          • 36 Posts
          Many thanks coroico.

          I did what you said and the following happens.

          This is the html in the content section in the test page:

          <img alt="Subaru Impreza STi" height="682" src="assets/images/Car%20Photos/2557555691_db8e9429d8_b.jpg" title="Subaru Impreza STi" width="1024" />


          and this is what’s being rendered in the search results after commenting out line 175 (I’m using version 1.7.1)

          <span class=Subaru Impreza STi" height="682" src="assets/images/Car%20Photos/2557555691_db8e9429d8_b.jpg" title="Subaru Impreza STi" width="1024" />


          this is the source of the result

          <img alt="<span class=" ajaxsearch_highlight="" ajaxsearch_highlight1="">Subaru Impreza STi" height="682" src="assets/images/Car%20Photos/2557555691_db8e9429d8_b.jpg" title="<span class="ajaxSearch_highlight ajaxSearch_highlight1">Subaru</span> Impreza STi" width="1024" />
          ... 


          my thoughts were that this was something to do with the search highlight, so I added the following to the search tag:

          &extract=`0`


          Then the only thing that showed in the results was the link to the page.

          Any further help would be greatly apprecited.

          Thanks in advance,

          Neil.
            • 5811
            • 1,717 Posts
            @4hero and Sylvaticus

            As demo I have used the StripOutput function provided by the new version Ajaxsearch 1.8 to show the images in the search Results. You could see the demo on the ajaxSearch Demo site. In the drop down list use all the searchWords (select them with the ctrl key).
            These search words are labels of <img > tags found in the english documents of the site.

            The stripOutput function is very simple:
            function myStripOutput($results){ 
            
              // renanme <img .... > tag by imgStart ... imgEnd
              $results = preg_replace("/\<img(.*?)\>/si","imgStart\$1imgEnd", $results );
            
              // replace line Breaking by space
              $results = stripLineBreaking($results);
              // strip other html tags
              $results = stripHtml($results);
              // strip javascript tags
              $results = stripJscripts($results);
              
              // renanme imgStart ... imgEnd  by <img .... > tag
              $results = preg_replace("/imgStart(.*?)imgEnd/si","<img\$1\>", $results );
            
              return $results;
            }
            1/ using a regular expression, all the <img (...) > tags are replaced by imgStart (...) imgEnd.
            2/ you use the stripLineBreaking, stripHtml and stripJscripts function available with AS to strip all other tags
            3/finally you replace again imgStart (...) imgEnd by <img (...) > tags

            So at the end, all html tags have been cleaned, except <img > tags.

            You could download the "image" config file used from the same demo page.

            Probably the function could/should be improved but this is a first step. If you have any suggestion to improve it, let me know, it could be interesting, to share these tricks.
              • 29076
              • 615 Posts
              I have only one thing to say: WOW! This is so great. I’m sorry, I going on a two weeks holiday, without netcontact!!! shocked , so I can’t test or help in any way in that periode, but as I said earlier, I really look foreward to the next version of AjaxSearch. This is great work.
                I think, thererfor I am! But what I am, and why...?
                • 5811
                • 1,717 Posts
                Thanks Sylvaticus. Your web site is beautiful and i am really happy If i could help you to promote Svalbard. Enjoy your holidays.
                  • 121
                  • 36 Posts
                  Thanks a lot coroico, I can’t wait to work with 1.8 cool Sorry about the delay, been on holiday also laugh

                  Thanks for your time on this,

                  Neil.