PassMark Logo
Home » Forum

Announcement

Collapse
No announcement yet.

Icon in search results (file type, not thumbnail)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Icon in search results (file type, not thumbnail)

    I was reading this thread:

    http://wrensoft.com/forum/viewtopic.php?t=127

    and the last post by wrensoft indicated that it would be possible to include icons based on the file type (i am looking for to distinguish PDF files) in the near future.

    I see that this website:

    http://childrensvaccine.org/search/s...2Bimmunisation

    ...was featured on the examples page, and was wondering how to get icons like these to show up. thanks!

  • #2
    This is not a feature in the current version of Zoom. However, we do have plans to support image associations with pages, so that you can have certain images appear next to each search result. The current schedule for this would be for either Version 4.2 or 5.0.

    The example website uses a customized script to display the icons and file sizes (this is mentioned on our examples page, right under the link). The user modified the search.php file himself to do this, and we thought it would be a good example of how the search script can be customized with a bit of PHP knowledge.

    You should be able to add PHP code to determine the file type by simply looking at the URL of the link, and whether it ends with ".pdf".
    --Ray
    Wrensoft Web Software
    Sydney, Australia
    Zoom Search Engine

    Comment


    • #3
      I've added a few lines to the search.php file. They add a second css class to the result_title class, if the url ends on .pdf. Now it's easy to add a small pdf-icon with a little css.

      It's around line 1279, where it says
      Code:
      print "<div class=\"result_title\">";
      Delete that line, and insert:

      Code:
      preg_match&#40;"/\.&#91;^\.\/&#93;+$/", strtolower&#40;$urls&#91;$ipage&#93;&#41;, $my_filetype&#41;;
      
      	if &#40;trim&#40;$my_filetype&#91;0&#93;&#41;=='.pdf'&#41; &#123;
      		print "<div class=\"result_title pdf\">";
      	&#125; else &#123;
         		print "<div class=\"result_title\">";
      	&#125;
      It's simple and it works.

      You could use a switch-case scenario instead, and thus add icons for .doc, .xls or whatever you fancy.

      Comment


      • #4
        thanks!

        Hi,

        Thanks for giving me inspiration!
        Wasn't quite sure from your example what you did in your template file to declare the css and display the icon? So I tried an alternative just as simple adding img src to the line, and an extra else if for .docs....


        // !!changed print "<div class=\"result_title\">";
        preg_match("/\.[^\.\/]+$/", strtolower($urls[$ipage]), $my_filetype);

        if (trim($my_filetype[0])=='.pdf') {
        print "<div class=\"result_title_pdf\"><img src=\"/orgdirs/hr/images/icon_pdf.gif\" align=\"absmiddle\">";
        } else if (trim($my_filetype[0])=='.doc') {
        print "<div class=\"result_title_pdf\"><img src=\"/orgdirs/hr/images/icon_word.gif\" align=\"absmiddle\">";
        } else {
        print "<div class=\"result_title\">";
        }

        Comment


        • #5
          jollynz,

          I previous had file type icons inserted based on the search category, my original catergories being .pdf, .htm, etc.

          We've now moved away from those categories and your method of resolving the file type has allowed us to retain file type icons so thank you.

          As a variant I put the icon after the file title. And for PDF files we include the file size as we have a few 5MB+ files lurking on the site.

          Code:
              if &#40;$UseCats&#41;
              &#123;
                  $catindex = rtrim&#40;$catpages&#91;$ipage&#93;&#41;;
          // Inserting File Type Icons
          // Resolve variable for the file type. 
          preg_match&#40;"/\.&#91;^\.\/&#93;+$/", strtolower&#40;$urls&#91;$ipage&#93;&#41;, $my_filetype&#41;; 
          
          // PDF file icon and file size.
          if &#40;trim&#40;$my_filetype&#91;0&#93;&#41;=='.pdf'&#41;  
             &#123; print " <span class=\"category\"> <img src=\"pdf.gif\"> ". rtrim&#40;$catnames&#91;$catindex&#93;&#41;; 
          	  $filepath = "..".rtrim&#40;$urls&#91;$ipage&#93;&#41;;
                  $filesize = filesize&#40;$filepath&#41;;
          	   if &#40;$filesize >= 1048576&#41; &#123; $filesize = number_format&#40;&#40;$filesize / 1048576&#41;,2&#41; . "MB"; &#125; 
          	   elseif &#40;$filesize >= 1024&#41; &#123; $filesize = number_format&#40;&#40;$filesize / 1024&#41;,0&#41; . "KB"; &#125; 
          	   elseif &#40;$filesize >= 0&#41; &#123; $filesize = $filesize . "Bytes";  &#125;
          	   print " ".$filesize."</span>";
          &#125;
          
          // HTM file icon.
          else &#123; 
          	if &#40;trim&#40;$my_filetype&#91;0&#93;&#41;=='.htm'&#41;   
             	   &#123; print " <span class=\"category\"> <img src=\"html.gif\"> ". rtrim&#40;$catnames&#91;$catindex&#93;&#41; . "</span>"; &#125;
          	else &#123; print " <span class=\"category\">". rtrim&#40;$catnames&#91;$catindex&#93;&#41; . "</span>"; &#125;
              	&#125;
              &#125;
              print "</div>\n";
          Mark Gallagher

          Comment


          • #6
            Here is yet another variation, this time for the ASP version of Zoom. (If anybody feels like improving it, please, be my guest. )

            On (or around) line 1558, you should see:

            Code:
            Response.Write&#40;"<div class=""result_title"">"&#41;
            Replace that with the following paragraph:

            Code:
            ' If the file is a PDF&#58;
            If InStr&#40;1, urls&#40;ipage&#41;, ".pdf", vbTextCompare&#41; <> 0 Then
            	Response.Write&#40;"<div class=""result_title"">  [img][/img] "&#41;
            			
            ' If the file is a DOC&#58;			
            ElseIf InStr&#40;1, urls&#40;ipage&#41;, ".doc", vbTextCompare&#41; <> 0 Then
            	Response.Write&#40;"<div class=""result_title"">  [img][/img] "&#41;
            
            ' If the file is a XLS&#58;			
            ElseIf InStr&#40;1, urls&#40;ipage&#41;, ".xls", vbTextCompare&#41; <> 0 Then
            	Response.Write&#40;"<div class=""result_title"">  [img][/img] "&#41;
            
            ' If the file is a PPT&#58;			
            ElseIf InStr&#40;1, urls&#40;ipage&#41;, ".ppt", vbTextCompare&#41; <> 0 Then
            	Response.Write&#40;"<div class=""result_title"">  [img][/img] "&#41;
            
            ' If the file is a web page&#58;			
            ElseIf InStr&#40;1, urls&#40;ipage&#41;, ".htm", vbTextCompare&#41; <> 0 Then
            	Response.Write&#40;"<div class=""result_title"">  [img][/img] "&#41;
            			
            ' For all other file types, don't show a picture&#58;			
            Else
            	Response.Write&#40;"<div class=""result_title"">"&#41;
            End If
            This code assumes that the gif images are all in the same folder as search.asp.

            - JW

            Comment


            • #7
              Originally posted by Ray
              This is not a feature in the current version of Zoom. However, we do have plans to support image associations with pages, so that you can have certain images appear next to each search result. The current schedule for this would be for either Version 4.2 or 5.0.
              I'm sorry to learn that this feature was not available in the 4.2 version. We would prefer to have a small .pdf icon next to all .pdf serarch results. Today we use a .desc file to all .pdf documents and starts the title of each document with "PDF Document:" That works as well, but it would be nice have the icon to show what files are .pdf's.
              --
              T.

              Comment


              • #8
                The post you quoted from Ray is about 12 months old. At that time we were thinking we might be able to get it into V4.2, which had not been released at the time.

                As it turned out it was a fair amount of development work to implement it properly and it made more sense to include it into V5. Which is what we have done. Development on other V5 features continue but it will be out in the next few months.

                -----
                David

                Comment

                Working...
                X