示例#1
0
function get_search_engine_results($search_query, $engine_array, $weight_array = null, $reverse = 0)
{
    foreach ($engine_array as $engine_type) {
        switch ($engine_type) {
            case 'google':
                $engine_object = new GoogleSearch();
                break;
            case 'bing':
                $engine_object = new BingSearch();
                break;
            default:
                return 0;
        }
        $res = $engine_object->perform_search($search_query);
        $object_array[] = $engine_object;
    }
    # Construct the return array
    $return_array = array();
    $no_more_results = 0;
    if ($weight_array) {
        # Return results in a weighted fashion
        while ($no_more_results == 0) {
            $rand = mt_rand(1, (int) array_sum($weight_array));
            foreach ($weight_array as $key => $value) {
                $rand -= $value;
                if ($rand <= 0) {
                    $result = $object_array[$key]->return_next_result($reverse);
                    break;
                }
            }
            if ($result) {
                $return_array[] = $result;
            } else {
                $no_more_results = 1;
            }
        }
    } else {
        # Return normal list of results ( [Response 0 for engine 0], [Response 0 for engine 1],
        # [Response 1 for engine 0]. [Response 1 for engine 1] ..... [Response n for engine 2] )
        while ($no_more_results == 0) {
            foreach ($object_array as $search_object) {
                $result = $search_object->return_next_result($reverse);
                if ($result) {
                    $return_array[] = $result;
                } else {
                    $no_more_results = 1;
                }
            }
        }
    }
    return $return_array;
}
示例#2
0
<?php

include 'class.BingSearch.php';
$bing = new BingSearch('Ayesh Karunaratne', 5000);
$bing->set_fetcher('curl');
$bing->debug_url();
//$bing->next_page();
$bing->debug_url();
$bing->search();