default to path search, not content, removed unneeded methods
This commit is contained in:
parent
3584d284c3
commit
46f51b9554
@ -15,11 +15,6 @@ SearchWorker::SearchWorker(const QString &dbpath)
|
|||||||
{
|
{
|
||||||
qDebug() << "failed to open database";
|
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)
|
QVector<SearchWorker::Command> SearchWorker::tokenize(QString expression)
|
||||||
@ -66,7 +61,7 @@ QVector<SearchWorker::Command> SearchWorker::tokenize(QString expression)
|
|||||||
result.append(Command("AND"));
|
result.append(Command("AND"));
|
||||||
}
|
}
|
||||||
wasbool = false;
|
wasbool = false;
|
||||||
result.append(Command("contains", loneword));
|
result.append(Command("path.contains", loneword));
|
||||||
}
|
}
|
||||||
if(filtername != "")
|
if(filtername != "")
|
||||||
{
|
{
|
||||||
@ -114,7 +109,7 @@ QString SearchWorker::createSql(const SearchWorker::Command &cmd)
|
|||||||
{
|
{
|
||||||
return " content.page = " + value;
|
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 ) )";
|
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;
|
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)
|
void SearchWorker::search(const QString &query)
|
||||||
{
|
{
|
||||||
|
@ -26,8 +26,6 @@ class SearchWorker : public QObject
|
|||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QSqlQuery *queryFile;
|
|
||||||
QSqlQuery *queryContent;
|
|
||||||
QVector<Command> tokenize(QString expression);
|
QVector<Command> tokenize(QString expression);
|
||||||
QString createSql(const Command &cmd);
|
QString createSql(const Command &cmd);
|
||||||
QString makeSql(const QVector<Command> &tokens);
|
QString makeSql(const QVector<Command> &tokens);
|
||||||
@ -36,8 +34,6 @@ public:
|
|||||||
SearchWorker();
|
SearchWorker();
|
||||||
SearchWorker(const QString &dbpath);
|
SearchWorker(const QString &dbpath);
|
||||||
public slots:
|
public slots:
|
||||||
void searchForFile(const QString &query);
|
|
||||||
void searchForContent(const QString &query);
|
|
||||||
void search(const QString &query);
|
void search(const QString &query);
|
||||||
signals:
|
signals:
|
||||||
void searchResultsReady(const QVector<SearchResult> &results);
|
void searchResultsReady(const QVector<SearchResult> &results);
|
||||||
|
Loading…
Reference in New Issue
Block a user