Example #1
0
 public function search($searchstring)
 {
     $q_house = '';
     if (ctype_digit(get_http_var('house'))) {
         $q_house = get_http_var('house');
     }
     $wtt = get_http_var('wtt');
     if ($wtt) {
         $q_house = 2;
     }
     # Fetch the results
     $data = \MySociety\TheyWorkForYou\Utility\Search::searchByUsage($searchstring, $q_house);
     $data['house'] = $q_house;
     $data['search_type'] = 'person';
     return $data;
 }
Example #2
0
function _api_getHansard_search($array)
{
    $search = isset($array['s']) ? trim($array['s']) : '';
    $pid = trim($array['pid']);
    $type = isset($array['type']) ? $array['type'] : '';
    $search = filter_user_input($search, 'strict');
    if ($pid) {
        $search .= ($search ? ' ' : '') . 'speaker:' . $pid;
    }
    if ($type) {
        $search .= " section:" . $type;
    }
    $o = get_http_var('order');
    if ($o == 'p') {
        $data = \MySociety\TheyWorkForYou\Utility\Search::searchByUsage($search);
        $out = array();
        if (!isset($data['speakers'])) {
            $data['speakers'] = array();
        }
        foreach ($data['speakers'] as $pid => $s) {
            $out[$pid] = array('house' => $s['house'], 'name' => $s['name'], 'party' => $s['party'], 'count' => $s['count'], 'mindate' => substr($s['pmindate'], 0, 7), 'maxdate' => substr($s['pmaxdate'], 0, 7));
        }
        api_output($out);
        return;
    }
    global $SEARCHENGINE;
    $SEARCHENGINE = new SEARCHENGINE($search);
    if (!$SEARCHENGINE->valid) {
        api_error('Invalid search term');
        return;
    }
    #    $query_desc_short = $SEARCHENGINE->query_description_short();
    $pagenum = get_http_var('page');
    $args = array('s' => $search, 'p' => $pagenum, 'num' => get_http_var('num'), 'pop' => 1, 'o' => $o == 'd' || $o == 'r' ? $o : 'd');
    $LIST = new HANSARDLIST();
    $LIST->display('search', $args, 'api');
}