Exemplo n.º 1
0
function getTopResults($queries, $todown, $msnkey, $culture_info)
{
    // create list of URLs
    $allURLs = new Urls();
    $i = 0;
    foreach ($queries as $query) {
        $query = mb_ereg_replace("/[^\\w\\d]/g", "", $query);
        $query = "'" . trim($query) . "'";
        $i++;
        try {
            $searchres = fetchBingResults($query, $todown, $msnkey, $culture_info);
        } catch (Exception $e) {
            print_error("exception in querying MSN!\n");
        }
        foreach ($searchres as $hit) {
            $ahit = new oneUrl();
            $ahit->mainUrl = $hit;
            $ahit->queryID = md5($hit);
            $ahit->msUrl = $hit;
            $ahit->counter = 1;
            $allURLs->addUrl($ahit);
        }
        // end parsing results
    }
    // end sending queries: we have top x results
    return $allURLs->getMax($todown);
}
Exemplo n.º 2
0
function test_global_search()
{
    // method sends a few queries to test search
    global $CFG;
    require_once $CFG->dirroot . '/plagiarism/crot/locallib.php';
    // testing global connectivity
    echo "Testing global connectivity...<br>";
    // read file from global bing web site
    $infile = @file_get_contents("http://www.bing.com/siteowner/s/siteowner/Logo_63x23_Dark.png", FILE_BINARY);
    if (strlen($infile) > 0 && substr($infile, 1, 3) == 'PNG') {
        // print the file size
        echo "<i>Bing.com is accessible from your server - <font color=\"green\"><b>OK</b></font></i><br><hr>";
    } else {
        echo "can not reach bing.com<br>";
    }
    // testing Bing search
    $plagiarismsettings = (array) get_config('plagiarism');
    $msnkey = $plagiarismsettings['crot_live_key'];
    $culture_info = $plagiarismsettings['crot_culture_info'];
    $todown = $plagiarismsettings['crot_number_of_web_documents'];
    $query = "Crot for Moodle";
    $query = "'" . trim($query) . "'";
    echo "Testing global search settings for Bing...<br>";
    try {
        $request = 'http://api.bing.net/xml.aspx?Appid=' . $msnkey . '&sources=web&Query=' . urlencode($query) . '&culture=' . $culture_info . '&Web.Options=DisableHostCollapsing+DisableQueryAlterations' . '&Options=DisableLocationDetection';
        echo "Sending query:" . $request;
        $searches = fetchBingResults($query, $todown, $msnkey, $culture_info);
    } catch (Exception $e) {
        print_error("exception in querying Bing!\n");
    }
    $i = 1;
    if ($searches) {
        echo "<i>- <font color=\"green\"><b>OK</b></font></i><hr>";
        echo "<b>Search results:</b><br>";
        echo "Top links for <i>" . $query . "</i> query:<br>";
        foreach ($searches as $hit) {
            echo "link {$i}:" . substr($hit, 0, 60) . "<br>";
            $i++;
        }
    } else {
        echo "<i> - <font color=\"red\"><b>ERROR!!!</b></font></i><hr>";
    }
    echo "<script type=\"text/javascript\">alert(\"Test is over\");</script>";
    flush();
}