Home > Fluid Dynamics Search Engine > Help > 1178

Displaying file-type icons in search results

You can display file-type icons in the search results for certain binary files. This feature is only useful if you've already configured FDSE to search binary files (see Searching binary files).

This feature is based on the template variable %file_type_icon%, which stores the base filename of an icon that matches the file type of the result listing. The variable values are:

Default Icon URL Extension file_type_icon Value Comment
.doc doc Microsoft Word
.pdf pdf Portable Document Format
.txt txt text
.xls xls Microsoft Excel
.pub pub Publisher
.mp3 audio Audio file
.wav audio Audio file
.mpg video Video file
.avi video Video file
* 0 All others - returns zero

The string values stored in the %file_type_icon% variable are used to create an HTML <img> tag which displays the file type icon.

Because only the base names are returned by the variable, you have freedom use your own icons. Simply create icons with the given names like "doc.jpg" or "audio.gif". Place them in a folder, and then construct the <img> tag accordingly (see below).

Fluid Dynamics maintains a default folder at http://xav.com/i/icon32/ which you are welcome to use. This default folder contains 32- by 32-pixel GIF images. All images are returned with special cache-control headers that cause the browser to cache the icons for a year. This allows us to host image files that are used by thousands of sites and millions of users, without incurring significant bandwidth costs.

Steps to enable:

  1. Make sure you're running FDSE version or newer (the first version to support variable %file_type_icon%).

  2. Edit the template file:


    This is the template that creates each search result line listing. By default, the HTML looks like this:

    	<dt><b>%Rank%. <a href="%Redirector%%URL%">%Title%</a></b> %admin_options%</dt>
    	<dd class="sr">
    		%Description%<br />
    		<b>URL:</b> %url% - %Size% - %Day% %Month% %Year%

    You can just insert the variable %file_type_icon% wherever you like. One solution is to use a table like so:

    <table border="0">
    	<td align="right"><b>%Rank%.</b></td>
    	<td colspan="2"><b><a href="%Redirector%%URL%">%Title%</a></b> %admin_options%</td>
    	<td><br /></td>
    	<td valign="top">
    		 <img src="http://xav.com/i/icon32/%file_type_icon%.gif"     
    		  height="32" width="32" border="0" hspace="4" vspace="4" /> 
    	<td valign="top">
    		%Description%<br />
    		<b>URL:</b> %url% - %Size% - %Day% %Month% %Year%

    If you are using your own icons, customize the portion in pink to use your own URL and dimensions.

  3. With this solution, the appropriate file type icon will be shown for any binary search results. A transparent GIF will be used as a placeholder in all other search result listings.


Below is an example of how search results will appear after this customization has been made.

Example of icons in search results listings


FDSE detects the file type by analyzing the file extension, at least when assigning the %file_type_icon% variable. This works in 95% of the cases.

The main way this would fail is when a binary file is returned by a dynamic page, like http://xav.com/download.cgi?example.doc. The algorithm will detect ".cgi" as the extension and will therefore not assign the correct ".doc" file type icon.

There is no plan to change FDSE to better deal with this potential problem. It can be avoided by naming files in a consistent, logical way.

Custom coding:

The %file_type_icon% variable is created by subroutine get_file_type_icon_by_url in Perl file /search/searchmods/common.pl. To create new variable values, simply edit that subroutine and define new associations between file extensions and return values.

    "Displaying file-type icons in search results"