Ver código fonte

Search tag fix: Mauvaise gestion des tags a espaces et sans, produisant un trie pas très pratique: fixed

bastien 13 anos atrás
pai
commit
2638c6a23a

+ 25 - 6
src/Muzich/CoreBundle/Controller/SearchController.php Ver arquivo

248
       {
248
       {
249
         if (strlen($word) > 1)
249
         if (strlen($word) > 1)
250
         {
250
         {
251
-          if (strlen(str_replace(strtoupper($canonicalizer->canonicalize($word)), '', strtoupper($tag['slug']))) < 4)
251
+          if (
252
+            strlen(str_replace(strtoupper($canonicalizer->canonicalize($word)), '', strtoupper($tag['slug']))) < 4
253
+            && $word != $search
254
+          )
252
           {
255
           {
253
             $tag_sorted = $this->sort_addtop_if_isnt_in($tag_sorted, $tag);
256
             $tag_sorted = $this->sort_addtop_if_isnt_in($tag_sorted, $tag);
254
           }
257
           }
263
       explode(' ', $search), 
266
       explode(' ', $search), 
264
       explode('-', $search)
267
       explode('-', $search)
265
     );
268
     );
269
+    
266
     $tags_counteds = array();
270
     $tags_counteds = array();
267
     foreach ($tags as $i => $tag)
271
     foreach ($tags as $i => $tag)
268
     {
272
     {
273
+      $terms_search = array_merge(
274
+        explode(' ', $tag['slug']), 
275
+        explode('-', $tag['slug'])
276
+      );
277
+      
269
       foreach ($terms as $word)
278
       foreach ($terms as $word)
270
       {
279
       {
271
-        if (strpos(strtoupper($tag['slug']), strtoupper($word)) !== false)
280
+        if (
281
+          strpos(strtoupper($tag['slug']), strtoupper($word)) !== false
282
+          && count($terms_search) > 2
283
+        )
272
         {
284
         {
273
           $count = 1;
285
           $count = 1;
274
           if (array_key_exists($tag['id'], $tags_counteds))
286
           if (array_key_exists($tag['id'], $tags_counteds))
300
           explode(' ', $tag['slug']), 
312
           explode(' ', $tag['slug']), 
301
           explode('-', $tag['slug'])
313
           explode('-', $tag['slug'])
302
         );
314
         );
303
-        
304
-        if ($words_search == $words_tag)
315
+                
316
+        if (count($words_search) == count($words_tag))
305
         {
317
         {
306
           $same_found = true;
318
           $same_found = true;
307
         }
319
         }
308
         
320
         
321
+        // Cette verif permet de ne pas ajouter les tags qui n'ont qu'un mot
322
+        // Si on ajouté ce tag maintenant il ne serais pas ajouté au controle en dessous
323
+        // (nom identique) et donc pas au dessus.
309
         $tag_sorted = $this->sort_addtop_if_isnt_in($tag_sorted, $counted['tag']);
324
         $tag_sorted = $this->sort_addtop_if_isnt_in($tag_sorted, $counted['tag']);
325
+        
310
       }
326
       }
311
     }
327
     }
312
     
328
     
330
             // Ci-dessous on déduit si le mot étant identique au tag représente bien
346
             // Ci-dessous on déduit si le mot étant identique au tag représente bien
331
             // le terme de recherche. De façon a si c'est le cas pouvoir dire:
347
             // le terme de recherche. De façon a si c'est le cas pouvoir dire:
332
             // oui le terme recherché est connu.
348
             // oui le terme recherché est connu.
333
-            (in_array($word, array(
349
+            if (in_array($word, array(
334
               $search,
350
               $search,
335
               str_replace(' ', '-', $search),
351
               str_replace(' ', '-', $search),
336
               str_replace('-', ' ', $search)
352
               str_replace('-', ' ', $search)
337
-            ))) ? $same_found = true : 
353
+            ))) 
354
+            { 
355
+              $same_found = true;
356
+            }
338
             $tag_sorted = $this->sort_addtop_if_isnt_in($tag_sorted, $tag);
357
             $tag_sorted = $this->sort_addtop_if_isnt_in($tag_sorted, $tag);
339
           }
358
           }
340
         }
359
         }