Aggiunto supporto a tante parole nel campo della ricerca.
Leonardo Robol [2010-02-17 20:26]
Aggiunto supporto a tante parole nel campo della ricerca.
diff --git a/Dizzy/EventManager.cs b/Dizzy/EventManager.cs
index 3d33f89..031c235 100644
--- a/Dizzy/EventManager.cs
+++ b/Dizzy/EventManager.cs
@@ -87,7 +87,7 @@ namespace Dizzy
}
public static bool AuthenticationDialog () {
- Log.Info ("Uei, sembra che qualcuno mi abbia chiesto di autenticarsi!");
+
if (EventManager.authDialog == null)
{
EventManager.authDialog = new AuthDialog ();
diff --git a/Dizzy/FileList.cs b/Dizzy/FileList.cs
index 2e4e0e4..48fcc42 100644
--- a/Dizzy/FileList.cs
+++ b/Dizzy/FileList.cs
@@ -19,12 +19,34 @@ namespace Dizzy
public ArrayList Search(string keyword, string type, string user) {
+ /* Facciamo qualche check per evitare utenti che inseriscono
+ * cose a caso */
+ keyword.Replace("%", "\\%");
+ keyword.Replace(";", "\\;");
+
+ /* keyword è presumibilmente nella forma di più keyword separate da
+ * spazi, e quindi dobbiamo sottoporla ad un "preprocessing" prima
+ * di darla in pasto ad una query sql. Per ora assumiamo che l'utente
+ * voglia l'unione dei risultati con le singole query. */
+ string [] keys = keyword.Split(' ');
+
this.connection.Open ();
ArrayList matches = new ArrayList ();
// Eseguiamo la query
SQLiteCommand sqlCmd = this.connection.CreateCommand ();
- sqlCmd.CommandText = "SELECT * from files WHERE name LIKE '%" + keyword + "%'";
+ string query = "SELECT * from files WHERE";
+ foreach(string k in keys)
+ {
+ if (query.EndsWith("'"))
+ query += " OR name LIKE '%" + k + "%'";
+ else
+ query += " name LIKE '%" + k + "%'";
+ }
+
+ query += ";";
+ sqlCmd.CommandText = query;
+ Log.Warning ("Executing query " + sqlCmd.CommandText);
SQLiteDataReader reader = sqlCmd.ExecuteReader ();
File tmp;