}
stopped = false;
- word = removeAccents(word);
if(word.indexOf("*")==-1)
word+="%";
+ qDebug() << word;
word = word.replace("*", "%");
+ qDebug() << word;
+ word = removeAccents(word);
+ qDebug() << word;
QSqlQuery cur(db);
cur.prepare("select word from dict where word like ? limit ?");
}
QString XdxfPlugin::search(QString key) {
+ if(_settings->value("cached") == "true")
+ return searchCache(key);
+ return searchFile(key);
+}
+
+
+
+QString XdxfPlugin::searchCache(QString key) {
+ qDebug() << "search cache";
+ QString result;
+ QString cacheFilePath = _settings->value("cache_path");
+ db.setDatabaseName(cacheFilePath);
+
+ if(!db.open()) {
+ qDebug() << "Database error" << db.lastError().text() << endl;
+ return searchFile(key);
+ }
+
+ QSqlQuery cur(db);
+ cur.prepare("select translation from dict where word like ? limit 1");
+ cur.addBindValue(key);
+ cur.exec();
+ if(cur.next())
+ result = cur.value(0).toString();
+ return result;
+
+}
+
+
+
+
+QString XdxfPlugin::searchFile(QString key) {
QFile dictionaryFile(path);
QString resultString("");
if(!dictionaryFile.open(QFile::ReadOnly | QFile::Text)) {
for(int i=0; i<normalized.size(); i++) {
if( !normalized[i].isLetterOrNumber() &&
!normalized[i].isSpace() &&
- !normalized[i].isDigit()) {
+ !normalized[i].isDigit() &&
+ normalized[i] != '*' &&
+ normalized[i] != '%') {
normalized.remove(i,1);
}
}
QSqlQuery cur(db);
cur.exec("PRAGMA synchronous = 0");
cur.exec("drop table dict");
- cur.exec("create table dict(word text ,transl text)");
QCoreApplication::processEvents();
+ cur.exec("create table dict(word text ,translation text)");
int counter = 0;
cur.exec("BEGIN;");