Пример #1
0
function main()
{
    if (strcmp('4.1.0', phpversion()) > 0) {
        die("Error: PHP version 4.1.0 or above required!");
    }
    if (!($file = fopen("search.idx", "rb"))) {
        die("Error: Search index file could NOT be opened!");
    }
    if (readHeader($file) != "DOXS") {
        die("Error: Header of index file is invalid!");
    }
    $query = "";
    if (array_key_exists("query", $_GET)) {
        $query = $_GET["query"];
    }
    echo "<input class=\"search\" type=\"text\" name=\"query\" value=\"{$query}\" size=\"20\" accesskey=\"s\"/>\n";
    echo "</span>\n";
    echo "</form>\n";
    echo "</div>\n";
    $results = array();
    $requiredWords = array();
    $forbiddenWords = array();
    $foundWords = array();
    $word = strtok($query, " ");
    while ($word) {
        if ($word[0] == '+') {
            $word = substr($word, 1);
            $requiredWords[] = $word;
        }
        if ($word[0] == '-') {
            $word = substr($word, 1);
            $forbiddenWords[] = $word;
        }
        if (!in_array($word, $foundWords)) {
            $foundWords[] = $word;
            search($file, $word, $results);
        }
        $word = strtok(" ");
    }
    $docs = array();
    combine_results($results, $docs);
    // filter out documents with forbidden word or that do not contain
    // required words
    $filteredDocs = filter_results($docs, $requiredWords, $forbiddenWords);
    // sort the results based on rank
    $sorted = array();
    sort_results($filteredDocs, $sorted);
    // report results to the user
    report_results($sorted);
    fclose($file);
}
function search()
{
    if (strcmp('4.1.0', phpversion()) > 0) {
        die("Error: PHP version 4.1.0 or above required!");
    }
    $paths = paths();
    $files = array();
    $j = 0;
    for ($i = 0; $i < sizeof($paths); $i++) {
        if (!($f = @fopen($paths[$i] . "search.idx", "rb"))) {
            die("Error: Search index file could NOT be opened!");
            continue;
        }
        $files[$j++] = $f;
        if (readHeader($f) != "DOXS") {
            die("Error: Header of index file is invalid!");
        }
    }
    $query = "";
    if (array_key_exists("query", $_GET)) {
        $query = $_GET["query"];
    }
    //end_form($query);
    echo "&nbsp;\n<div class=\"searchresults\">\n";
    $results = array();
    $requiredWords = array();
    $forbiddenWords = array();
    $foundWords = array();
    $word = strtok($query, " ");
    while ($word) {
        if ($word[0] == '+') {
            $word = substr($word, 1);
            $requiredWords[] = $word;
        }
        if ($word[0] == '-') {
            $word = substr($word, 1);
            $forbiddenWords[] = $word;
        }
        if (!in_array($word, $foundWords)) {
            $foundWords[] = $word;
            for ($i = 0; $i < sizeof($files); $i++) {
                do_search($paths[$i], $files[$i], strtolower($word), $results);
            }
        }
        $word = strtok(" ");
    }
    $docs = array();
    combine_results($results, $docs);
    // filter out documents with forbidden word or that do not contain
    // required words
    $filteredDocs = filter_results($docs, $requiredWords, $forbiddenWords);
    // sort the results based on rank
    $sorted = array();
    sort_results($filteredDocs, $sorted);
    // report results to the user
    report_results($sorted);
    echo "</div>\n";
    foreach ($files as $file) {
        fclose($file);
    }
}
Пример #3
0
function main()
{
    if (strcmp('4.1.0', phpversion()) > 0) {
        die("Error: PHP version 4.1.0 or above required!");
    }
    if (!($file = fopen("search.idx", "rb"))) {
        die("Error: Search index file could NOT be opened!");
    }
    if (readHeader($file) != "DOXS") {
        die("Error: Header of index file is invalid!");
    }
    $query = "";
    if (array_key_exists("query", $_GET)) {
        $query = $_GET["query"];
    }
    end_form(ereg_replace("[^[:alnum:]:\\.\\t ]", " ", $query));
    echo "&nbsp;\n<div class=\"searchresults\">\n";
    $results = array();
    $requiredWords = array();
    $forbiddenWords = array();
    $foundWords = array();
    $word = strtok($query, " ");
    while ($word) {
        if ($word[0] == '+') {
            $word = substr($word, 1);
            $requiredWords[] = $word;
        }
        if ($word[0] == '-') {
            $word = substr($word, 1);
            $forbiddenWords[] = $word;
        }
        if (!in_array($word, $foundWords)) {
            $foundWords[] = $word;
            search($file, strtolower($word), $results);
        }
        $word = strtok(" ");
    }
    $docs = array();
    combine_results($results, $docs);
    // filter out documents with forbidden word or that do not contain
    // required words
    $filteredDocs = filter_results($docs, $requiredWords, $forbiddenWords);
    // sort the results based on rank
    $sorted = array();
    sort_results($filteredDocs, $sorted);
    // report results to the user
    report_results($sorted);
    echo "</div>\n";
    fclose($file);
}
Пример #4
0
function main($idxfile)
{
    if (strcmp('4.1.0', phpversion()) > 0) {
        die("Error: PHP version 4.1.0 or above required!");
    }
    if (!($file = fopen($idxfile, "rb"))) {
        die("Error: Search index file could NOT be opened!");
    }
    if (readHeader($file) != "DOXS") {
        die("Error: Header of index file is invalid!");
    }
    $query = "";
    if (array_key_exists("query", $_GET)) {
        $query = $_GET["query"];
    }
    $results = array();
    $requiredWords = array();
    $forbiddenWords = array();
    $foundWords = array();
    $word = strtolower(strtok($query, " "));
    while ($word) {
        if ($word[0] == '+') {
            $word = substr($word, 1);
            $requiredWords[] = $word;
        }
        if ($word[0] == '-') {
            $word = substr($word, 1);
            $forbiddenWords[] = $word;
        }
        if (!in_array($word, $foundWords)) {
            $foundWords[] = $word;
            search($file, $word, $results);
        }
        $word = strtolower(strtok(" "));
    }
    $docs = array();
    combine_results($results, $docs);
    // filter out documents with forbidden word or that do not contain
    // required words
    $filteredDocs = filter_results($docs, $requiredWords, $forbiddenWords);
    // normalize rankings so they are in the range [0-100]
    normalize_ranking($filteredDocs);
    // sort the results based on rank
    $sorted = array();
    sort_results($filteredDocs, $sorted);
    // report results to the user
    report_results($sorted);
    fclose($file);
}