default to path search, not content, removed unneeded methods

This commit is contained in:
Albert S. 2018-09-02 12:38:07 +02:00
parent 3584d284c3
commit 46f51b9554
2 changed files with 2 additions and 43 deletions

View File

@ -15,11 +15,6 @@ SearchWorker::SearchWorker(const QString &dbpath)
{
qDebug() << "failed to open database";
}
queryContent = new QSqlQuery(db);
queryFile = new QSqlQuery(db);
queryFile->prepare("SELECT path, mtime FROM file WHERE path LIKE ? ORDER BY mtime DESC");
queryContent->prepare("SELECT file.path, content.page, file.mtime FROM file INNER JOIN content ON file.id = content.fileid INNER JOIN content_fts ON content.id = content_fts.ROWID WHERE content_fts.content MATCH ? ORDER By file.mtime DESC, content.page ASC");
}
QVector<SearchWorker::Command> SearchWorker::tokenize(QString expression)
@ -66,7 +61,7 @@ QVector<SearchWorker::Command> SearchWorker::tokenize(QString expression)
result.append(Command("AND"));
}
wasbool = false;
result.append(Command("contains", loneword));
result.append(Command("path.contains", loneword));
}
if(filtername != "")
{
@ -114,7 +109,7 @@ QString SearchWorker::createSql(const SearchWorker::Command &cmd)
{
return " content.page = " + value;
}
if(key == "contains")
if(key == "contains" || key == "c")
{
return " ( COALESCE( (SELECT 1 FROM content_fts WHERE content_fts.content MATCH '" + value + "' AND content_fts.ROWID= content.id), 0 ) )";
}
@ -132,38 +127,6 @@ QString SearchWorker::makeSql(const QVector<SearchWorker::Command> &tokens)
}
return result;
}
void SearchWorker::searchForFile(const QString &query)
{
QVector<SearchResult> results;
queryFile->addBindValue("%" + query + "%");
queryFile->exec();
while(queryFile->next())
{
SearchResult result;
result.page = 0;
result.path = queryFile->value(0).toString();
result.mtime = queryFile->value(1).toUInt();
results.append(result);
}
emit searchResultsReady(results);
}
void SearchWorker::searchForContent(const QString &query)
{
QVector<SearchResult> results;
queryContent->addBindValue(query);
queryContent->exec();
while(queryContent->next())
{
SearchResult result;
result.path = queryContent->value(0).toString();
result.page = queryContent->value(1).toUInt();
result.mtime = queryContent->value(2).toUInt();
results.append(result);
}
emit searchResultsReady(results);
}
void SearchWorker::search(const QString &query)
{

View File

@ -26,8 +26,6 @@ class SearchWorker : public QObject
Q_OBJECT
private:
QSqlQuery *queryFile;
QSqlQuery *queryContent;
QVector<Command> tokenize(QString expression);
QString createSql(const Command &cmd);
QString makeSql(const QVector<Command> &tokens);
@ -36,8 +34,6 @@ public:
SearchWorker();
SearchWorker(const QString &dbpath);
public slots:
void searchForFile(const QString &query);
void searchForContent(const QString &query);
void search(const QString &query);
signals:
void searchResultsReady(const QVector<SearchResult> &results);