Browse Source

Evolution #94: Trie des tags: tags exact en haut

bastien 13 years ago
parent
commit
74137cc769
1 changed files with 30 additions and 0 deletions
  1. 30 0
      src/Muzich/CoreBundle/Controller/SearchController.php

+ 30 - 0
src/Muzich/CoreBundle/Controller/SearchController.php View File

156
     throw new \Exception('XmlHttpRequest only for this action');
156
     throw new \Exception('XmlHttpRequest only for this action');
157
   }
157
   }
158
   
158
   
159
+  protected function sort_search_tags($tags, $search)
160
+  {
161
+    $tag_sorted = $tags;
162
+    
163
+    foreach ($tags as $i => $tag)
164
+    {
165
+      // Pas plus de trois caractères en plus de la recherche
166
+      if (strlen(str_replace(strtoupper($search), '', strtoupper($tag))) < 4)
167
+      {
168
+        unset($tag_sorted[$i]);
169
+        $tag_sorted = array_merge(array($tag), $tag_sorted);
170
+      }
171
+    }
172
+    
173
+    $tags = $tag_sorted;
174
+    
175
+    foreach ($tags as $i => $tag)
176
+    {
177
+      // Pas plus de trois caractères en plus de la recherche
178
+      if (strtoupper($search) == strtoupper($tag))
179
+      {
180
+        unset($tag_sorted[$i]);
181
+        $tag_sorted = array_merge(array($tag), $tag_sorted);
182
+      }
183
+    }
184
+    
185
+    return $tag_sorted;
186
+  }
187
+  
159
   /**
188
   /**
160
    *
189
    *
161
    * @param string $string_search 
190
    * @param string $string_search 
197
           $tags_response[] = $tag['name'];
226
           $tags_response[] = $tag['name'];
198
         }
227
         }
199
         
228
         
229
+        $tags_response = $this->sort_search_tags($tags_response, $string_search);
200
         $status = 'success';
230
         $status = 'success';
201
         $error  = '';
231
         $error  = '';
202
       }
232
       }