From: APTX Date: Sat, 31 Aug 2013 17:59:49 +0000 (+0200) Subject: Make the search tab use the same search query as the anime search functions. X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=3bd01f90e60a570bf9d0868f74578247e982fbd0;p=localmylist.git Make the search tab use the same search query as the anime search functions. --- diff --git a/localmylist-management/tabs/searchtab.cpp b/localmylist-management/tabs/searchtab.cpp index 9262e3c..7e2d404 100644 --- a/localmylist-management/tabs/searchtab.cpp +++ b/localmylist-management/tabs/searchtab.cpp @@ -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); diff --git a/localmylist/database.h b/localmylist/database.h index 8d7f329..6ed2a7b 100644 --- a/localmylist/database.h +++ b/localmylist/database.h @@ -226,7 +226,7 @@ public: void commit(); }; -QString toSearchQuery(const QString &string); +QString LOCALMYLISTSHARED_EXPORT toSearchQuery(const QString &string); } // namespace LocalMyList