Skip to content

Commit

Permalink
fix: 找图片类、音乐类功能的完善(无实体时)
Browse files Browse the repository at this point in the history
Description: 找图片类、音乐类功能的完善(无实体时)

Log: 找图片类、音乐类功能的完善(无实体时)
  • Loading branch information
lichaofan2008 authored and Clauszy committed Aug 9, 2024
1 parent b02827f commit 15a587e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "searcher/file/filesearchutils.h"
#include "global/builtinsearch.h"
#include "searcher/semantic/fileresultshandler.h"
#include "global/commontools.h"

using namespace GrandSearch;

Expand Down Expand Up @@ -80,8 +81,9 @@ bool AnythingQueryPrivate::searchUserPath(PushItemCallBack callBack, void *pdata
continue;

// 去除掉添加的data前缀
if (m_hasAddDataPrefix && absoluteFilePath.startsWith("/data"))
absoluteFilePath = absoluteFilePath.mid(5);
if (m_hasTransformed && absoluteFilePath.startsWith(m_searchPath))
absoluteFilePath.replace(m_searchPath, m_originalSearchPath);

m_count++;
if (m_handler) {
m_handler->appendTo(absoluteFilePath, items);
Expand Down Expand Up @@ -158,8 +160,8 @@ bool AnythingQueryPrivate::searchByAnything(PushItemCallBack callBack, void *pda
}

// 去除掉添加的data前缀
if (m_hasAddDataPrefix && path.startsWith("/data"))
path = path.mid(5);
if (m_hasTransformed && path.startsWith(m_searchPath))
path.replace(m_searchPath, m_originalSearchPath);

// 检查时间
QFileInfo info(path);
Expand Down Expand Up @@ -223,7 +225,7 @@ QString AnythingQueryPrivate::getRegExp() const
// 后缀名
QStringList suffixs = SemanticHelper::typeTosuffix(m_entity.types);
if (!suffixs.isEmpty())
regStr += QString(R"(\.(%0))").arg(suffixs.join('|'));
regStr += QString(R"(\.(%0)$)").arg(suffixs.join('|'));

return regStr;
}
Expand Down Expand Up @@ -270,17 +272,14 @@ void AnythingQuery::run(void *ptr, PushItemCallBack callBack, void *pdata)
bool useAnything = true;
if (!d->m_anythingInterface->hasLFT(d->m_searchPath)) {
// 有可能 anything 不支持/home目录,但是支持/data/home
if (QFile("/data/home").exists()) {
d->m_searchPath.prepend("/data");
if (!d->m_anythingInterface->hasLFT(d->m_searchPath)) {
qWarning() << "Do not support quick search for " << d->m_searchPath;
useAnything = false;
} else {
d->m_hasAddDataPrefix = true;
}
} else {
qWarning() << "Data path is not exist!";
const QString &tmpPath = CommonTools::bindPathTransform(d->m_searchPath, true);
if (!d->m_anythingInterface->hasLFT(tmpPath)) {
qWarning() << "Do not support quick search for " << tmpPath;
useAnything = false;
} else {
d->m_originalSearchPath = d->m_searchPath;
d->m_searchPath = tmpPath;
d->m_hasTransformed = true;
}
}
d->m_time.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ class AnythingQueryPrivate
ComDeepinAnythingInterface *m_anythingInterface = nullptr;
SemanticEntity m_entity;
QString m_searchPath;
QString m_originalSearchPath;
bool m_hasTransformed = false;

QStringList m_searchDirList;
bool m_hasAddDataPrefix = false;
FileResultsHandler *m_handler = nullptr;
QTime m_time;
int m_lastPush = 0;
Expand Down
18 changes: 17 additions & 1 deletion src/libgrand-search-daemon/searcher/semantic/semantichelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@ bool SemanticHelper::entityFromJson(const QString &json, SemanticEntity &out)
for (auto ro = entityObj.begin(); ro != entityObj.end(); ++ro) {
if (ro->isString()){
QString key = ro->toString().trimmed();
if (!key.isEmpty())
if (!key.isEmpty()) {
// 去除模型概率性带出的[SEP]...后缀
int pos = key.indexOf("[");
if (pos != -1) {
key = key.mid(0, pos);
}
out.keys.append(key);
}
}
}

Expand Down Expand Up @@ -113,6 +119,16 @@ bool SemanticHelper::entityFromJson(const QString &json, SemanticEntity &out)
for (const QString &txt : timeOfKey)
out.keys.removeOne(txt);

// 组装log打印内容,方便查看
QString types, keys;
for (const QString &str : out.types) {
types.append(str).append(", ");
}
for (const QString &str : out.keys) {
keys.append(str).append(", ");
}
qInfo() << QString("types(%1) keys(%2)").arg(types).arg(keys);

return true;
}

Expand Down

0 comments on commit 15a587e

Please sign in to comment.