Skip to content

Commit

Permalink
chore: Output log rectification
Browse files Browse the repository at this point in the history
Modify the search plug-in log

Log: Output log rectification
Task: https://pms.uniontech.com/task-view-278201.html
  • Loading branch information
Kakueeen authored and deepin-bot[bot] committed Jul 24, 2023
1 parent 5422598 commit c88beac
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ bool MainController::doSearchTask(QString taskId, const QUrl &url, const QString
stop(taskId);

auto task = new TaskCommander(taskId, url, keyword);
qInfo() << "new task: " << task << task->taskID();
Q_ASSERT(task);
qInfo() << "new task: " << task << task->taskID();

//直连,防止1被事件循环打乱时序
connect(task, &TaskCommander::matched, this, &MainController::matched, Qt::DirectConnection);
Expand Down Expand Up @@ -94,7 +94,9 @@ void MainController::onIndexFullTextSearchChanged(bool enable)
if (enable && !indexFuture.isRunning()) {
indexFuture = QtConcurrent::run([]() {
FullTextSearcher searcher(QUrl(), "");
qInfo() << "create index for full-text search";
searcher.createIndex("/");
qInfo() << "create index for full-text search done";
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ void TaskCommanderPrivate::working(AbstractSearcher *searcher)
AbstractSearcher *TaskCommanderPrivate::createFileNameSearcher(const QUrl &url, const QString &keyword)
{
bool isBindPath = false;
if (AnythingSearcher::isSupported(url, isBindPath))
if (AnythingSearcher::isSupported(url, isBindPath)) {
qInfo() << "Using anything for file name search";
return new AnythingSearcher(url, keyword, isBindPath, q);
}

if (FSearcher::isSupport(url))
if (FSearcher::isSupport(url)) {
qInfo() << "Using fsearch for file name search";
return new FSearcher(url, keyword, q);
}

qInfo() << "Using iterator for file name search";
return new IteratorSearcher(url, keyword, q);
}

Expand All @@ -58,7 +63,6 @@ void TaskCommanderPrivate::onUnearthed(AbstractSearcher *searcher)

void TaskCommanderPrivate::onFinished()
{
qDebug() << __FUNCTION__ << allSearchers.size() << finished << sender();
// 工作线程退出,若之前调用了deleteSelf那么在这里执行释放,否则发送结束信号
if (futureWatcher.isFinished()) {
if (deleted) {
Expand Down Expand Up @@ -117,7 +121,7 @@ bool TaskCommander::start()

void TaskCommander::stop()
{
qDebug() << "stop" << this->taskID();
qInfo() << "stop" << this->taskID();
d->futureWatcher.cancel();

for (auto searcher : d->allSearchers) {
Expand All @@ -144,6 +148,7 @@ void TaskCommander::createSearcher(const QUrl &url, const QString &keyword)
FullTextSearcher *searcher = new FullTextSearcher(url, keyword, this);
//直连,在线程处理
connect(searcher, &AbstractSearcher::unearthed, d, &TaskCommanderPrivate::onUnearthed, Qt::DirectConnection);
qInfo() << "Using Full-Text search";
d->allSearchers << searcher;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <dfm-base/base/device/deviceutils.h>
#include <dfm-base/utils/fileutils.h>
#include <dfm-base/base/application/application.h>
#include <dfm-base/base/schemefactory.h>

// Lucune++ headers
#include <FileUtils.h>
Expand All @@ -20,7 +21,6 @@

#include <QRegExp>
#include <QDebug>
#include <QFileInfo>
#include <QDateTime>
#include <QMetaEnum>
#include <QDir>
Expand Down Expand Up @@ -112,8 +112,10 @@ void FullTextSearcherPrivate::doIndexTask(const IndexReaderPtr &reader, const In
if (is_dir) {
doIndexTask(reader, writer, fn, type);
} else {
QFileInfo info(fn);
QString suffix = info.suffix();
auto info = InfoFactory::create<FileInfo>(QUrl::fromLocalFile(fn));
if (!info) continue;

QString suffix = info->nameOf(NameInfoType::kSuffix);
static QRegExp suffixRegExp(kSupportFiles);
if (suffixRegExp.exactMatch(suffix)) {
switch (type) {
Expand Down Expand Up @@ -172,7 +174,7 @@ void FullTextSearcherPrivate::indexDocs(const IndexWriterPtr &writer, const QStr
QMetaEnum enumType = QMetaEnum::fromType<FullTextSearcherPrivate::IndexType>();
qWarning() << QString(e.what()) << " type: " << enumType.valueToKey(type);
} catch (...) {
qWarning() << "Error: " << __FUNCTION__ << file;
qWarning() << "Index document failed! " << file;
}
}

Expand All @@ -192,8 +194,11 @@ bool FullTextSearcherPrivate::checkUpdate(const IndexReaderPtr &reader, const QS
return true;
} else {
DocumentPtr doc = searcher->doc(topDocs->scoreDocs[0]->doc);
QFileInfo info(file);
QString modifyTime = info.lastModified().toString("yyyyMMddHHmmss");
auto info = InfoFactory::create<FileInfo>(QUrl::fromLocalFile(file));
if (!info)
return false;

QString modifyTime = QString::number(info->timeOf(TimeInfoType::kLastModified).toLongLong());
String storeTime = doc->get(L"modified");

if (modifyTime.toStdWString() != storeTime) {
Expand All @@ -202,11 +207,11 @@ bool FullTextSearcherPrivate::checkUpdate(const IndexReaderPtr &reader, const QS
}
}
} catch (const LuceneException &e) {
qWarning() << "Error: " << __FUNCTION__ << QString::fromStdWString(e.getError()) << " file: " << file;
qWarning() << QString::fromStdWString(e.getError()) << " file: " << file;
} catch (const std::exception &e) {
qWarning() << "Error: " << __FUNCTION__ << QString(e.what()) << " file: " << file;
qWarning() << QString(e.what()) << " file: " << file;
} catch (...) {
qWarning() << "Error: " << __FUNCTION__ << " file: " << file;
qWarning() << "The file checked failed!" << file;
}

return false;
Expand All @@ -229,8 +234,8 @@ DocumentPtr FullTextSearcherPrivate::fileDocument(const QString &file)
doc->add(newLucene<Field>(L"path", file.toStdWString(), Field::STORE_YES, Field::INDEX_NOT_ANALYZED));

// file last modified time
QFileInfo info(file);
QString modifyTime = info.lastModified().toString("yyyyMMddHHmmss");
auto info = InfoFactory::create<FileInfo>(QUrl::fromLocalFile(file));
QString modifyTime = QString::number(info->timeOf(TimeInfoType::kLastModified).toLongLong());
doc->add(newLucene<Field>(L"modified", modifyTime.toStdWString(), Field::STORE_YES, Field::INDEX_NOT_ANALYZED));

// file contents
Expand Down Expand Up @@ -266,7 +271,8 @@ bool FullTextSearcherPrivate::createIndex(const QString &path)
QTime timer;
timer.start();
IndexWriterPtr writer = newIndexWriter(true);
qDebug() << "Indexing to directory: " << indexStorePath();
qInfo() << "Indexing to directory: " << indexStorePath();

writer->deleteAll();
doIndexTask(nullptr, writer, path, kCreate);
writer->optimize();
Expand All @@ -276,11 +282,11 @@ bool FullTextSearcherPrivate::createIndex(const QString &path)
status.storeRelease(AbstractSearcher::kCompleted);
return true;
} catch (const LuceneException &e) {
qWarning() << "Error: " << __FUNCTION__ << QString::fromStdWString(e.getError());
qWarning() << QString::fromStdWString(e.getError());
} catch (const std::exception &e) {
qWarning() << "Error: " << __FUNCTION__ << QString(e.what());
qWarning() << QString(e.what());
} catch (...) {
qWarning() << "Error: " << __FUNCTION__;
qWarning() << "The file index created failed!";
}

status.storeRelease(AbstractSearcher::kCompleted);
Expand All @@ -302,11 +308,11 @@ bool FullTextSearcherPrivate::updateIndex(const QString &path)

return true;
} catch (const LuceneException &e) {
qWarning() << "Error: " << __FUNCTION__ << QString::fromStdWString(e.getError());
qWarning() << QString::fromStdWString(e.getError());
} catch (const std::exception &e) {
qWarning() << "Error: " << __FUNCTION__ << QString(e.what());
qWarning() << QString(e.what());
} catch (...) {
qWarning() << "Error: " << __FUNCTION__;
qWarning() << "The file index updated failed!";
}

return false;
Expand Down Expand Up @@ -350,14 +356,15 @@ bool FullTextSearcherPrivate::doSearch(const QString &path, const QString &keywo
String resultPath = doc->get(L"path");

if (!resultPath.empty()) {
QFileInfo info(QString::fromStdWString(resultPath));
const QUrl &url = QUrl::fromLocalFile(StringUtils::toUTF8(resultPath).c_str());
auto info = InfoFactory::create<FileInfo>(url);
// delete invalid index
if (!info.exists()) {
indexDocs(writer, info.absoluteFilePath(), kDeleteIndex);
if (!info || !info->exists()) {
indexDocs(writer, url.path(), kDeleteIndex);
continue;
}

QString modifyTime = info.lastModified().toString("yyyyMMddHHmmss");
QString modifyTime = QString::number(info->timeOf(TimeInfoType::kLastModified).toLongLong());
String storeTime = doc->get(L"modified");
if (modifyTime.toStdWString() != storeTime) {
continue;
Expand All @@ -378,11 +385,11 @@ bool FullTextSearcherPrivate::doSearch(const QString &path, const QString &keywo
reader->close();
writer->close();
} catch (const LuceneException &e) {
qWarning() << "Error: " << __FUNCTION__ << QString::fromStdWString(e.getError());
qWarning() << QString::fromStdWString(e.getError());
} catch (const std::exception &e) {
qWarning() << "Error: " << __FUNCTION__ << QString(e.what());
qWarning() << QString(e.what());
} catch (...) {
qWarning() << "Error: " << __FUNCTION__;
qWarning() << "Search failed!";
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ bool SearchHelper::blockPaste(quint64 winId, const QList<QUrl> &fromUrls, const
Q_UNUSED(fromUrls)

if (to.scheme() == SearchHelper::scheme()) {
qDebug() << "The search root directory does not support paste!";
qInfo() << "The search root directory does not support paste!";
return true;
}
return false;
Expand Down

0 comments on commit c88beac

Please sign in to comment.