@@ -223,7 +223,7 @@ protected function fetchColumnSuggestions($searchTerm)
223
223
224
224
$ parsedArrayVars = [];
225
225
$ exactSearchTerm = trim ($ searchTerm , ' * ' );
226
- $ exactVarMatches = [];
226
+ $ exactVarSearches = [];
227
227
$ titleAdded = false ;
228
228
229
229
// Suggest exact custom variable matches first
@@ -237,6 +237,7 @@ protected function fetchColumnSuggestions($searchTerm)
237
237
)) as $ customVar
238
238
) {
239
239
$ search = $ name = $ customVar ->flatname ;
240
+ $ exactVarSearches [] = $ search ;
240
241
if (preg_match ('/\w+(?:\[(\d*)])+$/ ' , $ search , $ matches )) {
241
242
$ name = substr ($ search , 0 , -(strlen ($ matches [1 ]) + 2 ));
242
243
if (isset ($ parsedArrayVars [$ name ])) {
@@ -249,7 +250,6 @@ protected function fetchColumnSuggestions($searchTerm)
249
250
250
251
foreach ($ this ->customVarSources as $ relation => $ label ) {
251
252
if (isset ($ customVar ->$ relation )) {
252
- $ varRelation = $ relation . '.vars. ' . $ search ;
253
253
if ($ titleAdded === false ) {
254
254
$ this ->addHtml (HtmlElement::create (
255
255
'li ' ,
@@ -260,9 +260,7 @@ protected function fetchColumnSuggestions($searchTerm)
260
260
$ titleAdded = true ;
261
261
}
262
262
263
- $ exactVarMatches [] = $ varRelation ;
264
-
265
- yield $ varRelation => sprintf ($ label , $ name );
263
+ yield $ relation . '.vars. ' . $ search => sprintf ($ label , $ name );
266
264
}
267
265
}
268
266
}
@@ -289,9 +287,16 @@ protected function fetchColumnSuggestions($searchTerm)
289
287
290
288
// Finally, the other custom variable suggestions
291
289
$ titleAdded = false ;
292
- foreach (
293
- $ this ->getDb ()->select ($ this ->queryCustomvarConfig (Filter::like ('flatname ' , $ searchTerm ))) as $ customVar
294
- ) {
290
+ if (! empty ($ exactVarSearches )) {
291
+ $ filter = Filter::all (
292
+ Filter::like ('flatname ' , $ searchTerm ),
293
+ Filter::unequal ('flatname ' , $ exactVarSearches )
294
+ );
295
+ } else {
296
+ $ filter = Filter::like ('flatname ' , $ searchTerm );
297
+ }
298
+
299
+ foreach ($ this ->getDb ()->select ($ this ->queryCustomvarConfig ($ filter )) as $ customVar ) {
295
300
$ search = $ name = $ customVar ->flatname ;
296
301
if (preg_match ('/\w+(?:\[(\d*)])+$/ ' , $ search , $ matches )) {
297
302
$ name = substr ($ search , 0 , -(strlen ($ matches [1 ]) + 2 ));
@@ -305,25 +310,18 @@ protected function fetchColumnSuggestions($searchTerm)
305
310
306
311
foreach ($ this ->customVarSources as $ relation => $ label ) {
307
312
if (isset ($ customVar ->$ relation )) {
308
- $ varRelation = $ relation . '.vars. ' . $ search ;
309
- $ varLabel = sprintf ($ label , $ name );
310
313
// Suggest exact custom variable matches first
311
- if (
312
- ! in_array ($ varRelation , $ exactVarMatches )
313
- && $ this ->matchSuggestion ($ varRelation , $ varLabel , $ searchTerm )
314
- ) {
315
- if ($ titleAdded === false ) {
316
- $ this ->addHtml (HtmlElement::create (
317
- 'li ' ,
318
- ['class ' => static ::SUGGESTION_TITLE_CLASS ],
319
- t ('Custom Variables ' )
320
- ));
321
-
322
- $ titleAdded = true ;
323
- }
324
-
325
- yield $ varRelation => $ varLabel ;
314
+ if ($ titleAdded === false ) {
315
+ $ this ->addHtml (HtmlElement::create (
316
+ 'li ' ,
317
+ ['class ' => static ::SUGGESTION_TITLE_CLASS ],
318
+ t ('Custom Variables ' )
319
+ ));
320
+
321
+ $ titleAdded = true ;
326
322
}
323
+
324
+ yield $ relation . '.vars. ' . $ search => sprintf ($ label , $ name );
327
325
}
328
326
}
329
327
}
0 commit comments