|
@@ -171,40 +171,117 @@ class SearchController extends Controller
|
171
|
171
|
throw new \Exception('XmlHttpRequest only for this action');
|
172
|
172
|
}
|
173
|
173
|
|
174
|
|
- protected function sort_search_tags($tags, $search)
|
|
174
|
+ /**
|
|
175
|
+ * Ajoute le tag au début du tableau passé en paramètre si celui-ci
|
|
176
|
+ * n'est pas a l'intérieur.
|
|
177
|
+ *
|
|
178
|
+ * @param array $array
|
|
179
|
+ * @param Tag $tag
|
|
180
|
+ * @return array
|
|
181
|
+ */
|
|
182
|
+ private function sort_addtop_if_isnt_in($array, $tag)
|
|
183
|
+ {
|
|
184
|
+ $in = false;
|
|
185
|
+ for ($x=0;$x<=sizeof($array)-1;$x++)
|
|
186
|
+ {
|
|
187
|
+ if ($array[$x]['id'] == $tag['id'])
|
|
188
|
+ {
|
|
189
|
+ $in = true;
|
|
190
|
+ break;
|
|
191
|
+ }
|
|
192
|
+ }
|
|
193
|
+
|
|
194
|
+ if (!$in)
|
|
195
|
+ {
|
|
196
|
+ array_unshift($array, $tag);
|
|
197
|
+ return $array;
|
|
198
|
+ }
|
|
199
|
+ return $array;
|
|
200
|
+ }
|
|
201
|
+
|
|
202
|
+ /**
|
|
203
|
+ * Ajoute le tag a al fin du tableau passé en paramètre si celui-ci
|
|
204
|
+ * n'est pas a l'intérieur.
|
|
205
|
+ *
|
|
206
|
+ * @param array $array
|
|
207
|
+ * @param Tag $tag
|
|
208
|
+ * @return array
|
|
209
|
+ */
|
|
210
|
+ private function sort_addbottom_if_isnt_in($array, $tag)
|
|
211
|
+ {
|
|
212
|
+ $in = false;
|
|
213
|
+ for ($x=0;$x<=sizeof($array)-1;$x++)
|
|
214
|
+ {
|
|
215
|
+ if ($array[$x]['id'] == $tag['id'])
|
|
216
|
+ {
|
|
217
|
+ $in = true;
|
|
218
|
+ break;
|
|
219
|
+ }
|
|
220
|
+ }
|
|
221
|
+
|
|
222
|
+ if (!$in)
|
|
223
|
+ {
|
|
224
|
+ $array[] = $tag;
|
|
225
|
+ return $array;
|
|
226
|
+ }
|
|
227
|
+ return $array;
|
|
228
|
+ }
|
|
229
|
+
|
|
230
|
+ /**
|
|
231
|
+ * Organise le trie des tags de manière plus friendly user.
|
|
232
|
+ *
|
|
233
|
+ * @param array $tags
|
|
234
|
+ * @param string $search
|
|
235
|
+ * @return array
|
|
236
|
+ */
|
|
237
|
+ private function sort_search_tags($tags, $search)
|
175
|
238
|
{
|
176
|
239
|
$canonicalizer = new StrictCanonicalizer();
|
177
|
|
- $tag_sorted = $tags;
|
|
240
|
+ $tag_sorted = array();
|
178
|
241
|
|
179
|
242
|
foreach ($tags as $i => $tag)
|
180
|
243
|
{
|
181
|
244
|
// Pas plus de trois caractères en plus de la recherche
|
182
|
|
- foreach (explode(' ', $search) as $word)
|
|
245
|
+ $terms = array_merge(array($search), explode(' ', $search));
|
|
246
|
+ foreach ($terms as $word)
|
183
|
247
|
{
|
184
|
|
- if (strlen(str_replace(strtoupper($canonicalizer->canonicalize($word)), '', strtoupper($tag['slug']))) < 4)
|
|
248
|
+ if (strlen($word) > 1)
|
185
|
249
|
{
|
186
|
|
- unset($tag_sorted[$i]);
|
187
|
|
- $tag_sorted = array_merge(array($tag), $tag_sorted);
|
|
250
|
+ if (strlen(str_replace(strtoupper($canonicalizer->canonicalize($word)), '', strtoupper($tag['slug']))) < 4)
|
|
251
|
+ {
|
|
252
|
+ $tag_sorted = $this->sort_addtop_if_isnt_in($tag_sorted, $tag);
|
|
253
|
+ }
|
188
|
254
|
}
|
189
|
255
|
}
|
190
|
256
|
|
191
|
257
|
}
|
192
|
258
|
|
193
|
|
- $tags = $tag_sorted;
|
194
|
|
-
|
195
|
259
|
foreach ($tags as $i => $tag)
|
196
|
260
|
{
|
197
|
261
|
// Chaine de caractère identique
|
198
|
|
- foreach (explode(' ', $search) as $word)
|
|
262
|
+ $terms = array_merge(
|
|
263
|
+ array($search),
|
|
264
|
+ explode(' ', $search),
|
|
265
|
+ explode('-', $search),
|
|
266
|
+ array(str_replace(' ', '-', $search)),
|
|
267
|
+ array(str_replace('-', ' ', $search))
|
|
268
|
+ );
|
|
269
|
+
|
|
270
|
+ foreach ($terms as $word)
|
199
|
271
|
{
|
200
|
|
- if (strtoupper($canonicalizer->canonicalize($word)) == strtoupper($tag['slug']))
|
|
272
|
+ if (strlen($word) > 1)
|
201
|
273
|
{
|
202
|
|
- unset($tag_sorted[$i]);
|
203
|
|
- $tag_sorted = array_merge(array($tag), $tag_sorted);
|
|
274
|
+ if (strtoupper($canonicalizer->canonicalize($word)) == strtoupper($tag['slug']))
|
|
275
|
+ {
|
|
276
|
+ $tag_sorted = $this->sort_addtop_if_isnt_in($tag_sorted, $tag);
|
|
277
|
+ }
|
204
|
278
|
}
|
205
|
279
|
}
|
206
|
|
-
|
207
|
|
-
|
|
280
|
+ }
|
|
281
|
+
|
|
282
|
+ foreach ($tags as $i => $tag)
|
|
283
|
+ {
|
|
284
|
+ $tag_sorted = $this->sort_addbottom_if_isnt_in($tag_sorted, $tag);
|
208
|
285
|
}
|
209
|
286
|
|
210
|
287
|
return $tag_sorted;
|
|
@@ -242,17 +319,20 @@ class SearchController extends Controller
|
242
|
319
|
$params = array();
|
243
|
320
|
foreach ($words as $i => $word)
|
244
|
321
|
{
|
245
|
|
- $word = $canonicalizer->canonicalize($word);
|
246
|
|
- if ($where == '')
|
247
|
|
- {
|
248
|
|
- $where .= 'WHERE UPPER(t.slug) LIKE :str'.$i;
|
249
|
|
- }
|
250
|
|
- else
|
|
322
|
+ if (strlen($word) > 1)
|
251
|
323
|
{
|
252
|
|
- $where .= ' OR UPPER(t.slug) LIKE :str'.$i;
|
253
|
|
- }
|
|
324
|
+ $word = $canonicalizer->canonicalize($word);
|
|
325
|
+ if ($where == '')
|
|
326
|
+ {
|
|
327
|
+ $where .= 'WHERE UPPER(t.slug) LIKE :str'.$i;
|
|
328
|
+ }
|
|
329
|
+ else
|
|
330
|
+ {
|
|
331
|
+ $where .= ' OR UPPER(t.slug) LIKE :str'.$i;
|
|
332
|
+ }
|
254
|
333
|
|
255
|
|
- $params['str'.$i] = '%'.strtoupper($word).'%';
|
|
334
|
+ $params['str'.$i] = '%'.strtoupper($word).'%';
|
|
335
|
+ }
|
256
|
336
|
}
|
257
|
337
|
|
258
|
338
|
$tags = $this->getDoctrine()->getEntityManager()->createQuery("
|