Repository navigation
fix: return empty instead of failure for textless images in OCR extractor - #304
Johnson-zs wants to merge 1 commit into
Conversation
…ctor 1. Root cause: OcrExtractor::extract() returned std::nullopt (failure) when the OCR engine succeeded but the cleaned text had fewer than 2 characters, treating "image has no text" as "extraction failed" 2. Fix: return QByteArray() (empty = success, no text) so the caller processes it as a successful extraction with empty content 3. Impact: textless images no longer interrupt index updates; callers already handle empty QByteArray via the success path fix: 修复OCR提取器对无文字图片返回失败导致索引更新中断 1. 根因:OcrExtractor::extract() 在OCR引擎成功识别但清洗后文本 不足2字符时返回std::nullopt(失败),将"图片无文字"误判为 "提取失败",导致索引更新中断 2. 方案:改为返回QByteArray()(空=成功无文本),使调用方走成功 路径处理空内容 3. 影响:无文字图片不再中断索引更新,调用方已兼容空QByteArray Log: Fixed OCR extractor returning failure for textless images, causing index update interruption Influence: - Test image text content search with images containing text - Test image text content search with textless images (wallpapers, solid colors) - Verify mixed folders with both text and textless images index completely Log: 修复OCR提取器对无文字图片误判为失败导致索引更新中断的问题 Influence: - 测试含文字图片的文本内容搜索索引 - 测试无文字图片(壁纸、纯色图)的文本内容搜索索引 - 验证混合文件夹(含文字+无文字图片)的索引完整性 PMS: BUG-384853
Reviewer's GuideImplementationTreat OCR results with fewer than two cleaned characters as successful empty extraction rather than failure.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[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 |
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/extractor/plugins/ocr-extractor/ocrextractor.cpp" line_range="334" />
<code_context>
- qDebug() << "OcrExtractor::extract: cleaned OCR result has less than 2 characters for:" << filePath;
- return std::nullopt;
+ qDebug() << "OcrExtractor::extract: image has no extractable text for:" << filePath;
+ return QByteArray();
}
</code_context>
<issue_to_address>
**Single-character OCR text disappears**
When OCR recognizes a meaningful single character and cleaning preserves it, `OcrExtractor::extract()` rejects the one-character result at the `< 2` guard and returns empty content, so `OcrDocumentBuilder` omits the OCR field and the character is not searchable.
Reject only empty cleaned results, allowing valid one-character OCR text to reach the index.
</issue_to_address>| qDebug() << "OcrExtractor::extract: cleaned OCR result has less than 2 characters for:" << filePath; | ||
| return std::nullopt; | ||
| qDebug() << "OcrExtractor::extract: image has no extractable text for:" << filePath; | ||
| return QByteArray(); |
There was a problem hiding this comment.
🟡 Medium · Single-character OCR text disappears
When OCR recognizes a meaningful single character and cleaning preserves it, OcrExtractor::extract() rejects the one-character result at the < 2 guard and returns empty content, so OcrDocumentBuilder omits the OCR field and the character is not searchable.
Reject only empty cleaned results, allowing valid one-character OCR text to reach the index.
Prompt for AI agents
In `src/extractor/plugins/ocr-extractor/ocrextractor.cpp` at line 334:
**Single-character OCR text disappears**
When OCR recognizes a meaningful single character and cleaning preserves it, `OcrExtractor::extract()` rejects the one-character result at the `< 2` guard and returns empty content, so `OcrDocumentBuilder` omits the OCR field and the character is not searchable.
Reject only empty cleaned results, allowing valid one-character OCR text to reach the index.|
基于错误分析创建,按纠偏 corr-01a22b17-1 返工关闭 |
Root Cause Analysis
OcrExtractor::extract()inocrextractor.cpp:334returnedstd::nullopt(failure) when the OCR engine successfully analyzed an image but the cleaned text had fewer than 2 characters. This treated "image has no text" (e.g., photos, wallpapers, solid-color images) as "extraction failed". The downstream callerExtractorApp::processBatch()(extractorapp.cpp:108) checksresult.has_value()—std::nullopttriggerssendFailed(), marking the image as failed. With 62–88% of images being textless, the overall index update failure rate exceeded the threshold, causing the UI to show "索引更新失败".Key evidence:
ocrextractor.cpp:332-334returnsstd::nulloptfor textless images;extractorapp.cpp:108-113sendssendFailedonstd::nullopt; repro demo confirmed Case 2 (textless) and Case 3 (engine failure) produce identicalsendFailedresults.Fix
Changed
return std::nullopt;toreturn QByteArray();atocrextractor.cpp:334, and updated the debug log message from "cleaned OCR result has less than 2 characters" to "image has no extractable text" to reflect the corrected semantics.QByteArray()is a successful extraction with empty content —has_value()returns true, so the caller walks thesendDatasuccess path, sending empty text. All downstream handlers (processextractor.cpp,taskhandler.cpp) already handle empty text via the success path.Change Safety Assessment
Code Safety
8d481bc(initial migration), not a historical bug fix — this change does not revert any existing fixExtractorApp::processBatch()already handles emptyQByteArrayviasendDatasuccess path; no signature or API changeBusiness Impact Scope
ocrextractor.cpp), extraction app (extractorapp.cpp), process extractor (processextractor.cpp)Verification Suggestion
根因分析
OcrExtractor::extract()(ocrextractor.cpp:334)在 OCR 引擎成功分析图片但清洗后文本不足 2 字符时返回std::nullopt(失败),将"图片无文字"(如照片、壁纸、纯色图片)误判为"提取失败"。下游调用者ExtractorApp::processBatch()(extractorapp.cpp:108)检查result.has_value(),std::nullopt触发sendFailed(),将该图片标记为提取失败。由于 62–88% 的图片为无文字图片,整体索引更新失败率超过阈值,导致 UI 显示"索引更新失败"。关键证据:
ocrextractor.cpp:332-334对无文字图片返回std::nullopt;extractorapp.cpp:108-113收到std::nullopt后发送sendFailed;复现验证器确认 Case 2(无文字)与 Case 3(引擎故障)产生相同的sendFailed结果。修复方案
将
ocrextractor.cpp:334的return std::nullopt;改为return QByteArray();,同时更新调试日志从"cleaned OCR result has less than 2 characters"改为"image has no extractable text"以反映修正后的语义。QByteArray()表示成功的空内容提取——has_value()返回 true,调用方走sendData成功路径,发送空文本。所有下游处理者(processextractor.cpp、taskhandler.cpp)已通过成功路径处理空文本。改动安全评估
代码安全评估
8d481bc(初始迁移)引入,非历史 bug 修复产物——本次改动不撤销任何已有修复ExtractorApp::processBatch()已通过sendData成功路径兼容空QByteArray,无签名或 API 变更业务影响范围
ocrextractor.cpp)、提取应用(extractorapp.cpp)、进程提取器(processextractor.cpp)验证建议
Summary by Sourcery
Bug Fixes: