Skip to content

Commit

Permalink
Merge pull request #9537 from jitendrapurohit/CRM-19048-add
Browse files Browse the repository at this point in the history
CRM-19048: Fix attached operator search
  • Loading branch information
Yashodha Chaku authored Dec 15, 2016
2 parents 52b84b1 + e0b5165 commit 04f66eb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions CRM/Utils/QueryFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,17 @@ protected function _formatFts($text, $mode) {
protected function _formatFtsBool($text, $mode) {
$result = NULL;
$operators = array('+', '-', '~', '(', ')');
$wildCards = array('@', '%', '*');
$expression = preg_quote(implode('', array_merge($operators, $wildCards)), '/');

//Return if searched string ends with an unsupported operator.
//Or if the string contains an invalid joint occurrence of operators.
foreach ($operators as $val) {
if ($text == '@' || CRM_Utils_String::endsWith($text, $val)) {
if ($text == '@' || CRM_Utils_String::endsWith($text, $val) || preg_match("/[{$expression}]{2,}/", $text)) {
$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");
$operators = implode("', '", $operators);
CRM_Core_Error::statusBounce("Full-Text Search does not support the use of a search string ending with any of these operators ('{$operators}' or a single '@'). Please adjust your search term and try again.", $url);
CRM_Core_Error::statusBounce("Full-Text Search does not support the use of a search with two attached operators or string ending with any of these operators ('{$operators}' or a single '@'). Please adjust your search term and try again.", $url, 'Invalid Search String');
}
}

Expand Down

0 comments on commit 04f66eb

Please sign in to comment.