Newsgroup: it.comp.www.php
Titolo: Motore di ricerca iSearch

Ciao a tutti...
ho installato da qualche settimana questo script:
iSearch V1.9i
-------------
http://www.iSearchTheNet.com/isearch
E' un buon script per l'indicizzazione del proprio sito.
E' ora presente all'indirizzo: 
www.tuttoscout.org/cerca
Ho solo una piccola modifica da fare, ma da solo non ci riesco.
Essendo un sito moooolto grosso, rischio che se qualcuno dgt "campi" abbia
come risultato molte di pagine, il tutto и corretto, ma quello che dovrei
avere и quello di mettere in cima ai risultati, magari anche in evidenza,
quella/e pagina/e che abbiano nell'url la parola ricercata.
La tabella in questione и: "search_urls"
cella: "base"
Datemi solo qualche indicazione su come fare...
la "pappa pronta" non mi piace,perchи devo capire come "fare"...
altrimenti vi stresserт a vita...!!!
Nel frattempo, inserisco di seguito i codici delle 3 pagine principali che
compongono lo script.
Cmq, il tutto lo trovate all'indirizzo:
http://www.iSearchTheNet.com/isearch
Ciao e... Grazie!
Riccardo.
index.php
---------
<html>
<head>
<title>Cerca con TuttoScout</title>
<meta name="keywords" content="Motore di ricerca">
<meta name="description" content="Motore di ricerca">
<?include("meta.txt");?>
<LINK REL=StyleSheet HREF="style.css" TYPE="text/css">
</head>
<BODY onLoad="self.focus();" scroll="auto">
<?include("top.html");?>
<br>
<table width="778" border=0 align="center"><tr><td>
<?php
define('IN_ISEARCH', true);
/* Array of get/post variable names */
$isearch_get_post_vars = array(
        "action",
        "s",
        "page",
        "internet",
        "utf8",
    );
$isearch_path = ".";
include("$isearch_path/isearch_core.inc.php");
include("$isearch_path/isearch_search.inc.php");
/* Open the search component */
$isearch_open_result = isearch_open();
if (isset($internet))
{
    /* Process the search form data */
    if (!isset($isearch_operator))
    {
        $isearch_operator = $isearch_defaultOperator;
    }
    $s = urlencode(isearch_cleanSearchString($s, $isearch_operator));
    header( "Location:
http://www.iSearchTheNet.com/search.php?s=$s&lang=$isearch_langName&style=$isearch_styleName
" )
;
    /* Close the search component */
    isearch_close();
    exit;       /*** EXIT ***/
}
/* Check the action and set the page title accordingly */
if (isset($action))
{
    $isearch_pageTitle = $isearch_lang['results_title'];
}
else
{
    $isearch_pageTitle = $isearch_lang['search_title'];
}
include("$isearch_path/isearch_header.inc.php");
echo <<<EOF
<H1 class="isearch">$isearch_pageTitle<a href="admin/"><img src="admin.gif"
border="0" align="absmiddle" alt="Amministrazione Motore di ricerca"
hspace="10"></a></H1>
EOF;
if (!$isearch_open_result)
{
    echo "<P>Unable to read iSearch configuration\n";
}
if (!isset($s))
{
    /* We do not have a search string to process */
    $s = "";
}
else
{
    /* Process the search form data */
    if (!isset($isearch_operator))
    {
        $isearch_operator = $isearch_defaultOperator;
    }
    if ($isearch_contentTypeCharset == "utf-8")
    {
        $s = utf8_decode($s);
    }
    /* Clean the search strings */
    $s = isearch_cleanSearchString($s, $isearch_operator);
    isearch_find($s);
    if (!isset($page))
    {
        $page = 1;
    }
    isearch_showResults($page);
}
/* Define the width (in characters) of the search string entry field */
$isearch_searchFormWidth = 40;
/* Include a "Search Internet" button */
$isearch_allowSearchInternet = True;
/* Display the search form */
include("$isearch_path/isearch_form.inc.php");
/* Close the search component */
isearch_close();
include("$isearch_path/isearch_footer.inc.php");
echo <<<EOF
</BODY>
</HTML>
EOF;
?>
</td></tr></table>
<br><br>
<table width="778" border=0 align="center"><tr><td><br></td></tr></table>
<br>
<?include("bottom.html");?>
</body>
</html>
isearch_core.inc.php
--------------------
<?php
if ( !defined('IN_ISEARCH') )
{
    die("Hacking attempt");
}
/* Disable notice errors */
error_reporting(E_ALL ^ E_NOTICE);
/* Convert GET/POST vars */
if (is_array($isearch_get_post_vars))
{
    foreach ($isearch_get_post_vars as $var)
    {
        if (isset($_GET[$var]))
        {
            $$var = $_GET[$var];
        }
        else if (isset($_POST[$var]))
        {
            $$var = $_POST[$var];
        }
    }
}
/* Include configuration options */
include ("$isearch_path/isearch_config.inc.php");
$isearch_version = "1.9i";
/* Set maximim execution time */
ini_set("max_execution_time", $isearch_max_execution_time);
/* Die function - called on a fatal error */
function isearch_die( $error = "unknown" )
{
    echo "<H1>iSearch Error:". $error."</H1>";
    isearch_log($error);
    exit;
}
/* Open the iSearch component */
function isearch_open()
{
    global $isearch_path;
    global $isearch_sql_server, $isearch_sql_username,
$isearch_sql_password, $isearch_sql_database;
    global $isearch_db;
    global $isearch_nextId;
    global $isearch_adminEmail;
    global $isearch_allowedFileExtensions;
    global $isearch_allowDirectories;
    global $isearch_startUrls;
    global $isearch_allowedUrlsBeginning;
    global $isearch_allowedUrls;
    global $isearch_disallowedUrlsBeginning;
    global $isearch_disallowedUrls;
    global $isearch_maxFileSize;
    global $isearch_resultsPerPage;
    global $isearch_followFrames;
    global $isearch_googleStyleResults;
    global $isearch_targetFrame;
    global $isearch_searchLogLastEmailed;
    global $isearch_searchLogEmailDays;
    global $isearch_keepCache;
    global $isearch_langName;
    global $isearch_styleName;
    global $isearch_wizardMode;
    global $isearch_removeGetVars;
    global $isearch_wwwOption;
    global $isearch_stripDefaults;
    global $isearch_robotsDomains;
    global $isearch_robotsExcludes;
    global $isearch_table_info, $isearch_table_urls;
    global $isearch_resultColour;
    global $isearch_languageCode;
    global $isearch_lang;
    $isearch_db = mysql_connect($isearch_sql_server, $isearch_sql_username,
$isearch_sql_password) or isearch_die("Unable to connect to database. Please
check your iSearch MySQL server, username and password configuration
options.");
    mysql_select_db($isearch_sql_database, $isearch_db) or
isearch_die("Unable to select the database. Please check your iSearch MySQL
database configuration option.");
    $resultInfo = mysql_query ("SELECT * FROM $isearch_table_info",
$isearch_db);
    if ($resultInfo)
    {
        $isearch_itemInfo = mysql_fetch_object($resultInfo);
        if ($isearch_itemInfo)
        {
            /* Check whether fields introduced with version 1.5 are present
             * in the table and add them if not.
             */
            if (!isset($isearch_itemInfo->search_log))
            {
                $query = "ALTER TABLE $isearch_table_info ";
                $query .= "ADD allow_directories INT(10) DEFAULT '0' NOT
NULL, ";
                $query .= "ADD max_file_size INT(10) DEFAULT '65536' NOT
NULL, ";
                $query .= "ADD results_per_page INT(10) DEFAULT '10' NOT
NULL, ";
                $query .= "ADD follow_frames INT(10) DEFAULT '0' NOT NULL,
";
                $query .= "ADD google_style_results INT(10) DEFAULT '0' NOT
NULL, ";
                $query .= "ADD target_frame VARCHAR(255) DEFAULT '_self' NOT
NULL, ";
                $query .= "ADD search_log_last_emailed INT(10) NOT NULL, ";
                $query .= "ADD search_log_email_days INT(10) DEFAULT '0' NOT
NULL";
                mysql_query($query, $isearch_db);
            }
            /* Check whether fields introduced with version 1.6 are present
             * in the table and add them if not.
             */
            if (!isset($isearch_itemInfo->lang))
            {
                $query = "ALTER TABLE $isearch_table_urls ";
                $query .= "ADD cache LONGTEXT NOT NULL, ";
                $query .= "ADD size INT(10) NOT NULL, ";
                $query .= "CHANGE words words LONGTEXT NOT NULL, ";
                $query .= "CHANGE bigwords bigwords LONGTEXT NOT NULL, ";
                $query .= "CHANGE keywords keywords LONGTEXT NOT NULL, ";
                $query .= "CHANGE description description LONGTEXT NOT
NULL";
                mysql_query($query, $isearch_db);
                $query = "ALTER TABLE $isearch_table_info ";
                $query .= "ADD keep_cache INT(10) DEFAULT '0' NOT NULL, ";
                $query .= "ADD lang VARCHAR(255) DEFAULT 'english' NOT NULL,
";
                $query .= "ADD style VARCHAR(255) DEFAULT 'classic' NOT
NULL, ";
                $query .= "ADD wizard_mode INT(10) DEFAULT '0' NOT NULL, ";
                $query .= "ADD remove_get_vars TEXT NOT NULL, ";
                mysql_query($query, $isearch_db);
                mysql_query ("INSERT INTO $isearch_table_info
(remove_get_vars) VALUES ('PHPSESSID')", $isearch_db);
            }
            /* Check whether fields introduced with version 1.8 are present
             * in the table and add them if not.
             */
            if (!isset($isearch_itemInfo->www_option))
            {
                $query = "ALTER TABLE $isearch_table_urls ";
                $query .= "ADD base VARCHAR(255) NOT NULL, ";
                $query .= "ADD sig VARCHAR(255) NOT NULL ";
                mysql_query($query, $isearch_db);
                $query = "ALTER TABLE $isearch_table_info ";
                $query .= "ADD allowed_urls_beginning TEXT NOT NULL, ";
                $query .= "ADD disallowed_urls_beginning TEXT NOT NULL, ";
                $query .= "ADD www_option INT(10) DEFAULT '0' NOT NULL, ";
                $query .= "ADD strip_defaults TEXT NOT NULL, ";
                $query .= "ADD robots TEXT NOT NULL, ";
                $query .= "CHANGE start_urls start_urls LONGTEXT NOT NULL,
";
                $query .= "CHANGE allowed_urls allowed_urls LONGTEXT NOT
NULL, ";
                $query .= "CHANGE disallowed_urls disallowed_urls LONGTEXT
NOT NULL";
                mysql_query($query, $isearch_db);
                $resultInfo = mysql_query ("SELECT * FROM
$isearch_table_info", $isearch_db);
            }
        }
    }
    $resultInfo = mysql_query ("SELECT * FROM $isearch_table_info",
$isearch_db);
    if ($resultInfo)
    {
        $isearch_itemInfo = mysql_fetch_object($resultInfo);
        if ($isearch_itemInfo)
        {
            $isearch_nextId = $isearch_itemInfo->next_id;
            $isearch_adminEmail = $isearch_itemInfo->admin_email;
            $isearch_allowedFileExtensions = explode(" ",
$isearch_itemInfo->allowed_file_ext);
            $isearch_startUrls = explode(" ",
$isearch_itemInfo->start_urls);
            $isearch_allowedUrlsBeginning = explode(" ",
$isearch_itemInfo->allowed_urls_beginning);
            $isearch_allowedUrls = explode(" ",
$isearch_itemInfo->allowed_urls);
            $isearch_disallowedUrlsBeginning = explode(" ",
$isearch_itemInfo->disallowed_urls_beginning);
            $isearch_disallowedUrls = explode(" ",
$isearch_itemInfo->disallowed_urls);
            $isearch_maxFileSize = $isearch_itemInfo->max_file_size;
            $isearch_resultsPerPage = $isearch_itemInfo->results_per_page;
            $isearch_followFrames = $isearch_itemInfo->follow_frames;
            $isearch_allowDirectories =
$isearch_itemInfo->allow_directories;
            $isearch_googleStyleResults =
$isearch_itemInfo->google_style_results;
            $isearch_targetFrame = $isearch_itemInfo->target_frame;
            $isearch_searchLogLastEmailed =
$isearch_itemInfo->search_log_last_emailed;
            $isearch_searchLogEmailDays =
$isearch_itemInfo->search_log_email_days;
            $isearch_keepCache = $isearch_itemInfo->keep_cache;
            $isearch_langName = $isearch_itemInfo->lang;
            $isearch_styleName = $isearch_itemInfo->style;
            $isearch_wizardMode = $isearch_itemInfo->wizard_mode;
            $isearch_removeGetVars = explode(" ",
$isearch_itemInfo->remove_get_vars);
            $isearch_wwwOption = $isearch_itemInfo->www_option;
            $isearch_stripDefaults = explode(" ",
$isearch_itemInfo->strip_defaults);
            $isearch_robotsDomains = explode(" ", ereg_replace("#.*$", "",
$isearch_itemInfo->robots));
            $isearch_robotsExcludes = explode(" ", ereg_replace("^[^#]*#",
"", $isearch_itemInfo->robots));
            include ("$isearch_path/lang/$isearch_langName.inc.php");
            return True;
        }
    }
    return False;
}
/* Close the iSearch component */
function isearch_close()
{
    global $isearch_db;
    mysql_close($isearch_db);
}
/* Lock the search tables */
function isearch_lock()
{
    global $isearch_useLocks;
    global $isearch_table_info, $isearch_table_urls;
    global $isearch_db;
    if ($isearch_useLocks)
    {
        mysql_query ("LOCK TABLES $isearch_table_info WRITE", $isearch_db);
        $resultInfo = mysql_query ("SELECT * FROM $isearch_table_info",
$isearch_db);
        if ($resultInfo)
        {
            $isearch_itemInfo = mysql_fetch_object($resultInfo);
            if ($isearch_itemInfo)
            {
                $now = time();
                if ((! $isearch_itemInfo->locked) ||
                    (($now - $isearch_itemInfo->locked_time) >
$isearch_lock_timeout))
                {
                    $isearch_gotLock = True;
                    mysql_query("UPDATE $isearch_table_info SET
locked_time='$now', locked='1' WHERE id='1'", $isearch_db);
                }
            }
        }
        mysql_query ("UNLOCK TABLES", $isearch_db);
        return $isearch_gotLock;
    }
    return True;
}
/* Unlock the search tables */
function isearch_unlock()
{
    global $isearch_useLocks;
    global $isearch_table_info;
    global $isearch_db;
    if ($isearch_useLocks)
    {
        mysql_query("UPDATE $isearch_table_info SET locked='0' WHERE
id='1'", $isearch_db);
    }
}
?>
isearch_search.inc.php
----------------------
<?php
function isearch_clearSearchLog()
{
    global $isearch_table_search_log;
    global $isearch_db;
    mysql_query("DELETE FROM $isearch_table_search_log", $isearch_db);
}
/* Return the contents of the spider log */
function isearch_getSearchLog()
{
    global $isearch_table_search_log;
    global $isearch_db;
    $log = "";
    $resultInfo = mysql_query ("SELECT * FROM $isearch_table_search_log
ORDER BY id", $isearch_db);
    if ($resultInfo)
    {
        while ($isearch_itemInfo = mysql_fetch_object($resultInfo))
        {
            $log .= $isearch_itemInfo->msg . "\n";
        }
    }
    return $log;
}
/* Save the string in the iSearch log file */
function isearch_searchLog($string)
{
    global $isearch_table_search_log;
    global $isearch_adminEmail;
    global $isearch_searchLogEmailDays;
    global $isearch_searchLogLastEmailed;
    global $isearch_table_info;
    global $isearch_db;
    $msg = date("M d, Y, H:i:s - ") . $string;
    mysql_query ("INSERT INTO $isearch_table_search_log (msg) VALUES ('" .
mysql_escape_string($msg) . "')", $isearch_db);
    if ($isearch_searchLogEmailDays > 0)
    {
        $now = time();
        if ($isearch_searchLogLastEmailed + ($isearch_searchLogEmailDays *
60 * 60 * 24) < $now)
        {
            /* Email the search log */
            $mailTo = "$isearch_adminEmail";
            $mailSubject = "iSearch search log";
            $mailBody = "The following searches have been performed on your
site:\n";
            $mailBody .= "\n";
            $mailBody .= isearch_getSearchLog();
            $mailBody .= "\n";
            $mailBody .= "This email is automatically generated by iSearch.
To change how often\n";
            $mailBody .= "this email is sent, please use your iSearch admin
control panel.\n";
            $mailBody .= "\n";
            $mailBody .= "Visit the iSearch home page at
http://www.isearchthenet.com/isearch\n
";
            $mailHeaders = "From: $isearch_adminEmail\n";
            if (mail($mailTo, $mailSubject, $mailBody, $mailHeaders))
            {
                mysql_query("UPDATE $isearch_table_info SET
search_log_last_emailed='$now'", $isearch_db);
                $isearch_searchLogLastEmailed = $now;
                isearch_clearSearchLog();
            }
        }
    }
}
/* Clean the search string
 * Parameters:
 *  $data     : Contains the string to clean
 *  $operator : Logical operator to insert between words. Should be "AND",
"OR"
 *              or "" (uses the default defined in isearch_config.inc.php)
 */
function isearch_cleanSearchString($data, $operator = "")
{
    global $isearch_defaultOperator;
    global $isearch_8bitCharset;
    if ("$operator" == "")
    {
        $operator = $isearch_defaultOperator;
    }
    if ($isearch_8bitCharset)
    {
        /* Convert to lower case, doing accented character conversion
correctly */
        $data = strtr($data,
"ABCDEFGHIJKLMNOPQRSTUVWXYZАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮ" . chr(0x8a) .
chr(0x8e) ,
"abcdefghijklmnopqrstuvwxyzабвгдежзийклмнопрстуфхцчшщъыьэю" . chr(0x9a) .
chr(0x9e) );
        /* Strip out all characters except numeric, alpha, whitespace, quote
or bracket */
        $data = preg_replace('/([^-\.,@0-9a-z' . chr(0xbf) . '-' . chr(0xff)
. chr(0x9a) . chr(0x9e) . '\s\)\("])/e', "", $data);
    }
    /* Ensure that quotes and brackets are surrounded by spaces */
    $data = ereg_replace('"', ' " ', $data);
    $data = ereg_replace("\\(", ' ( ', $data);
    $data = ereg_replace("\\)", ' ) ', $data);
    /* Compact all white space into a single space character */
    $data = ereg_replace("[[:space:]]+", " ", $data);
    /* Strip white space from beginning and end of the string */
    $data = trim($data);
    /* Remove any "AND" and "OR" at beginning or end of search string */
    $data = eregi_replace("(^and |^or | and$| or$)", "", $data);
    /* Replace repeated AND, OR or NOT words */
    $data = eregi_replace(" and (and |or )+", " and ", $data);
    $data = eregi_replace(" or (and |or )+", " or ", $data);
    $data = eregi_replace(" not not ", " ", $data);
    $words = explode(" ", $data);
    $data = "";
    $inQuote = False;
    $expectWord = True;
    $bracketCount = 0;
    for ($i = 0; $i < count($words); $i++)
    {
        if ($inQuote)
        {
            if ($words[$i] == '"')
            {
                $inQuote = False;
                $expectWord = False;
                $data .= ' "';
            }
            else
            {
                $data .= " $words[$i]";
            }
        }
        else
        {
            switch ($words[$i])
            {
                case '"':
                    $inQuote = True;
                    if (!$expectWord)
                    {
                        $data .= " $operator";
                    }
                    $data .= ' "';
                    break;
                case '(':
                    if (!$expectWord)
                    {
                        $data .= " $operator";
                    }
                    $data .= ' (';
                    $bracketCount ++;
                    $expectWord = True;
                    break;
                case ')':
                    if (($bracketCount > 0) && ($expectWord))
                    {
                        $data .= ' )';
                        $bracketCount --;
                    }
                    $expectWord = False;
                    break;
                case "and":
                case "or":
                case "AND":
                case "OR":
                    if (!$expectWord)
                    {
                        $data .= " " . strtoupper($words[$i]);
                        $expectWord = True;
                    }
                    break;
                case "not":
                case "NOT":
                    if (!$expectWord)
                    {
                        $data .= " $operator";
                        $expectWord = True;
                    }
                    $data .= " NOT";
                    break;
                default:
                    if (!$expectWord)
                    {
                        /* No operator between this word and the previos
one.
                         * Insert an AND
                         */
                        $data .= " $operator";
                    }
                    $data .= " $words[$i]";
                    $expectWord = False;
                    break;
            }
        }
    }
    if ($inQuote)
    {
        /* Incorrect number of quotes - add a final closing quote */
        $data .= ' "';
    }
    while ($bracketCount > 0)
    {
        $data .= ' )';
        $bracketCount --;
    }
    /* Strip white space from the beginning and end of the string */
    $data = trim($data);
    return $data;
}
/* Add a URL to the array of search results.
 */
function isearch_addResult($url, $title, $description, $size, $ranking)
{
    global $isearch_resultArray;
    $isearch_resultArray[] = array(
                            'url' => $url,
                            'title' => $title,
                            'description' => $description,
                            'size' => $size,
                            'ranking' => $ranking );
}
/* Add to the ranking of a URL in array of search results.
 */
function isearch_addResultRanking($url, $ranking = 1)
{
    global $isearch_resultArray;
    /* Find the URL in the result array */
    for ($i = 0; $i < count($isearch_resultArray); $i++)
    {
        if ($isearch_resultArray[$i]['url'] == $url)
        {
            $isearch_resultArray[$i]['ranking'] += $ranking;
            break;
        }
    }
}
/* Sort the results array, based on ranking order */
function isearch_sortResults()
{
    global $isearch_resultArray;
    if (isset($isearch_resultArray))
    {
        $finished = False;
        while (! $finished)
        {
            $finished = True;
            for ($i = 1; $i < count($isearch_resultArray); $i++)
            {
                if ($isearch_resultArray[$i-1]['ranking'] <
$isearch_resultArray[$i]['ranking'])
                {
                    /* Swap these 2 results. */
                    $temp = $isearch_resultArray[$i-1];
                    $isearch_resultArray[$i-1] = $isearch_resultArray[$i];
                    $isearch_resultArray[$i] = $temp;
                    $finished = False;
                }
            }
        }
    }
}
/* Search the site for a string. Returns the number of matches found. */
function isearch_find($searchString)
{
    global $isearch_searchString;
    global $isearch_table_urls;
    global $isearch_resultArray;
    global $isearch_db;
    global $isearch_rankingBodyWord;
    global $isearch_rankingBigBodyWord;
    global $isearch_rankingKeyword;
    global $isearch_maxMatches;
    $isearch_searchString = $searchString;
    /* Build the query string */
    $query = "SELECT * FROM $isearch_table_urls WHERE";
    $not = "";
    $words = explode(" ", $isearch_searchString);
    for ($i = 0; $i < count($words); $i++)
    {
        if (($words[$i] == "AND") || ($words[$i] == "OR"))
        {
            $query .= " " . $words[$i];
        }
        else if ($words[$i] == ")")
        {
            $query .= " )";
            $not = "";
        }
        else if ($words[$i] == "(")
        {
            $query .= " $not(";
            $not = "";
        }
        else if ($words[$i] == "NOT")
        {
            $not = "NOT ";
        }
        else
        {
            $query .= " _words_ " . $not . "REGEXP ";
            if ($words[$i] == '"')
            {
                $i++;
                $exp = '[ \.,@-]';
                while (($words[$i] != "") && ($words[$i] != '"'))
                {
                    $exp .= $words[$i] . '[ \.,@-]';
                    $searchwords[] = $words[$i];
                    $i++;
                }
                $query .= '"' . $exp . '"';
            }
            else
            {
                $query .= '"' . $words[$i] . '"';
                $searchwords[] = $words[$i];
            }
            $not = "";
        }
    }
    if (!isset($searchwords))
    {
        /* No search words were found. */
        return 0;
    }
    /* Perform 3 searches. The first one searches through all words on the
page,
     * including keywords, to produce a list of pages that match. The next 2
     * searches may allow pages that should not match (e.g. if the search
term
     * is "lion AND NOT tiger" and "lion" appears in the keywords, "tiger"
does
     * not appear in the keywords, but does in the page body).
     */
    $resultWords = mysql_query(ereg_replace(" _words_ ", " words ", $query)
. " LIMIT $isearch_maxMatches", $isearch_db);
    $resultKeyWords = mysql_query(ereg_replace(" _words_ ", " keywords ",
$query), $isearch_db);
    $resultBigWords = mysql_query(ereg_replace(" _words_ ", " bigwords ",
$query), $isearch_db);
    /* Clear the result array */
    unset($isearch_resultArray);
    if ($resultWords)
    {
        while ($item = mysql_fetch_object($resultWords))
        {
            $temp = explode("#", $item->words);
            $body = $temp[0];
            $ranking = 0;
            foreach ($searchwords as $word)
            {
                $pos = -1;
                do
                {
                    $pos ++;
                    if ($pos > 0)
                    {
                        $ranking += $isearch_rankingBodyWord;
                    }
                    $pos = strpos($body, $word, $pos);
                } while ($pos > 0);
            }
            isearch_addResult($item->url, $item->title, $item->description,
$item->size, $ranking);
        }
    }
    if ($resultKeyWords)
    {
        while ($item = mysql_fetch_object($resultKeyWords))
        {
            $body = $item->keywords;
            $ranking = 0;
            foreach ($searchwords as $word)
            {
                $pos = -1;
                do
                {
                    $pos ++;
                    if ($pos > 0)
                    {
                        $ranking += $isearch_rankingKeyword;
                    }
                    $pos = strpos($body, $word, $pos);
                } while ($pos > 0);
            }
            if ($ranking)
            {
                /* Increase ranking for this result */
                isearch_addResultRanking($item->url, $ranking);
            }
        }
    }
    if ($resultBigWords)
    {
        while ($item = mysql_fetch_object($resultBigWords))
        {
            $body = $item->bigwords;
            $ranking = 0;
            foreach ($searchwords as $word)
            {
                $pos = -1;
                do
                {
                    $pos ++;
                    if ($pos > 0)
                    {
                        $ranking += $isearch_rankingBigBodyWord;
                    }
                    $pos = strpos($body, $word, $pos);
                } while ($pos > 0);
            }
            if ($ranking)
            {
                /* Increase ranking for this result */
                isearch_addResultRanking($item->url, $ranking);
            }
        }
    }
    /* Sort the result array */
    isearch_sortResults();
    isearch_searchLog("$isearch_searchString");
    return count($isearch_resultArray);
}
function isearch_getHighlightWords($searchString)
{
    $temp = explode(" ", $searchString);
    $inQuote = False;
    $not = False;
    for ($i = 0; $i < count($temp); $i++)
    {
        if ($inQuote)
        {
            if ($temp[$i] == '"')
            {
                $inQuote = False;
            }
            else
            {
                $highlightWords[] = $temp[$i];
            }
        }
        else
        {
            if ($temp[$i] == '"')
            {
                $inQuote = True;
            }
            else if ($temp[$i] == "NOT")
            {
                $not = !($not);
            }
            else if (($temp[$i] != "AND") && ($temp[$i] != "OR") &&
($temp[$i] != ")") && ($temp[$i] != "("))
            {
                $highlightWords[] = $temp[$i];
            }
        }
    }
    return $highlightWords;
}
function isearch_googleStyleDescription($resultIndex, $highlightWords)
{
    global $isearch_resultArray;
    global $isearch_table_urls;
    global $isearch_db;
    global $isearch_8bitCharset;
    $isearch_googleMinBefore = 5;
    $isearch_googleMinAfter = 10;
    $isearch_googleMaxWordCount = 32;
    $item = $isearch_resultArray[$resultIndex];
    $url = $item['url'];
    $result = mysql_query ("SELECT words FROM $isearch_table_urls WHERE
url='$url'", $isearch_db);
    if (($result) && ($resultItem = mysql_fetch_object($result)))
    {
        $words = explode(" ", $resultItem->words);
    }
    else
    {
        /* Query failed */
        return $item['description'];
    }
    if (count($highlightWords) == 0)
    {
        return $item['description'];
    }
    /* Find the position of each word to highlight */
    for ($j = 0; $j < count($words); $j++)
    {
        for ($i = 0; $i < count($highlightWords); $i++)
        {
            if (eregi($highlightWords[$i], $words[$j]))
            {
                $pos[] = $j;
                break;  /* Avoid multiple entries in pos[] on same word */
            }
        }
    }
    if (count($pos) == 0)
    {
        /* This should never happen ! */
        $pos[] = 0;
        $isearch_googleMinAfter = 999;
    }
    else if (count($pos) == 1)
    {
        /* Increase the number of words displayed before and after the hit
word */
        $isearch_googleMinBefore *= 2;
        $isearch_googleMinAfter = 999;
    }
    if ($isearch_8bitCharset)
    {
        $trans = get_html_translation_table(HTML_ENTITIES);
    }
    else
    {
        $trans = get_html_translation_table(HTML_SPECIALCHARS);
    }
    $wordCount = 0;
    $posCount = 0;
    $description = "";
    while (($wordCount < $isearch_googleMaxWordCount) && ($posCount <
count($pos)))
    {
        $startPos = $pos[$posCount] - $isearch_googleMinBefore;
        if ($startPos < 0)
        {
            $startPos = 0;
        }
        $endPos = $pos[$posCount] + $isearch_googleMinAfter + 1;
        if (($posCount == 0) && ($startPos != 0))
        {
            $description = "... ";
        }
        for ($i = $startPos; $i < $endPos; $i++)
        {
            $wordCount ++;
            if ($wordCount > $isearch_googleMaxWordCount)
            {
                break;
            }
            $lastWord = $i;
            /* Check whether this is a matched word */
            if (($posCount < count($pos)) && ($i == $pos[$posCount]))
            {
                $description .= "<FONT class=\"highlight\">" .
strtr($words[$i], $trans) . "</FONT> ";
                $posCount ++;
                if ($i + $isearch_googleMinAfter + 1 > $endPos)
                {
                    $endPos = $i + $isearch_googleMinAfter + 1;
                }
            }
            else
            {
                $description .= strtr($words[$i], $trans) . " ";
            }
            if (($posCount+1 < count($pos)) && ($i +
$isearch_googleMinBefore >= $pos[$posCount+1]))
            {
                if ($pos[$posCount + 1] > $endPos)
                {
                    $endPos = $pos[$posCount + 1];
                }
            }
        }
        $description .= "... ";
    }
    if ($wordCount < $isearch_googleMaxWordCount)
    {
        $i = $lastWord + 1;
        while (($wordCount < $isearch_googleMaxWordCount) && ($i <
count($words)))
        {
            $wordCount ++;
            $description .= $words[$i] . " ";
            $i++;
        }
        $description .= "... ";
    }
    return $description;
}
function isearch_highlight($in, $highlightWords)
{
    $words = explode(" ", $in);
    /* Search each word, and highlight  */
    for ($j = 0; $j < count($words); $j++)
    {
        for ($i = 0; $i < count($highlightWords); $i++)
        {
            if (eregi($highlightWords[$i], $words[$j]))
            {
                $words[$j] = "<FONT class=\"highlight\">" . $words[$j] .
"</FONT>";
                break;
            }
        }
    }
    return implode(" ", $words);
}
/* Show results of a site search */
function isearch_showResults($pageNumber = 1)
{
    global $isearch_searchString;
    global $isearch_resultArray;
    global $isearch_resultsPerPage;
    global $isearch_googleStyleResults;
    global $isearch_targetFrame;
    global $isearch_keepCache;
    global $isearch_lang;
    global $isearch_version;
    global $isearch_8bitCharset;
    global $isearch_contentTypeCharset;
    $resultCount = count($isearch_resultArray);
    $maxPage = ceil($resultCount / $isearch_resultsPerPage);
    if ($pageNumber < 1)
    {
        $pageNumber = 1;
    }
    if ($pageNumber > $maxPage)
    {
        $pageNumber = $maxPage;
    }
    $lastResult = $pageNumber * $isearch_resultsPerPage;
    $firstResult = $lastResult - $isearch_resultsPerPage + 1;
    if ($lastResult > $resultCount)
    {
        $lastResult = $resultCount;
    }
    if ($firstResult < 0)
    {
        $firstResult = 0;
    }
    if ($isearch_8bitCharset)
    {
        $trans = get_html_translation_table(HTML_ENTITIES);
    }
    else
    {
        $trans = get_html_translation_table(HTML_SPECIALCHARS);
    }
    $htmlSearchString = strtr($isearch_searchString, $trans);
    if ($isearch_contentTypeCharset == "utf-8")
    {
        $urlSearchString = urlencode(utf8_encode($isearch_searchString));
    }
    else
    {
        $urlSearchString = urlencode($isearch_searchString);
    }
    $patterns[] = "/(%s)/";
    $replacements[] = "<FONT class=\"search\">" . $htmlSearchString .
"</FONT>";
    $patterns[] = "/(%f)/";
    $replacements[] = $firstResult;
    $patterns[] = "/(%l)/";
    $replacements[] = $lastResult;
    $patterns[] = "/(%t)/";
    $replacements[] = $resultCount;
    foreach (array_keys($isearch_lang) as $key)
    {
        $isearch_lang_converted[$key] = preg_replace($patterns,
$replacements, $isearch_lang[$key]);
    }
    echo "<TABLE class=\"head\" WIDTH=\"100%\" BORDER=\"0\"><TR
class=\"head\">\n";
    echo "<TD class=\"head\">" . $isearch_lang_converted['results_head2'] .
"</TD>\n";
    echo "<TD class=\"head\" align=\"right\">" .
$isearch_lang_converted['results_head3'] . "</TD>\n";
    echo "</TR></TABLE><BR>\n";
    $highlightWords = isearch_getHighlightWords($isearch_searchString);
    if ($resultCount > 0)
    {
        for ($i = $firstResult-1; $i < $lastResult; $i++)
        {
            $item = $isearch_resultArray[$i];
            $url = $item['url'];
            $title = $item['title'];
            /* Use google style results if explicitly set, or if there is no
             * description for this page
             */
            $description = $item['description'];
            if (($isearch_googleStyleResults) || ("$description" == ""))
            {
                $description = isearch_googleStyleDescription($i,
$highlightWords);
            }
            else
            {
                /* Highlight searched words */
                $description = isearch_highlight($description,
$highlightWords);
            }
            echo "<p align=justify><A class=\"title\" HREF=\"$url\"
TARGET=\"$isearch_targetFrame\">" . $title . "</A><BR>\n";
            echo "<FONT class=\"description\">" . $description .
"</FONT><BR>\n";
            echo "<A class=\"url\" HREF=\"$url\"
TARGET=\"$isearch_targetFrame\">" . $url . "</A>";
            echo "<FONT class=\"size\">&nbsp;-&nbsp;" . ceil($item['size'] /
1024) . 'k';
            if ($isearch_keepCache)
            {
                echo "&nbsp;-&nbsp;";
            }
            echo "</FONT>";
            if ($isearch_keepCache)
            {
                echo "<A class=\"viewcache\" HREF=\"viewcache.php?url=" .
urlencode($url) . "\">" . $isearch_lang_converted['cached'] . "</A>";
            }
            echo "<BR><BR>\n";
        }
        echo "<BR>\n";
        /* If more than one results page, display "previous" and/or "next"
links */
        if ($maxPage > 1)
        {
            echo "<TABLE class=\"prevnext\" BORDER=0 WIDTH=\"100%\">\n";
            echo "<TR class=\"prevnext\">\n";
            if ($pageNumber > 1)
            {
                $prevPageNumber = $pageNumber - 1;
                echo "<TD class=\"prevnext\" width=\"10%\"
align=\"left\"><DIV align=\"left\">&nbsp;&nbsp;<A class=\"prevnext\"
HREF=\"index.php?action=search&s=$urlSearchString&page=$prevPageNumber\">" .
$isearch_lang_converted['previous'] . "</A></DIV></TD>\n";
            }
            else
            {
                echo "<TD class=\"prevnext\" width=\"10%\"
align=\"left\">&nbsp;</TD>\n";
            }
            echo "<TD class=\"prevnext\" width=\"80%\"
align=\"center\"><CENTER>&nbsp;";
            for ($i = 1; $i <= $maxPage; $i++)
            {
                if ($i == $pageNumber)
                {
                    echo "$i&nbsp;";
                }
                else
                {
                    echo "<A class=\"prevnext\"
HREF=\"index.php?action=search&s=$urlSearchString&page=$i\">$i</A>&nbsp;";
                }
            }
            echo "</CENTER></TD>";
            if ($pageNumber < $maxPage)
            {
                $nextPageNumber = $pageNumber + 1;
                echo "<TD class=\"prevnext\" width=\"10%\"
align=\"right\"><DIV align=\"right\"><A class=\"prevnext\"
HREF=\"index.php?action=search&s=$urlSearchString&page=$nextPageNumber\">" .
$isearch_lang_converted['next'] . "</A>&nbsp;&nbsp;</DIV></TD>\n";
            }
            else
            {
                echo "<TD class=\"prevnext\" width=\"10%\"
align=\"left\">&nbsp;</TD>\n";
            }
            echo "</TR>\n";
            echo "</TABLE>\n";
        }
        echo "<BR>\n";
    }
    else
    {
        echo "<H2 class=\"nomatch\" align=center>" .
$isearch_lang_converted['nomatch'] . "</H2><BR><BR>\n";
    }
}
/* Show the site map */
function isearch_showSiteMap($currentId = -1, $depth = 0, $mapType = -1)
{
    global $isearch_table_urls;
    global $isearch_targetFrame;
    global $isearch_db;
    global $isearch_defaultSitemapType;
    if ($mapType < 0)
    {
        $mapType = $isearch_defaultSitemapType;
    }
    switch ($mapType)
    {
        case 0:
            /* Show site map in link order */
            if ($currentId == -1)
            {
                mysql_query ("LOCK TABLES $isearch_table_urls READ",
$isearch_db);
            }
            $result = mysql_query ("SELECT id, title, url FROM
$isearch_table_urls WHERE referrer_id='$currentId'", $isearch_db);
            if (($result) && (mysql_num_rows($result) > 0))
            {
                echo "<UL>\n";
                while ($item = mysql_fetch_object($result))
                {
                    echo "<LI><A HREF=\"$item->url\"
TARGET=\"$isearch_targetFrame\">$item->title</A><BR></LI>\n";
                    if (($item->id > -1) && ($depth < 10))
                    {
                        isearch_showSiteMap($item->id, $depth+1, 0);
                    }
                }
                echo "</UL>\n";
            }
        break;
        case 1: /* Flat unordered */
        case 2: /* Flat ordered by URL */
        case 3: /* Flat ordered by title */
            if ($mapType == 1)
            {
                $order = "";
            }
            else if ($mapType == 2)
            {
                $order = "ORDER BY url";
            }
            else if ($mapType == 3)
            {
                $order = "ORDER BY title";
            }
            /* Show flat site map (ordered by url) */
            $result = mysql_query ("SELECT id, title, url FROM
$isearch_table_urls $order", $isearch_db);
            if (($result) && (mysql_num_rows($result) > 0))
            {
                echo "<UL>\n";
                while ($item = mysql_fetch_object($result))
                {
                    echo "<LI><A HREF=\"$item->url\"
TARGET=\"$isearch_targetFrame\">$item->title</A><BR></LI>\n";
                }
                echo "</UL>\n";
            }
            else
            {
                echo "<P>No pages found.\n";
            }
        break;
        case 4: /* URL hierarcial */
            $result = mysql_query ("SELECT id, title, url FROM
$isearch_table_urls ORDER BY url", $isearch_db);
            if (($result) && (mysql_num_rows($result) > 0))
            {
                $levelCount = 0;
                while ($item = mysql_fetch_object($result))
                {
                    $temp = explode("/",
ereg_replace('(^.*://)|(\?.*$)|(/$)', "", $item->url));
                    $myLevel = count($temp) - 1;
                    if ($myLevel > $levelCount)
                    {
                        echo str_repeat("<UL>\n", $myLevel - $levelCount);
                    }
                    if ($myLevel < $levelCount)
                    {
                        echo str_repeat("</UL>\n", $levelCount - $myLevel);
                    }
                    $levelCount = $myLevel;
                    echo "<LI><A HREF=\"$item->url\"
TARGET=\"$isearch_targetFrame\">$item->title</A><BR></LI>\n";
                }
                echo str_repeat("</UL>\n", $levelCount);
            }
            else
            {
                echo "<P>No pages found.\n";
            }
        break;
    }
    if ($currentId == -1)
    {
        mysql_query ("UNLOCK TABLES", $isearch_db);
    }
}
?>

help :(
nessuno lo usa questo script?
solo per confrontarmi con qualcuno e vedere se è possibile mettere in "cima"
ai risultati gli url che contengono la prola ricercata...
Bye..!!!
Riccardo.