@@ -1004,6 +1004,8 @@ public function updateShares(IShareable $shareable, $add, $remove) {
10041004 * - 'escape_like_param' - If set to false wildcards _ and % are not escaped, otherwise they are
10051005 * - 'limit' - Set a numeric limit for the search results
10061006 * - 'offset' - Set the offset for the limited search results
1007+ * - 'wildcard' - Whether the search should use wildcards
1008+ * @psalm-param array{escape_like_param?: bool, limit?: int, offset?: int, wildcard?: bool} $options
10071009 * @return array an array of contacts which are arrays of key-value-pairs
10081010 */
10091011 public function search ($ addressBookId , $ pattern , $ searchProperties , $ options = []): array {
@@ -1035,13 +1037,15 @@ public function searchPrincipalUri(string $principalUri,
10351037 * @param string $pattern
10361038 * @param array $searchProperties
10371039 * @param array $options
1040+ * @psalm-param array{types?: bool, escape_like_param?: bool, limit?: int, offset?: int, wildcard?: bool} $options
10381041 * @return array
10391042 */
10401043 private function searchByAddressBookIds (array $ addressBookIds ,
10411044 string $ pattern ,
10421045 array $ searchProperties ,
10431046 array $ options = []): array {
10441047 $ escapePattern = !\array_key_exists ('escape_like_param ' , $ options ) || $ options ['escape_like_param ' ] !== false ;
1048+ $ useWildcards = !\array_key_exists ('wildcard ' , $ options ) || $ options ['wildcard ' ] !== false ;
10451049
10461050 $ query2 = $ this ->db ->getQueryBuilder ();
10471051
@@ -1083,7 +1087,9 @@ private function searchByAddressBookIds(array $addressBookIds,
10831087
10841088 // No need for like when the pattern is empty
10851089 if ('' !== $ pattern ) {
1086- if (!$ escapePattern ) {
1090+ if (!$ useWildcards ) {
1091+ $ query2 ->andWhere ($ query2 ->expr ()->eq ('cp.value ' , $ query2 ->createNamedParameter ($ pattern )));
1092+ } elseif (!$ escapePattern ) {
10871093 $ query2 ->andWhere ($ query2 ->expr ()->ilike ('cp.value ' , $ query2 ->createNamedParameter ($ pattern )));
10881094 } else {
10891095 $ query2 ->andWhere ($ query2 ->expr ()->ilike ('cp.value ' , $ query2 ->createNamedParameter ('% ' . $ this ->db ->escapeLikeParameter ($ pattern ) . '% ' )));
0 commit comments