]> Some of my projects - localmylist.git/commitdiff
Make the search tab use the same search query as the anime search functions.
authorAPTX <marek321@gmail.com>
Sat, 31 Aug 2013 17:59:49 +0000 (19:59 +0200)
committerAPTX <marek321@gmail.com>
Sat, 31 Aug 2013 17:59:49 +0000 (19:59 +0200)
localmylist-management/tabs/searchtab.cpp
localmylist/database.h

index 9262e3c1ccfd73b9840bdea24933fbb2feb0c5cf..7e2d404c2525536ed56af975d000f174ae8e3ab0 100644 (file)
@@ -51,21 +51,17 @@ void SearchTab::on_input_textChanged(const QString &text)
                return;
        }
 
-       if (text.length() >= 3)
-               query = "%" + text + "%";
-       else
-               query = text + "%";
+       query = toSearchQuery(text);
 
        QSqlQuery &q = MyList::instance()->database()->prepare(
-       "SELECT a.aid, b.title AS main_title, a.title, a.language, a.type FROM anime_title a "
-       "       LEFT JOIN anime_title b on b.aid = a.aid "
-       "       WHERE a.title ILIKE :query "
-       "               AND b.type = 1 "
-       "       ORDER BY a.title ASC, a.aid ASC "
-       "       LIMIT 100");
-       q.bindValue(":word", text);
+       "SELECT at.title_id, at.aid, at.type, at.language, at.title "
+       "       FROM anime_title at "
+       "       WHERE at.title ILIKE :query "
+       "       ORDER BY at.title <-> :query2 ASC "
+       "       LIMIT :limit");
        q.bindValue(":query", query);
-
+       q.bindValue(":query2", query);
+       q.bindValue(":limit", 100);
        MyList::instance()->database()->exec(q);
        model->setQuery(q);
 
index 8d7f329060b644cb5930dfbdfb81d561364fdaf6..6ed2a7b83fa5a65b6b0a7bf906225eef3e4be995 100644 (file)
@@ -226,7 +226,7 @@ public:
        void commit();
 };
 
-QString toSearchQuery(const QString &string);
+QString LOCALMYLISTSHARED_EXPORT toSearchQuery(const QString &string);
 
 } // namespace LocalMyList