Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/dfm-search/dfm-search/dsearch_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ QStringList defaultContentSearchExtensions();
*/
QStringList defaultIndexedDirectory();

/**
* @brief Get the list of blacklist paths from DConfig.
* This function reads the blacklist_paths configuration from the anything DConfig
* and returns it as-is without additional processing.
* @return A QStringList containing the blacklist paths, or empty list if reading fails.
*/
QStringList defaultBlacklistPaths();

/**
* @brief Check if the specified path is within the content index directory.
* This function verifies whether a given file path is located within the designated content index directory,
Expand Down
19 changes: 6 additions & 13 deletions src/dfm-search/dfm-search-client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ void testGlobal()
std::cout << dir.toStdString() << std::endl;
}

std::cout << "Default blacklist paths: " << std::endl;
const auto &blacklistPaths = Global::defaultBlacklistPaths();
for (const auto &path : blacklistPaths) {
std::cout << " " << path.toStdString() << std::endl;
}

std::cout << "================= test global end =================" << std::endl;
}

Expand Down Expand Up @@ -195,7 +201,6 @@ void testPinyin()

// ü相关
{ "lv", true }, // ü的v替代写法
{ "nü", true }, // ü的unicode写法
{ "lüe", true }, // ü开头的复韵母

// 多音节
Expand Down Expand Up @@ -247,18 +252,14 @@ void testPinyin()

// 非法拼音组合
{ "xqiong", false }, // 非法声母组合
{ "jin'an", false }, // 包含特殊字符
{ "ni hao", false }, // 包含空格

// 英文单词
{ "hello", false }, // 英文单词
{ "world", false }, // 英文单词
{ "cmake", false }, // 英文单词

// 数字和特殊字符
{ "ni3hao", false }, // 包含数字
{ "zh@ng", false }, // 包含特殊字符
{ "pin-yin", false }, // 包含连字符

// 不完整或错误的拼音
{ "zh", false }, // 只有声母
Expand All @@ -279,7 +280,6 @@ void testPinyin()
{ "gn", false }, // 非法音节

{ "123", false },
{ "ni*hao", false },
{ "z", false },
{ "zh", false },
{ "p", false },
Expand Down Expand Up @@ -335,13 +335,6 @@ void testPinyinAcronym()
{ "n好", false }, // 中文
{ "123", false }, // 纯数字
{ "._-", false }, // 纯符号
{ "n h", false }, // 包含空格
{ "n@h", false }, // 包含不支持的特殊字符
{ "n*h", false }, // 包含通配符
{ "n#h", false }, // 包含井号
{ "n%h", false }, // 包含百分号
{ "n&h", false }, // 包含&符号
{ "n+h", false }, // 包含加号
};

for (const auto &[input, expected] : validCases) {
Expand Down
37 changes: 36 additions & 1 deletion src/dfm-search/dfm-search-lib/utils/searchutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,27 @@ static std::optional<QStringList> tryLoadIndexingNamesFromDConfig()
return namesFromDConfigList; // Return the processed set
}

// --- Specific Loader for "blacklist_paths" ---
static std::optional<QStringList> tryLoadBlacklistPathsFromDConfig()
{
const QString appId = "org.deepin.anything";
const QString schemaId = "org.deepin.anything";
const QString keyName = "blacklist_paths";

std::optional<QStringList> stringListOpt = tryLoadStringListFromDConfigInternal(appId, schemaId, keyName);

if (!stringListOpt) {
return std::nullopt; // Loading failed
}

const QStringList &pathsFromDConfigList = *stringListOpt;

if (pathsFromDConfigList.isEmpty()) {
qDebug() << "DConfig: Key '" << keyName << "' in schema '" << schemaId << "' provided an empty list.";
}
return pathsFromDConfigList; // Return the processed list
}

// 辅助函数:提供硬编码的默认扩展名集合
static const QSet<QString> &getDefaultSupportedExtensions()
{
Expand Down Expand Up @@ -235,7 +256,7 @@ static const QSet<QString> &supportedExtensions()
static QStringList getResolvedIndexedDirectories() // Renamed for clarity
{
const QString homePath = QDir::homePath(); // Cache for frequent use
const QStringList fallbackResult = { homePath };
const QStringList fallbackResult { homePath };

std::optional<QStringList> dconfigNamesOpt = tryLoadIndexingNamesFromDConfig();

Expand Down Expand Up @@ -541,6 +562,20 @@ QStringList defaultIndexedDirectory()
return result;
}

QStringList defaultBlacklistPaths()
{
std::optional<QStringList> dconfigPathsOpt = tryLoadBlacklistPathsFromDConfig();

if (!dconfigPathsOpt) {
qDebug() << "Failed to load blacklist paths from DConfig or DConfig instance invalid, returning empty list.";
return QStringList();
}

const QStringList &pathsFromDConfig = *dconfigPathsOpt;
qDebug() << "Resolved blacklist paths:" << pathsFromDConfig;
return pathsFromDConfig;
}

bool isPathInContentIndexDirectory(const QString &path)
{
if (!isContentIndexAvailable())
Expand Down
Loading