diff --git a/classes/AlertView/Standard.php b/classes/AlertView/Standard.php index 9003b82dda..3d651ddc26 100644 --- a/classes/AlertView/Standard.php +++ b/classes/AlertView/Standard.php @@ -136,6 +136,7 @@ private function getBasicData() { $this->data['addword'] = trim(get_http_var("addword")); $this->data['this_step'] = trim(get_http_var("this_step")); $this->data['shown_related'] = get_http_var('shown_related'); + $this->data['match_all'] = get_http_var('match_all') == 'on'; if ($this->data['addword'] || $this->data['step']) { $alert = $this->alert->check_token($this->data['token']); @@ -159,6 +160,10 @@ private function getBasicData() { $existing_section = $this->data['alert_parts']['sections'][0]; } + if ($this->data['alert_parts']['match_all']) { + $this->data['match_all'] = true; + } + $words = get_http_var('words', $this->data['alert_parts']['words'], true); $this->data['words'] = []; @@ -197,9 +202,13 @@ private function getBasicData() { $this->data['search_section'] = trim(get_http_var("search_section", $existing_section)); - $this->data['keyword'] = implode(' OR ', $this->data['words']); + $separator = ' OR '; + if ($this->data['match_all']) { + $separator = ' '; + } + $this->data['keyword'] = implode($separator, $this->data['words']); if ($this->data['exclusions']) { - $this->data['keyword'] .= " -" . $this->data["exclusions"]; + $this->data['keyword'] = '(' . $this->data['keyword'] . ') -' . $this->data["exclusions"]; } $this->data['results'] = ''; @@ -483,6 +492,14 @@ protected function formatSearchMemberData() { protected function setUserData() { if (!isset($this->data['criteria'])) { $criteria = $this->data['keyword']; + if (!$this->data['match_all']) { + $has_or = strpos($criteria, ' OR ') !== false; + $missing_braces = strpos($criteria, '(') === false; + + if ($has_or && $missing_braces) { + $criteria = "($criteria)"; + } + } if ($this->data['search_section']) { $criteria .= " section:" . $this->data['search_section']; } diff --git a/classes/Utility/Alert.php b/classes/Utility/Alert.php index 9f9ecc48ab..fc85dccef8 100644 --- a/classes/Utility/Alert.php +++ b/classes/Utility/Alert.php @@ -89,10 +89,14 @@ public static function forUser($email) { public static function prettifyCriteria($alert_criteria, $as_parts = false) { $text = ''; - $parts = ['words' => [], 'sections' => [], 'exclusions' => []]; + $parts = ['words' => [], 'sections' => [], 'exclusions' => [], 'match_all' => true]; if ($alert_criteria) { # check for phrases + if (strpos($alert_criteria, ' OR ') !== false) { + $parts['match_all'] = false; + } $alert_criteria = str_replace(' OR ', ' ', $alert_criteria); + $alert_criteria = str_replace(['(', ')'], '', $alert_criteria); if (strpos($alert_criteria, '"') !== false) { # match phrases preg_match_all('/"([^"]*)"/', $alert_criteria, $phrases); diff --git a/www/includes/easyparliament/templates/html/alert/_alert_form.php b/www/includes/easyparliament/templates/html/alert/_alert_form.php index ee2391e0f0..8c8b8fddc3 100644 --- a/www/includes/easyparliament/templates/html/alert/_alert_form.php +++ b/www/includes/easyparliament/templates/html/alert/_alert_form.php @@ -45,6 +45,11 @@ +