Repository navigation
feat: enhance filename index status handling and pinyin output - #408
Conversation
Extended filename search capabilities with improved index status evaluation and pinyin metadata support. Updated index status handling to better distinguish between scanning/monitoring states, ensuring search reliability during various index operations. Added pinyin and pinyin acronym fields to search results when available from the filename index. Changes: 1. Enhanced index status evaluation with new logic focusing on createInProgress and updateInProgress flags 2. Renamed status.json to index_status.json and updated path to use QStandardPaths 3. Added pinyin and pinyin acronym getters/setters to FileNameResultAPI 4. Updated indexed strategy to extract pinyin data from Lucene documents 5. Enhanced JSON and text output formats to include pinyin metadata when available 6. Added comprehensive test cases for pinyin output and index status mapping Log: Added pinyin metadata to search results and improved index status reliability detection Influence: 1. Test search results with Chinese filenames to verify pinyin metadata appears in JSON/text output 2. Verify pinyin fields only appear when detailed results are enabled 3. Test that plain filename results without pinyin do not output empty pinyin keys 4. Verify index status accurately reflects scanning vs monitoring states during index operations 5. Test search behavior during index creation/recovery operations to ensure proper fallback 6. Validate that index status unavailable warning appears when no local index exists feat: 增强文件名索引状态处理和拼音输出 扩展了文件名搜索功能,改进了索引状态评估和拼音元数据支持。更新了索引状态 处理逻辑,更好地区分扫描/监控状态,确保在各种索引操作期间的搜索可靠性。 当文件名索引中可用时,搜索结果中添加拼音和拼音首字母字段。 变更内容: 1. 增强索引状态评估逻辑,重点关注 createInProgress 和 updateInProgress 标志 2. 将 status.json 重命名为 index_status.json 并使用 QStandardPaths 更新 路径 3. 为 FileNameResultAPI 添加拼音和拼音首字母的getter/setter方法 4. 更新索引策略以从Lucene文档中提取拼音数据 5. 增强JSON和文本输出格式,当可用时包含拼音元数据 6. 为拼音输出和索引状态映射添加全面的测试用例 Log: 在搜索结果中添加拼音元数据并改进索引状态可靠性检测 Influence: 1. 测试包含中文文件名的搜索结果,验证拼音元数据是否出现在JSON/文本输出中 2. 验证拼音字段仅在详细结果启用时出现 3. 测试没有拼音的普通文件名结果不会输出空的拼音键 4. 验证索引状态在索引操作期间准确反映扫描与监控状态 5. 测试索引创建/恢复操作期间的搜索行为,确保正确的回退机制 6. 验证当没有本地索引时会出现索引状态不可用警告
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Johnson-zs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideThe PR makes filename-index reliability decisions from the new persisted status schema, including safer fallback behavior during creation, recovery, and backlog processing, while carrying indexed pinyin metadata through the result API into detailed JSON and text output with focused tests. Sequence diagram for filename search with index readiness and pinyin outputsequenceDiagram
participant Client
participant SearchUtility
participant FilenameIndex
participant Output
Client->>SearchUtility: isFileNameIndexReadyForSearch()
SearchUtility->>FilenameIndex: readFileNameIndexStatusFile()
FilenameIndex-->>SearchUtility: index_status.json
SearchUtility-->>Client: ready or fallback to realtime search
Client->>FilenameIndex: processDetailedSearchResult()
FilenameIndex-->>Client: SearchResult with pinyin and pinyinAcronym
Client->>Output: resultToJson() or printSearchResult()
Output-->>Client: detailed output with non-empty pinyin fields
State diagram for filename index status mappingstateDiagram-v2
[*] --> Unavailable
Unavailable --> Scanning: invalid or missing status JSON
StatusLoaded --> Scanning: createInProgress or updateInProgress
StatusLoaded --> Updating: backlogExceeded
StatusLoaded --> Monitoring: lastUpdateTime present and no blocking flags
StatusLoaded --> Scanning: lastUpdateTime empty
Monitoring --> Ready: index directory exists
Scanning --> RealtimeFallback: index not trustworthy
Updating --> RealtimeFallback: index severely lagged
state StatusLoaded
state Monitoring
state Scanning
state Updating
state Unavailable
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/dfm-search/dfm-search-lib/utils/searchutility.cpp" line_range="762-764" />
<code_context>
- }
+ const QJsonObject root = doc.object();
+ fields.parsed = true;
+ fields.createInProgress = root.value("createInProgress").toBool(false);
+ fields.updateInProgress = root.value("updateInProgress").toBool(false);
+ fields.backlogExceeded = root.value("backlogExceeded").toBool(false);
+ fields.lastUpdateTime = root.value("lastUpdateTime").toString();
+ return fields;
</code_context>
<issue_to_address>
**Malformed status trusts an updating index**
When a status JSON object has a non-boolean progress flag and a non-empty `lastUpdateTime`, `parseFileNameIndexStatusJson()` converts the malformed flag to `false` with `toBool(false)`, so `fileNameIndexReadyForSearchFromJson()` can authorize searches against an index whose status is untrustworthy. Callers can receive stale or incomplete results.
Validate the JSON types of the progress flags and `lastUpdateTime`, and reject the status object when any field has the wrong type.
</issue_to_address>
### Comment 2
<location path="src/dfm-search/dfm-search-lib/utils/searchutility.cpp" line_range="838-839" />
<code_context>
QString fileNameIndexDirectory()
{
- return QString("/run/user/%1/deepin-anything-server").arg(getuid());
+ return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)
+ + "/deepin/dde-file-manager/filename-index";
}
</code_context>
<issue_to_address>
**Existing filename indexes disappear**
When an installation or older producer still uses `/run/user/<uid>/deepin-anything-server` and the new directory has not been populated, `fileNameIndexDirectory()` and its readers look only in the new data location, so they miss the legacy index and status file. Indexed filename searches become unavailable or lose existing results, and semantic searches fall back to slower realtime traversal.
Migrate the legacy index and status file or keep a fallback that reads the legacy location until the new location is populated.
Also at `src/dfm-search/dfm-search-lib/utils/searchutility.cpp:840`.
</issue_to_address>
### Comment 3
<location path="src/dfm-search/dfm-search-lib/utils/searchutility.cpp" line_range="828-830" />
<code_context>
+
+std::optional<QString> fileNameIndexStatusFromJson(const QByteArray &jsonContent)
{
- if (!isFileNameIndexDirectoryAvailable()) {
- qWarning() << "Index directory not available";
+ const FileNameIndexStatusFields fields = parseFileNameIndexStatusJson(jsonContent);
+ if (!fields.parsed)
return std::nullopt;
- }
</code_context>
<issue_to_address>
**In-progress status appears unavailable**
When the status JSON reports creation or an update before Lucene has a committed index, `fileNameIndexStatus()` checks index availability before reading the status file, so it returns `nullopt` even when the file reports an in-progress state. Callers see status unavailable instead of `scanning`.
Read and map the status file before requiring a readable Lucene index.
</issue_to_address>| fields.createInProgress = root.value("createInProgress").toBool(false); | ||
| fields.updateInProgress = root.value("updateInProgress").toBool(false); | ||
| fields.backlogExceeded = root.value("backlogExceeded").toBool(false); |
There was a problem hiding this comment.
🟡 Medium · Malformed status trusts an updating index
When a status JSON object has a non-boolean progress flag and a non-empty lastUpdateTime, parseFileNameIndexStatusJson() converts the malformed flag to false with toBool(false), so fileNameIndexReadyForSearchFromJson() can authorize searches against an index whose status is untrustworthy. Callers can receive stale or incomplete results.
Validate the JSON types of the progress flags and lastUpdateTime, and reject the status object when any field has the wrong type.
Prompt for AI agents
In `src/dfm-search/dfm-search-lib/utils/searchutility.cpp` at lines 762-764:
**Malformed status trusts an updating index**
When a status JSON object has a non-boolean progress flag and a non-empty `lastUpdateTime`, `parseFileNameIndexStatusJson()` converts the malformed flag to `false` with `toBool(false)`, so `fileNameIndexReadyForSearchFromJson()` can authorize searches against an index whose status is untrustworthy. Callers can receive stale or incomplete results.
Validate the JSON types of the progress flags and `lastUpdateTime`, and reject the status object when any field has the wrong type.| return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) | ||
| + "/deepin/dde-file-manager/filename-index"; |
There was a problem hiding this comment.
🟠 High · Existing filename indexes disappear
When an installation or older producer still uses /run/user/<uid>/deepin-anything-server and the new directory has not been populated, fileNameIndexDirectory() and its readers look only in the new data location, so they miss the legacy index and status file. Indexed filename searches become unavailable or lose existing results, and semantic searches fall back to slower realtime traversal.
Migrate the legacy index and status file or keep a fallback that reads the legacy location until the new location is populated.
Also at src/dfm-search/dfm-search-lib/utils/searchutility.cpp:840.
Prompt for AI agents
In `src/dfm-search/dfm-search-lib/utils/searchutility.cpp` at lines 838-839:
**Existing filename indexes disappear**
When an installation or older producer still uses `/run/user/<uid>/deepin-anything-server` and the new directory has not been populated, `fileNameIndexDirectory()` and its readers look only in the new data location, so they miss the legacy index and status file. Indexed filename searches become unavailable or lose existing results, and semantic searches fall back to slower realtime traversal.
Migrate the legacy index and status file or keep a fallback that reads the legacy location until the new location is populated.
Also at `src/dfm-search/dfm-search-lib/utils/searchutility.cpp:840`.| if (!isFileNameIndexDirectoryAvailable()) { | ||
| qWarning() << "Index directory not available"; | ||
| return std::nullopt; |
There was a problem hiding this comment.
🟡 Medium · In-progress status appears unavailable
When the status JSON reports creation or an update before Lucene has a committed index, fileNameIndexStatus() checks index availability before reading the status file, so it returns nullopt even when the file reports an in-progress state. Callers see status unavailable instead of scanning.
Read and map the status file before requiring a readable Lucene index.
Prompt for AI agents
In `src/dfm-search/dfm-search-lib/utils/searchutility.cpp` at lines 828-830:
**In-progress status appears unavailable**
When the status JSON reports creation or an update before Lucene has a committed index, `fileNameIndexStatus()` checks index availability before reading the status file, so it returns `nullopt` even when the file reports an in-progress state. Callers see status unavailable instead of `scanning`.
Read and map the status file before requiring a readable Lucene index.
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 1.索引状态优先级逻辑(createInProgress > updateInProgress > backlogExceeded > state)设计合理,边界条件处理完善 2. 代码质量 ✅评价: 良好 ✅ 通过 潜在问题:
建议: 1.parseFileNameIndexStatusJson 提取为共享辅助函数,有效避免代码重复 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 1.拼音数据提取使用 Lucene doc->get() 为 O(1) 查找,无性能影响 4. 代码安全 🔒存在0个安全漏洞 评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 1.文件路径使用 QStandardPaths 系统标准路径,非用户输入,无路径遍历风险 💡 改进建议代码示例// 修复建议:恢复诊断日志并显式关闭文件
QByteArray readFileNameIndexStatusFile()
{
const QString &statusFilePath = QDir(fileNameIndexDirectory()).filePath("index_status.json");
QFile statusFile(statusFilePath);
if (!statusFile.exists()) {
qWarning() << "Status file does not exist:" << statusFilePath;
return {};
}
if (!statusFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << "Failed to open status file:" << statusFile.errorString();
return {};
}
const QByteArray content = statusFile.readAll();
statusFile.close();
return content;
}
FileNameIndexStatusFields parseFileNameIndexStatusJson(const QByteArray &jsonContent)
{
FileNameIndexStatusFields fields;
QJsonParseError jsonError;
const QJsonDocument doc = QJsonDocument::fromJson(jsonContent, &jsonError);
if (jsonError.error != QJsonParseError::NoError || !doc.isObject()) {
qWarning() << "Failed to parse index status JSON:" << jsonError.errorString();
return fields;
}
// ... rest of parsing logic
}本报告由 AI 代码审查工具自动生成 |
|
/forcemerge |
|
This pr force merged! (status: blocked) |
Extended filename search capabilities with improved index status
evaluation and pinyin metadata support. Updated index status handling to
better distinguish between scanning/monitoring states, ensuring search
reliability during various index operations. Added pinyin and pinyin
acronym fields to search results when available from the filename index.
Changes:
createInProgress and updateInProgress flags
QStandardPaths
when available
mapping
Log: Added pinyin metadata to search results and improved index status
reliability detection
Influence:
appears in JSON/text output
pinyin keys
during index operations
ensure proper fallback
index exists
feat: 增强文件名索引状态处理和拼音输出
扩展了文件名搜索功能,改进了索引状态评估和拼音元数据支持。更新了索引状态
处理逻辑,更好地区分扫描/监控状态,确保在各种索引操作期间的搜索可靠性。
当文件名索引中可用时,搜索结果中添加拼音和拼音首字母字段。
变更内容:
标志
路径
Log: 在搜索结果中添加拼音元数据并改进索引状态可靠性检测
Influence:
Summary by Sourcery
Improve filename index reliability and include available pinyin metadata in detailed search results.
New Features:
Bug Fixes:
Enhancements:
Tests: