Exemple #1
0
 /**
  * Test looking up a person by full name works as expected.
  */
 public function testSearchMemberDbLookupFullName()
 {
     // Test a full name.
     $results = \MySociety\TheyWorkForYou\Utility\Search::searchMemberDbLookup('Mary Smith');
     $this->assertEquals(1, $results->rows());
     $this->assertEquals(3, $results->field(0, 'person_id'));
     // Test an inverse full name.
     $results = \MySociety\TheyWorkForYou\Utility\Search::searchMemberDbLookup('Smith Mary');
     $this->assertEquals(1, $results->rows());
     $this->assertEquals(3, $results->field(0, 'person_id'));
     // Test a name with title.
     $results = \MySociety\TheyWorkForYou\Utility\Search::searchMemberDbLookup('Mrs Smith');
     $this->assertEquals(1, $results->rows());
     $this->assertEquals(3, $results->field(0, 'person_id'));
 }
Exemple #2
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;
 }
Exemple #3
0
 private function parse_person_params()
 {
     $searchstring = '';
     # Searching from MP pages
     if ($searchspeaker = trim(get_http_var('pid'))) {
         $searchstring .= " speaker:{$searchspeaker}";
     }
     # Searching from MP pages
     if ($searchspeaker = trim(get_http_var('person'))) {
         $q = \MySociety\TheyWorkForYou\Utility\Search::searchMemberDbLookup($searchspeaker);
         $pids = array();
         $row_count = $q->rows();
         for ($i = 0; $i < $row_count; $i++) {
             $pids[$q->field($i, 'person_id')] = true;
         }
         $pids = array_keys($pids);
         if (count($pids) > 0) {
             $searchstring .= ' speaker:' . join(' speaker:', $pids);
         }
     }
     return $searchstring;
 }
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');
}
Exemple #5
0
 private function prettifyCriteria($alert_criteria)
 {
     $text = '';
     if ($alert_criteria) {
         $criteria = explode(' ', $alert_criteria);
         $words = array();
         $spokenby = array_values(\MySociety\TheyWorkForYou\Utility\Search::speakerNamesForIDs($alert_criteria));
         foreach ($criteria as $c) {
             if (!preg_match('#^speaker:(\\d+)#', $c, $m)) {
                 $words[] = $c;
             }
         }
         if ($spokenby && count($words)) {
             $text = implode(' or ', $spokenby) . ' mentions [' . implode(' ', $words) . ']';
         } else {
             if (count($words)) {
                 $text = '[' . implode(' ', $words) . ']' . ' is mentioned';
             } else {
                 if ($spokenby) {
                     $text = implode(' or ', $spokenby) . " speaks";
                 }
             }
         }
         return $text;
     }
     return $text;
 }
Exemple #6
0
 public function criteria_pretty($html = false)
 {
     $criteria = explode(' ', $this->criteria);
     $spokenby = array_values(\MySociety\TheyWorkForYou\Utility\Search::speakerNamesForIDs($alert_criteria));
     $words = array();
     foreach ($criteria as $c) {
         if (!preg_match('#^speaker:(\\d+)#', $c, $m)) {
             $words[] = $c;
         }
     }
     $criteria = '';
     if (count($words)) {
         $criteria .= ($html ? '<li>' : '* ') . 'Mentions of [' . join(' ', $words) . ']' . ($html ? '</li>' : '') . "\n";
     }
     if ($spokenby) {
         $criteria .= ($html ? '<li>' : '* ') . "Things by {$spokenby}" . ($html ? '</li>' : '') . "\n";
     }
     return $criteria;
 }
Exemple #7
0
 private function find_members()
 {
     $searchstring = trim(preg_replace('#-?[a-z]+:[a-z0-9]+#', '', $this->searchstring));
     $q = \MySociety\TheyWorkForYou\Utility\Search::searchMemberDbLookup($searchstring);
     if (!$q) {
         return array();
     }
     $members = array();
     if ($q->rows() > 0) {
         $row_count = $q->rows();
         for ($n = 0; $n < $row_count; $n++) {
             $member = new \MySociety\TheyWorkForYou\Member(array('person_id' => $q->field($n, 'person_id')));
             // searchMemberDbLookup returns dups so we
             // key by person_id to work round this
             $members[$member->person_id] = $member;
         }
     }
     return $members;
 }