Skip to content

Commit

Permalink
add/update MP search functions
Browse files Browse the repository at this point in the history
Update constituency search to allow it to return all constituencies for
a postcode instead of just westminster.
Add a function to get a list of member ids from a search string.
  • Loading branch information
struan committed Dec 17, 2024
1 parent 06c528e commit a644038
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions classes/Utility/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,25 @@ public static function searchMemberDbLookupWithNames($searchstring, $current_onl
* Given a search term, find constituencies by name or postcode.
*
* @param string $searchterm The term to search for.
* @param bool $mp_only if true (default) only return westminster constituency if using a postcode, otherwise return all.
*
* @return array A list of the array of constituencies, then a boolean
* saying whether it was a postcode used.
*/

public static function searchConstituenciesByQuery($searchterm) {
public static function searchConstituenciesByQuery($searchterm, $mp_only=true) {
if (validate_postcode($searchterm)) {
// Looks like a postcode - can we find the constituency?
$constituency = Postcode::postcodeToConstituency($searchterm);
if ($constituency) {
return [ [$constituency], true ];
if ($mp_only) {
$constituency = Postcode::postcodeToConstituency($searchterm);
if ($constituency) {
return [ [$constituency], true ];
}
} else {
$constituencies = Postcode::postcodeToConstituencies($searchterm);
if ($constituencies) {
return [ $constituencies, true ];
}
}
}

Expand Down Expand Up @@ -297,6 +305,28 @@ public static function speakerNamesForIDs($searchstring) {
return $speakers;
}

/**
* get list of members of speaker IDs from search string
*
* @param string $searchstring The search string with the speaker:NNN text
*
* @return array Array with the speaker id string as key and speaker name as value
*/

public static function membersForIDs($searchstring) {
$criteria = explode(' ', $searchstring);
$speakers = [];

foreach ($criteria as $c) {
if (preg_match('#^speaker:(\d+)#', $c, $m)) {
$MEMBER = new \MEMBER(['person_id' => $m[1]]);
$speakers[$m[1]] = $MEMBER;
}
}

return $speakers;
}

/**
* replace speaker:NNNN with speaker:Name in search string
*
Expand Down

0 comments on commit a644038

Please sign in to comment.