pbordescnil commited on
Commit
b1b9446
·
1 Parent(s): c335baf

Sort autocomplete suggestions by downloads

Browse files
Files changed (1) hide show
  1. application_neo4j/app.py +6 -3
application_neo4j/app.py CHANGED
@@ -326,13 +326,16 @@ def autocomplete():
326
  if node_filter and node_filter in ["Model", "Dataset"]: # Mesure de sécurité
327
  label_cypher = f":{node_filter}"
328
 
329
- # Récupère les noms commençant par le préfixe fourni
 
 
330
  cypher = f"""
331
  MATCH (n{label_cypher})
332
  WHERE toLower(n.name) STARTS WITH toLower($prefix)
333
  AND n.name IS NOT NULL
334
- RETURN n.name AS name, labels(n)[0] as label
335
- ORDER BY size(n.name) ASC
 
336
  LIMIT 10
337
  """
338
  try:
 
326
  if node_filter and node_filter in ["Model", "Dataset"]: # Mesure de sécurité
327
  label_cypher = f":{node_filter}"
328
 
329
+ # Récupère les noms commençant par le préfixe fourni. Les suggestions les
330
+ # plus téléchargées sont proposées en premier ; le nom garantit un ordre
331
+ # stable lorsque plusieurs éléments ont le même nombre de téléchargements.
332
  cypher = f"""
333
  MATCH (n{label_cypher})
334
  WHERE toLower(n.name) STARTS WITH toLower($prefix)
335
  AND n.name IS NOT NULL
336
+ RETURN n.name AS name, labels(n)[0] AS label,
337
+ coalesce(n.downloads, 0) AS downloads
338
+ ORDER BY downloads DESC, toLower(n.name) ASC
339
  LIMIT 10
340
  """
341
  try: