2 * This file is part of NeverNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\r
8 * Software distributed under the License is distributed
\r
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
\r
10 * express or implied. See the GPL for the specific language
\r
11 * governing rights and limitations.
\r
13 * You should have received a copy of the GPL along with this
\r
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
\r
15 * or write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
20 package cx.fbn.nevernote.filters;
\r
22 import java.util.List;
\r
24 import com.trolltech.qt.sql.QSqlDatabase;
\r
25 import com.trolltech.qt.sql.QSqlQuery;
\r
27 import cx.fbn.nevernote.Global;
\r
29 public class WordFilter {
\r
30 private final List<String> wordList;
\r
33 public WordFilter(QSqlDatabase d, List<String> list) {
\r
36 QSqlQuery query = new QSqlQuery(db);
\r
37 QSqlQuery insert = new QSqlQuery(db);
\r
39 if (wordList == null)
\r
41 if (wordList.size() == 0)
\r
43 query.exec("create temporary table guidList (guid text)");
\r
45 query.exec("delete from guidList");
\r
47 query.prepare("Select guid from words where word like :word and weight>=:weight");
\r
48 insert.prepare("insert into guidList (guid) values (:guid)");
\r
49 for (int i=0; i<wordList.size(); i++) {
\r
50 query.bindValue(":word", wordList.get(i)+"%");
\r
51 query.bindValue(":weight", Global.getRecognitionWeight());
\r
52 if (!query.exec()) {
\r
53 Global.logger.log(Global.logger.LOW, query.lastError().toString());
\r
55 while (query.next()) {
\r
56 insert.bindValue(":guid", query.value(0).toString());
\r
67 public boolean contains(String guid) {
\r
68 if (wordList.size() == 0)
\r
70 QSqlQuery query = new QSqlQuery(db);
\r
71 query.prepare("select count(guid) from guidList where guid=:guid");
\r
72 query.bindValue("guid", guid);
\r
74 while (query.next()) {
\r
75 Integer count = new Integer(query.value(0).toString());
\r
76 if (count >= wordList.size()) {
\r