Location: PHPKode > scripts > Site Search classes > site-search-classes/documentation.htm
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>SiteSearch Documentation</title>
    <style type="text/css">
    <!--
      body {
          margin: 30px 5%;
          text-align: left;
          font: 75% Verdana, Arial;
      }

      h1 {
          margin: 0px 0px 70px 0px;
          text-align: center;
          color: #00c;
      }
      h2 {
          margin: 50px 0px 0px 0px;
          color: #c00;
      }
      h3 {
          margin: 50px 0px 10px 0px;
          color: #080;
      }
      h3 .parameters {
          font-size: 90%;
          color: #333;
      }
      h3 .type {
          color: #999;
          font-style: italic;
      }
      hr {
          margin: 5px 0px;
          width: 90%;
          text-align: left;
          color: #aaa;
      }

      .title {
          line-height: 40px;
          font-size: 120%;
          color: #000;
          font-weight: bold;
      }
      pre.code {
          margin: 0px 0px 40px 0px;
          width: 750px;
          padding: 10px;
          background-color: #e5e5e5;
          border: 1px dotted #000;
          font: 120% Courier New, Lucida Console;
      }
      pre.code .php_tags {
          font-weight: bold;
          color: #c00;
      }
      pre.code .function {
          color: #00c;
      }
      pre.code .structure {
          color: #060;
      }
      pre.code .string {
          color: #c00;
      }
      pre.code .numeric {
          color: #f00;
      }
      pre.code .comments {
          color: #f70;
      }

      a:link {
          color: #00c;
          text-decoration: none;
      }
      a:visited {
          color: #00c;
          text-decoration: none;
      }
      a:hover {
          color: #c70;
      }
      a:active {
          color: #c00;
      }

      strong.note {
          color: #00c;
          margin-left: 30px;
      }
      ol {
          margin-top: 5px;
          line-height: 150%;
      }


    -->
    </style>
  </head>
  <body>

    <h1>SiteSearch Documentation</h1>


    <h2>Introduction</h2>
    <hr />
    <p>
        SiteSearch class is a search engine for small and medium sites. It doesn't work with databases, so it is very easy 
        to implement it. This class will search in the content of each file. You can set the file extensions allowed to be 
        searched in, and you can hide directories that SiteSearch should not open.
    </p>
    <p>
        You can split the search in different sections of your site (what saves time), and you can make the search in text 
        documents (like .htm, .php, .asp, etc.) or images. If you download PowerThumb Class (it is in my role of classes
        at <a href="http://www.phpclasses.org/">PHP Classes</a>), in the result of image search will have thumbnails.
    </p>


    <h2>How to Use</h2>
    <hr />
    <p>
        First, it will be necessary import <strong>SiteSearch</strong> class file to the script. Than you may create the object from 
        SiteSearch class.
    </p>

<span class="title">1. Creating the SiteSearch object:</span>
<pre class="code">
<span class="php_tags">&lt;?php</span>

<span class="comments">// Imports SiteSearch class</span>
<span class="function">require_once</span> <span class="string">&quot;class.sitesearch.php&quot;</span>;

<span class="comments">// Creates and object called &quot;$Search&quot;</span>
$Search = <span class="structure">new</span> <span class="function">SiteSearch</span>();

<span class="php_tags">?&gt;</span>
</pre>


    <p>
        And now a real life example. Let's suppose you want to select the &quot;name&quot; and &quot;email&quot; of all 
        clients that celebrate birthday in this month. The name of database in this example is &quot;my_database&quot; and 
        the selected table is &quot;clients&quot;.
    </p>

<span class="title">2. Setting search options:</span>
<pre class="code">
<span class="php_tags">&lt;?php</span>

$Search = <span class="structure">new</span> <span class="function">SiteSearch</span>();


<span class="comments">// This will create search sections (you MUST create at least one).
// All subdirectories will be searched in automatically</span>
$Search-><span class="function">addSection</span>(<span class="string">&quot;Whole Site&quot;</span>, <span class="string">&quot;../&quot;</span>);
$Search-><span class="function">addSection</span>(<span class="string">&quot;PHP&quot;</span>, <span class="string">&quot;../php/&quot;</span>);
$Search-><span class="function">addSection</span>(<span class="string">&quot;Javascript&quot;</span>, <span class="string">&quot;../javascript/&quot;</span>);


<span class="comments">// This will allow search in documents only</span>
$Search-><span class="function">searchInDocuments</span>(<span class="structure">true</span>);
$Search-><span class="function">searchInImages</span>(<span class="structure">false</span>);


<span class="comments">// This will hide directories that should NOT be opened by the search engine</span>
$Search-><span class="function">hideDir</span>(<span class="string">&quot;../includes/&quot;</span>);
$Search-><span class="function">hideDir</span>(<span class="string">&quot;../log_files/&quot;</span>);


<span class="comments">// This includes files .htm in the search results, and hides files .php</span>
$Search-><span class="function">addDocumentExtension</span>(<span class="string">"htm"</span>);
$Search-><span class="function">hideDocumentExtension</span>(<span class="string">"php"</span>);


