@@ -26,23 +26,18 @@ protected function getConfiguration(Types $types, LeafType $leafType): array
2626 ];
2727 }
2828
29- public function getDqlCondition (UniqueNameFactory $ uniqueNameFactory , ClassMetadata $ metadata , QueryBuilder $ queryBuilder , string $ alias , string $ field , array $ args ): string
29+ public function getDqlCondition (UniqueNameFactory $ uniqueNameFactory , ClassMetadata $ metadata , QueryBuilder $ queryBuilder , string $ alias , string $ field , array $ args ): ? string
3030 {
31- $ search = $ args ['term ' ];
32-
33- $ fields = [];
34-
35- // Find all textual fields for the entity
36- $ textType = ['string ' , 'text ' ];
37- foreach ($ metadata ->fieldMappings as $ g ) {
38- if (in_array ($ g ['type ' ], $ textType , true )) {
39- $ fields [] = $ alias . '. ' . $ g ['fieldName ' ];
40- }
31+ $ words = preg_split ('/[[:space:]]+/ ' , $ args ['term ' ], -1 , PREG_SPLIT_NO_EMPTY );
32+ if (!$ words ) {
33+ return null ;
4134 }
4235
36+ $ fields = $ this ->getSearchableFields ($ metadata , $ alias );
37+
4338 // Build the WHERE clause
4439 $ wordWheres = [];
45- foreach (preg_split ( ' /[[:space:]]+/ ' , $ search , - 1 , PREG_SPLIT_NO_EMPTY ) as $ i => $ word ) {
40+ foreach ($ words as $ word ) {
4641 $ parameterName = $ uniqueNameFactory ->createParameterName ();
4742
4843 $ fieldWheres = [];
@@ -58,4 +53,25 @@ public function getDqlCondition(UniqueNameFactory $uniqueNameFactory, ClassMetad
5853
5954 return '( ' . implode (' AND ' , $ wordWheres ) . ') ' ;
6055 }
56+
57+ /**
58+ * Find all textual fields for the entity
59+ *
60+ * @param ClassMetadata $metadata
61+ * @param string $alias
62+ *
63+ * @return array
64+ */
65+ private function getSearchableFields (ClassMetadata $ metadata , string $ alias ): array
66+ {
67+ $ fields = [];
68+ $ textType = ['string ' , 'text ' ];
69+ foreach ($ metadata ->fieldMappings as $ g ) {
70+ if (in_array ($ g ['type ' ], $ textType , true )) {
71+ $ fields [] = $ alias . '. ' . $ g ['fieldName ' ];
72+ }
73+ }
74+
75+ return $ fields ;
76+ }
6177}
0 commit comments