Last active
November 10, 2016 12:27
-
-
Save jitendrapurohit/11ad9fb6da083998b4d4141ffda26d4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/CRM/Utils/QueryFormatter.php b/CRM/Utils/QueryFormatter.php | |
index bdbabea..f009371 100644 | |
@@ -211,6 +287,13 @@ class CRM_Utils_QueryFormatter { | |
*/ | |
protected function _formatFtsBool($text, $mode) { | |
$result = NULL; | |
+ // Bounce back if delimiters are searched in Full Text search mode. | |
+ $delimiters = array('(', ')', '+', '-', '<', '>', '@', '~'); | |
+ if (in_array($text, $delimiters)) { | |
+ $csid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', 'CRM_Contact_Form_Search_Custom_FullText', 'value', 'name'); | |
+ $url = CRM_Utils_System::url("civicrm/contact/search/custom", "csid={$csid}&reset=1"); | |
+ CRM_Core_Error::statusBounce("InnoDB full-text search does not support the use of delimiters in boolean full-text searches.", $url); | |
+ } | |
// normalize user-inputted wildcards | |
$text = str_replace('%', '*', $text); | |
@@ -319,7 +402,17 @@ class CRM_Utils_QueryFormatter { | |
* @return array | |
*/ | |
protected function parseWords($text) { | |
- return explode(' ', preg_replace('/[ \r\n\t]+/', ' ', trim($text))); | |
+ //NYSS 9692 special handling for emails | |
+ if (preg_match('/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/', $text)) { | |
+ $text = str_replace('@', ' ', $text); | |
+ } | |
+ //NYSS also replace other occurrences of @ | |
+ $replacedText = preg_replace('/[ \r\n\t\@]+/', ' ', trim($text)); | |
+ //Filter empty values if any. | |
+ $keywords = array_filter(explode(' ', $replacedText)); | |
+ | |
+ //Ensure each searched keywords are wrapped in double quotes. | |
+ foreach ($keywords as &$val) { | |
+ if (!is_numeric($val)) { | |
+ $val = "\"{$val}\""; | |
+ } | |
+ } | |
+ return $keywords; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment