From 34efbc0c189f2edd9a90bcdeb503ec7e7ed3fabe Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Thu, 14 Jul 2011 10:27:18 -0700 Subject: [PATCH] Adding starts with/ends with logic to search string --- third_party/search_fields/pi.search_fields.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/third_party/search_fields/pi.search_fields.php b/third_party/search_fields/pi.search_fields.php index e37de80..badf6a9 100644 --- a/third_party/search_fields/pi.search_fields.php +++ b/third_party/search_fields/pi.search_fields.php @@ -242,8 +242,13 @@ function Search_fields() } else { - $term = $this->_sanitize_search_terms($term); - $sql_conditions .= ' '.$field_sql.' '.$like.' "%'.$this->EE->db->escape_like_str($term).'%" '.$andor; + // starts with, ends with, or contains + $l_wildcard = substr($term, 0, 2) == '\^' ? '' : '%'; + $r_wildcard = substr($term, -2, 2) == '\$' ? '' : '%'; + $term = str_replace(array('\^', '\$'), '', $term); + + $term = $this->_sanitize_search_terms($term); + $sql_conditions .= ' '.$field_sql.' '.$like.' "' .$l_wildcard.$this->EE->db->escape_like_str($term).$r_wildcard.'" '.$andor; } } $sql_conditions = substr($sql_conditions, 0, -strlen($andor)).') ';