Mysearch Class Documentation (English)

1. Installation

2. Usage
    a) Include
    b) Initialize / Set Database for Search

3. Functions => Not needed, but helpfull to customize your Search
    a) Search for Keyword only
    b) Search Keywords "and" or "or"
    c) Replace URL in Result
    c) Set Length for Result
    e) Set Style for Keyword Replace in Result
    f) Set Tables for Search
    g) Set URLS to result
    h) Set Style for URL to Result

4. Start Search and set Keywords

5. List Results
    a) Show Number of Results and/or Number of Field Matches
    b) List all Results and/or Keywords, Number of Results, Table of results and Field of Results

6. Attachment
    a) The easiest way to use this Class
    b) The complex way to use this Class
    c) Credits

NOTE : GREEN is String, MAGENTA is Int

1. INSTALLATION

Open the File mysearch.class.php and Set your Server (Default: localhost) your Username for MYSQL and your Password for MYSQL.
You can also change ERROR_HANDLING, but its not recommended.

Now you can Upload the Class onto your Server.

 

2. USAGE

    a) Include

    Make a new File eg. search.php
    Include the mysearch Class with eg. include("path_to_class/mysearch.class.php");

    b) Initialize / Set Database for Search

    $search = new mysearch; //That's the easiest way to Initialize... It will search all Databases @ your Mysql Server
    $search = new mysearch("DATABASE"); //With this Parameter you set the Database for Search ... Now just the Database : DATABASE will be     searched
    $search = new mysearch(array("DATABASE1", "DATABASE2")); //With Array you got the Option to search more then one Database ...
    In this Case : DATABASE1 and DATABASE2

 

3. FUNCTIONS => Not needed, but helpfull to customize your Search (If you Not set this Functions, they are STANDARD)

    a) Search for Keyword only

    SET : $search->kwd_only("on");
    STANDARD : OFF
    DESCRIPTION : If you set This Function to ON, it will only search for the word(s) stand alone. eg. It will find "til" and will not find "until"

 

    b) Search Keywords "and" or "or"

    SET : $search->and_or_kwd("or");
    STANDARD : AND
    DESCRIPTION : If you set This Function to OR, it will search the fields where Keyword1 or Keyword2 matches.

 

    c) Replace URL in Result

    SET : $search->replace_url_in_result("on");
    
STANDARD : OFF
    
DESCRIPTION : If you set this Function to ON, it will replace all URLS in the Result..
    If the String is "My favorite Site is http://www.php.net and www.mysql.com" the Result shows the URLS : http://www.php.net and www.mysql.com as Links.

 

    d) Set Length for Result

    SET : $search->sub_len_result("the_length_of_the_result");
    STANDARD :
OFF
    DESCRIPTION :
If you set this Function, the Result just show you the first "the_length_of_the_result" Chars. (eg. 150)

 


    e) Set Style for Keyword Replace in Result

    SET : $search->kwd_found_style("<font size=\"4\" color=\"#FF0000\"><a title=\"Searchword : &quot;\\0&quot;\">\\0</a></font>");
    STANDARD :
<font color=\"#35B84A\"><b>\\0</b></font>
    DESCRIPTION :
This will set the Style of the founded Keyword in the Result.
    IMPORTANT : The \\0 is important, it stands for the Keyword.

 


    f) Set Tables for Search

    SET : $search->tables("table1"); //All Fields in TABLE1
    or
    SET :
$search->tables(array("table1" => "", //Whole TABLE1
                                                    "table2" => "field1",
//FIELD1 in TABLE2
                                                    "table3" => array("field1", "field2"));
//FIELD1 and FIELD2 in TABLE3
    STANDARD :
OFF
    DESCRIPTION :
If it's NOT SET, the class will search all Tables

 


    g) Set URLS to result

    SET : $search->urls4result(array("table1" => "%%HOST/my_table1_dir/index.php",
                                                           "table2" => "/index.php?menu_id=%%ID",

                                                        
  "table3" => "/%%TABLE/%%FIELD.php"));
    STANDARD :
OFF
    VARIABLES :
%%TABLE stands for the Table, the Keyword was found
                            %%FIELD stands for the Field, the Keyword was found
                            %%DB stands for theDatabase, the Keyword was found
                            %%HOST stands for the Host. eg. www.myhost.com
                            %%MY_FIELD is very important, IN PLACE OF "MY_FIELD" you got the option to SET a Field of the Table where                                                         the Value of the Fieldname is taken, and Replaced with %%MY_FIELD.
                            eg. with %%ID he take the Value of ID and return it.
    DESCRIPTION :
If this Function is Set, the Result will show you the URL (you set in the Array) @ the End of the founded String.
    IMPORTANT : The Variable passed to urls4result() have to be a Array

 


    h) Set Style for URL to Result

    SET : $search->res_url_style("<a href=\"%%URL\" target=\"_self\"><font size=\"2\">%%URL</font></a>");
    STANDARD :
<a href=\"%%URL\" target=\"_self\"><font size=\"2\">%%URL</font></a>
    VARIABLES :
%%URL stands for the URL you passed with urls4result()
                            %%HOST stands for the Host. eg. www.myhost.com
    DESCRIPTION :
This will set the Style of the URL @ the End of the founded String
    IMPORTANT : urls4result() must be set before res_url_style()

 

 

4. START SEARCH AND SET KEYWORDS

    SET : $search->start("searchwords", "Content Seperator", "Keyword Seperator");
    STANDARD : $search->start("", "<br><br>\n", ", ");
    DESCRIPTION : The easiest way to use is: $search->start("my_keywords"); //my_keywords have to be a string. eg. "keyword1 keyword2 keyword3"
    The Content Seperator stands for the way, the results be listet.... In the Standard Case, it looks like : "My_first_result<br><br>My_second_result".
    The Keyword Seperator (Look @ 5b).
    IMPORTANT : If you are using a TEMPLATE CLASS you have to set the Block after $search->start()
    eg. $tpl->set_block(); between $search->start() and while($search->out())

 

5. LIST RESULTS

    a) Show Number of Results and/or Number of Field Matches

    After you set $search->start() you are able to show the Number of Results, and/or show the Number of Fields, the Keyword was found in.
    Number of Results : $search->results
    Number of Field Matches : $search->fields_count
    EXAMPLE :
    <?
    echo "<b>Totaling there are &quot;".$search->results."&quot; Results in &quot;".$search->fields_count."&quot; Fields found.</b>";
    ?>

 

    b) List all Results and/or Keywords, Number of Results, Table of results and Field of Results

    DESCRIPTION : With while($search->out()){//listed Results} the Class will list your Result of each Field the Keyword(s) was found.
    VARIABLES :
    $search->r("result")
Contains the Number of Results found in this Field
    $search->r("keywords") Contains the Keywords Seperate with the Keyword Seperator given @ $search->start()
    $search->r("table")
Contains the Name of the Table, this Result were found
    $search->r("field")
Contains the Name of the Field, this Result were found
    $search->r("content")
Contains the Content .. Seperated with the Content Seperator given @ $search->start()
    
EXAMPLE :
    
<?
    while($search->out()){
    echo $search->r("result")." Results for &quot ".$search->r("keywords")." &quot in Table ".$search->r("table")." => Field ".$search->r("field")."     </b></i></u><br><br>
    ".$search->r("content");
    }
    ?>

 

6. ATTACHMENT

    a) The easiest way to use this Class

     <?
     //This way below will search ALL Databases and ALL Tables and ALL Fields for the Searchwords
     $search = new mysearch;
     $search->start($my_searchwords);
     echo
"<b>Totaling there are &quot;".$search->results."&quot; Results in &quot;".$search->fields_count."&quot; Fields found.</b>";

           while($search->out()){
           echo $search->r("result")." Results for &quot ".$search->r("keywords")." &quot in Table ".$search->r("table")." => Field ".$search->r("field")."            </b></i></u><br><br>
          ".$search->r("content");
          }
     ?>

 

    b) The complex way to use this Class

     <?
     //This way below will just Search TABLE1 (All Fields), TABLE2 (FIELD1), TABLE3 (FIELD1 and FIELD2) in DATABASE
     $search = new mysearch("DATABASE");
     $search->kwd_only("on");
     $search->and_or_kwd("or");
     $search->replace_url_in_result("on");
     $search->kwd_found_style("<a title=\"Searchword : &quot;\\0&quot;\"><font size=\"4\" color=\"#FF0000\">\\0</font></a>");

     $search->tables(array("table1" => "",
//Whole TABLE1
                                           "table2" => "field1",
//FIELD1 in TABLE2
                                           "table3" => array("field1", "field2"));
//FIELD1 and FIELD2 in TABLE3

     $search->urls4result(array("table1" => "%%HOST/my_table1_dir/index.php",
                                                   "table2" => "/index.php?menu_id=%%ID",

                                                   
"table3" => "/%%TABLE/%%FIELD.php"));

     $search->res_url_style("<a href=\"%%URL\" target=\"_self\"><font size=\"2\">%%URL</font></a>");

     $search->start($my_searchwords, "<br><hr><br>", ", ");
     echo
"<b>Totaling there are &quot;".$search->results."&quot; Results in &quot;".$search->fields_count."&quot; Fields found.</b>";

           while($search->out()){
           echo $search->r("result")." Results for &quot ".$search->r("keywords")." &quot in Table ".$search->r("table")." => Field ".$search->r("field")."            </b></i></u><br><br>
          ".$search->r("content");
          }
     ?>

 

    c) Credits

     Author : Oliver Harbourn
     E-Mail : oliver@kstp.at
     Date : 31.01.2003

          Related sites :
          Mysql
          PHP


© Oliver Harbourn 2003 - All Rights Reserved