Browse Source

Saisie de tag: Meilleure gestion de touches comme ;, : ...

bastien 13 years ago
parent
commit
148e707592

+ 27 - 9
src/Muzich/CoreBundle/Controller/SearchController.php View File

243
     foreach ($tags as $i => $tag)
243
     foreach ($tags as $i => $tag)
244
     {
244
     {
245
       // Pas plus de trois caractères en plus de la recherche
245
       // Pas plus de trois caractères en plus de la recherche
246
-      $terms = array_merge(array($search), explode(' ', $search));
246
+      $terms = array_merge(
247
+        explode(' ', $search), 
248
+        explode('-', $search), 
249
+        explode(',', $search)
250
+      );
247
       foreach ($terms as $word)
251
       foreach ($terms as $word)
248
       {
252
       {
253
+        $word = trim($word);
249
         if (strlen($word) > 1)
254
         if (strlen($word) > 1)
250
         {
255
         {
251
           if (
256
           if (
264
     // on cherche les mot composé comme lui
269
     // on cherche les mot composé comme lui
265
     $terms = array_merge(
270
     $terms = array_merge(
266
       explode(' ', $search), 
271
       explode(' ', $search), 
267
-      explode('-', $search)
272
+      explode('-', $search), 
273
+      explode(',', $search)
268
     );
274
     );
269
     
275
     
270
     $tags_counteds = array();
276
     $tags_counteds = array();
272
     {
278
     {
273
       $terms_search = array_merge(
279
       $terms_search = array_merge(
274
         explode(' ', $tag['slug']), 
280
         explode(' ', $tag['slug']), 
275
-        explode('-', $tag['slug'])
281
+        explode('-', $tag['slug']), 
282
+        explode(',', $tag['slug'])
276
       );
283
       );
277
       
284
       
278
       foreach ($terms as $word)
285
       foreach ($terms as $word)
279
       {
286
       {
287
+        $word = trim($word);
280
         if (
288
         if (
281
           strpos(strtoupper($tag['slug']), strtoupper($word)) !== false
289
           strpos(strtoupper($tag['slug']), strtoupper($word)) !== false
282
-          && count($terms_search) > 2
290
+          && count($terms_search) > 3
283
         )
291
         )
284
         {
292
         {
285
           $count = 1;
293
           $count = 1;
295
       }
303
       }
296
     }
304
     }
297
     
305
     
306
+    
298
     foreach ($tags_counteds as $id => $counted)
307
     foreach ($tags_counteds as $id => $counted)
299
     {
308
     {
300
       if ($counted['count'] > 1)
309
       if ($counted['count'] > 1)
305
         
314
         
306
         $words_search = array_merge(
315
         $words_search = array_merge(
307
           explode(' ', $search), 
316
           explode(' ', $search), 
308
-          explode('-', $search)
317
+          explode('-', $search), 
318
+          explode(',', $search)
309
         );
319
         );
320
+        $words_search = array_unique($words_search);
310
         
321
         
311
         $words_tag = array_merge(
322
         $words_tag = array_merge(
312
           explode(' ', $counted['tag']['slug']), 
323
           explode(' ', $counted['tag']['slug']), 
313
           explode('-', $counted['tag']['slug'])
324
           explode('-', $counted['tag']['slug'])
314
         );
325
         );
315
-        
326
+        $words_tag = array_unique($words_tag);
327
+            
316
         if (count($words_search) == count($words_tag))
328
         if (count($words_search) == count($words_tag))
317
         {
329
         {
318
           $same_found = true;
330
           $same_found = true;
333
         array($search), 
345
         array($search), 
334
         explode(' ', $search), 
346
         explode(' ', $search), 
335
         explode('-', $search),
347
         explode('-', $search),
348
+        explode(',', $search),
336
         array(str_replace(' ', '-', $search)),
349
         array(str_replace(' ', '-', $search)),
337
         array(str_replace('-', ' ', $search))
350
         array(str_replace('-', ' ', $search))
338
       );
351
       );
339
       
352
       
340
       foreach ($terms as $word)
353
       foreach ($terms as $word)
341
       {
354
       {
355
+        $word = trim($word);
342
         if (strlen($word) > 1)
356
         if (strlen($word) > 1)
343
         {
357
         {
344
           if (strtoupper($canonicalizer->canonicalize($word)) == strtoupper($tag['slug']))
358
           if (strtoupper($canonicalizer->canonicalize($word)) == strtoupper($tag['slug']))
345
           {
359
           {
346
-            // Ci-dessous on déduit si le mot étant identique au tag représente bien
347
-            // le terme de recherche. De façon a si c'est le cas pouvoir dire:
360
+            // Ci-dessous on déduit si le mot est identique au tag . 
361
+            // De façon a ce que si c'est le cas, pouvoir dire:
348
             // oui le terme recherché est connu.
362
             // oui le terme recherché est connu.
349
             if (in_array($word, array(
363
             if (in_array($word, array(
350
               $search,
364
               $search,
351
               str_replace(' ', '-', $search),
365
               str_replace(' ', '-', $search),
352
-              str_replace('-', ' ', $search)
366
+              str_replace('-', ' ', $search),
367
+              str_replace(',', ' ', $search),
368
+              str_replace(', ', '-', $search),
369
+              str_replace(',', ' ', $search),
370
+              str_replace(', ', '-', $search)
353
             ))) 
371
             ))) 
354
             { 
372
             { 
355
               $same_found = true;
373
               $same_found = true;

+ 8 - 2
web/js/tags/jquery.tagBox.js View File

45
         self.tagInput = $('<input>', {
45
         self.tagInput = $('<input>', {
46
             'type' : 'text',
46
             'type' : 'text',
47
             'keydown' : function(e) {
47
             'keydown' : function(e) {
48
-                if(e.keyCode == 13 || e.keyCode == self.delimit_key ) {
49
-                    $(this).trigger("selectTag");
48
+                //if(e.keyCode == 13 || e.keyCode == self.delimit_key ) {
49
+                if(
50
+                  e.keyCode == 13 
51
+                  || e.keyCode == self.delimit_key
52
+                  || e.keyCode == 59
53
+                  || e.keyCode == 190
54
+                ) {
55
+                    //$(this).trigger("selectTag");
50
                     e.preventDefault();
56
                     e.preventDefault();
51
                 }
57
                 }
52
             },
58
             },