<span class="comments">// Printing search form</span>
$Search-><span class="function">form</span>();


<span class="function">echo</span> <span class="string">&quot;Here are your search results: &quot;</span>;

<span class="comments">// Printing search results</span>
$Search-><span class="function">results</span>();

<span class="php_tags">?&gt;</span>
</pre>

    <p>
        <strong class="note">NOTE:</strong> by default, the search will be in the following extensions: &quot;htm&quot;, 
        &quot;html&quot;, &quot;shtml&quot;, &quot;php&quot;, &quot;php3&quot;, &quot;jsp&quot;, &quot;asp&quot;, 
        &quot;pdf&quot;, &quot;txt&quot; (when searching in documents), and &quot;jpg&quot;, &quot;jpeg&quot;, 
        &quot;gif&quot;, &quot;png&quot;, &quot;bmp&quot; (when searching in images).
    </p>




      <h2>Methods</h2>
      <hr />

       <p>
         <h3><span class="type">void</span> SiteSearch <span class="parameters">( [ <span class="type">array</span> $site_sections, <span class="type">array</span> $excluded_dir_list, <span class="type">array</span> $docs_ext_list, <span class="type">array</span> $imgs_ext_list ] )</span></h3>
         Class constructor. Parameters are:
         <ol>
           <li>site_sections: associative array of the site sections. Elements should be like this: section_name =&gt; section_root_dir.</li>
           <li>excluded_dir_list: array with all directories that SiteSearch should just ignore.</li>
           <li>docs_ext_list: array with documents extensions that will be searched in.</li>
           <li>imgs_ext_list: array with images extensions that will be searched in.</li>
         </ol>
       </p>

       <p>
         <h3><span class="type">string</span> form <span class="parameters">( [<span class="type">bool</span> $should_print] )</span></h3>
         Prints the HTML code for the search form. If you don't want it to be printed, only returned, set the optional parameter to FALSE.
       </p>

       <p>
         <h3><span class="type">string</span> results <span class="parameters">( [<span class="type">bool</span> $should_print] )</span></h3>
         Prints the HTML code for the search results. If you don't want it to be printed, only returned, set the optional parameter to FALSE.
       </p>

       <p>
         <h3><span class="type">void</span> addSection <span class="parameters">( <span class="type">str</span> $section_name, <span class="type">str</span> $section_root_dir )</span></h3>
         Adds a new site section for the search. It will look in subdirectories of <em>$section_root_dir</em> automatically. This 
         method should be called at least once before you call <em>results()</em> method, or no search directories will be given 
         (what displays an error message: &quot;Please select a search section&quot;).
       </p>

       <p>
         <h3><span class="type">void</span> hideDir <span class="parameters">( <span class="type">str</span> $dir )</span></h3>
         Adds a new hidden dir. Files in this diretory will NOT be opened during the search process.
       </p>

       <p>
         <h3><span class="type">void</span> addDocumentExtension <span class="parameters">( <span class="type">str</span> $extension )</span></h3>
         Adds a file extension in the list of extensions allowed to be opened during the search of documents.
       </p>

       <p>
         <h3><span class="type">void</span> hideDocumentExtension <span class="parameters">( <span class="type">str</span> $extension )</span></h3>
         Removes a file extension in the list of extensions allowed to be opened during the search of documents.
       </p>

       <p>
         <h3><span class="type">void</span> addImageExtension <span class="parameters">( <span class="type">str</span> $extension )</span></h3>
         Adds a file extension in the list of extensions allowed to be opened during the search of images.
       </p>

       <p>
         <h3><span class="type">void</span> hideImageExtension <span class="parameters">( <span class="type">str</span> $extension )</span></h3>
         Removes a file extension in the list of extensions allowed to be opened during the search of images.
       </p>

       <p>
         <h3><span class="type">void</span> searchInDocuments <span class="parameters">( [<span class="type">bool</span> $should_search] )</span></h3>
         Sets if the search should be in text documents like .htm, .php, .asp, .txt, etc. Default parameter value is TRUE.
       </p>

       <p>
         <h3><span class="type">void</span> searchInImages <span class="parameters">( [<span class="type">bool</span> $should_search] )</span></h3>
         Sets if the search should be in image files. Default parameter value is TRUE.
       </p>

       <p>
         <h3><span class="type">void</span> showDetails <span class="parameters">( [<span class="type">bool</span> $should_show] )</span></h3>
         Sets if should display search details like elapsed time, total number of documents that were search in and total matches. 
         Default parameter value is TRUE.
       </p>



    <h2>Credits</h2>
    <hr />

     <p>
       Carlos Reche <br />
       <em><a href="mailto:hide@address.com">carlosreche at yahoo dot com</a></em>
     </p>
     <p>
       Jan 6, 2005<br />
       Sorocaba, SP - Brazil
     </p>



  </body>
</html>
Return current item: Site Search classes