Skip to content

feat: enhance OCR search with highlighting and config options#279

Merged
deepin-bot[bot] merged 3 commits intolinuxdeepin:masterfrom
Johnson-zs:master
Apr 23, 2026
Merged

feat: enhance OCR search with highlighting and config options#279
deepin-bot[bot] merged 3 commits intolinuxdeepin:masterfrom
Johnson-zs:master

Conversation

@Johnson-zs
Copy link
Copy Markdown
Contributor

  1. Added highlighting support for OCR text search results
  2. Implemented preview content length restriction for OCR results
  3. Added new configuration options for OCR text search:
    • Maximum preview length
    • Highlighting enable/disable toggle
    • Full text retrieval enable/disable toggle
  4. Updated command line interface and documentation for OCR search
    features
  5. Removed deprecated comments about lack of highlighting support
  6. Default max results changed to 0 (unlimited) from 100
  7. Added highlightedContent field in OCR result API

Log: Added OCR search result highlighting and preview features with
configurable options

Influence:

  1. Test OCR search with highlighting enabled/disabled
  2. Verify preview length restriction works as expected
  3. Test full text retrieval vs metadata only modes
  4. Check JSON and text output formats for highlighted content
  5. Test various max-results values including 0 (unlimited)
  6. Verify backward compatibility with existing OCR searches

feat: 增强OCR搜索功能,支持高亮和配置选项

  1. 为OCR文本搜索结果添加高亮支持
  2. 实现OCR结果预览内容长度限制
  3. 新增OCR文本搜索配置选项:
    • 最大预览长度
    • 高亮显示开关
    • 全文检索开关
  4. 更新命令行接口和文档以支持OCR搜索特性
  5. 移除关于不支持高亮的过时注释
  6. 默认最大结果数从100改为0(无限制)
  7. 在OCR结果API中添加highlightedContent字段

Log: 新增OCR搜索结果高亮和预览功能,支持配置选项

Influence:

  1. 测试启用/禁用高亮时的OCR搜索
  2. 验证预览长度限制是否正常工作
  3. 测试全文检索与仅元数据模式
  4. 检查高亮内容在JSON和文本输出格式中的显示
  5. 测试各种max-results值,包括0(无限制)
  6. 验证与现有OCR搜索功能的向后兼容性

@deepin-ci-robot
Copy link
Copy Markdown

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

1. Added highlighting support for OCR text search results
2. Implemented preview content length restriction for OCR results
3. Added new configuration options for OCR text search:
   - Maximum preview length
   - Highlighting enable/disable toggle
   - Full text retrieval enable/disable toggle
4. Updated command line interface and documentation for OCR search
features
5. Removed deprecated comments about lack of highlighting support
6. Default max results changed to 0 (unlimited) from 100
7. Added highlightedContent field in OCR result API

Log: Added OCR search result highlighting and preview features with
configurable options

Influence:
1. Test OCR search with highlighting enabled/disabled
2. Verify preview length restriction works as expected
3. Test full text retrieval vs metadata only modes
4. Check JSON and text output formats for highlighted content
5. Test various max-results values including 0 (unlimited)
6. Verify backward compatibility with existing OCR searches

feat: 增强OCR搜索功能,支持高亮和配置选项

1. 为OCR文本搜索结果添加高亮支持
2. 实现OCR结果预览内容长度限制
3. 新增OCR文本搜索配置选项:
   - 最大预览长度
   - 高亮显示开关
   - 全文检索开关
4. 更新命令行接口和文档以支持OCR搜索特性
5. 移除关于不支持高亮的过时注释
6. 默认最大结果数从100改为0(无限制)
7. 在OCR结果API中添加highlightedContent字段

Log: 新增OCR搜索结果高亮和预览功能,支持配置选项

Influence:
1. 测试启用/禁用高亮时的OCR搜索
2. 验证预览长度限制是否正常工作
3. 测试全文检索与仅元数据模式
4. 检查高亮内容在JSON和文本输出格式中的显示
5. 测试各种max-results值,包括0(无限制)
6. 验证与现有OCR搜索功能的向后兼容性
1. Created new base classes TextSearchOptionsAPI and TextSearchResultAPI
2. Moved common functionality from ContentSearch and OcrTextSearch to
base classes
3. Changed ContentOptionsAPI and OcrTextOptionsAPI to inherit from
TextSearchOptionsAPI
4. Changed ContentResultAPI and OcrTextResultAPI to inherit from
TextSearchResultAPI
5. Consolidated duplicate code for preview length, highlighting, file
attributes and timestamps
6. Updated implementation files to reflect inheritance changes

The changes introduce better code organization by:
1. Removing duplicate code across different search types
2. Creating a clear hierarchy for search API classes
3. Making it easier to maintain and extend common functionality
4. Following DRY (Don't Repeat Yourself) principle
5. Increasing default preview length from 50 to 200 characters

All existing functionality remains the same, only the implementation
structure changed.

refactor: 重构文本搜索API结构

1. 创建新的基类TextSearchOptionsAPI和TextSearchResultAPI
2. 将ContentSearch和OcrTextSearch中的通用功能移至基类
3. 修改ContentOptionsAPI和OcrTextOptionsAPI继承自TextSearchOptionsAPI
4. 修改ContentResultAPI和OcrTextResultAPI继承自TextSearchResultAPI
5. 整合预览长度、高亮显示、文件属性和时间戳处理的重复代码
6. 更新实现文件以反映继承关系变化

这些改动通过以下方式改善了代码组织:
1. 消除了不同类型搜索间的重复代码
2. 为搜索API类创建了清晰的层次结构
3. 使得维护和扩展通用功能更加容易
4. 遵循DRY(不要重复自己)原则
5. 将默认预览长度从50字符增加到200字符

所有现有功能保持不变,仅改变了实现结构。
Moved test object creation function declarations to file scope for
better organization
Added TextSearchAPI test suite to the main test runner
Previously only DfmSearch, SearchUtils and TimeRangeFilter tests were
executed
Now TextSearchAPI tests will also be run as part of the test suite
This ensures comprehensive testing coverage for all search-related
components

The change maintains backward compatibility while extending the test
coverage

Influence:
1. Verify all existing tests still pass
2. Check TextSearchAPI tests are executed and report results correctly
3. Ensure test suite exits with correct status code
4. Confirm no memory leaks from test object creation/deletion

test: 在测试运行器中添加 TextSearchAPI 测试

将测试对象创建函数声明移至文件作用域以便更好组织
在主要测试运行器中添加了 TextSearchAPI 测试套件
之前仅执行了 DfmSearch、SearchUtils 和 TimeRangeFilter 测试
现在 TextSearchAPI 测试也将作为测试套件的一部分运行
此变更确保了对所有搜索相关组件的全面测试覆盖

该变更在保持向后兼容的同时扩展了测试范围

Influence:
1. 验证所有现有测试仍能通过
2. 检查 TextSearchAPI 测试是否被执行并正确报告结果
3. 确保测试套件以正确的状态码退出
4. 确认测试对象创建/删除不会导致内存泄漏
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

Git Diff 代码审查报告

总体评价

这次提交引入了一个新的基类 TextSearchOptionsAPITextSearchResultAPI,用于重构内容搜索和OCR文本搜索的API,实现了代码复用和更好的类层次结构。整体设计合理,但存在一些可以改进的地方。

详细审查

1. 语法和逻辑

1.1 contentsearchapi.cpp 中的拼写错误

if (!m_options.hasCustomOption("searchResultHighligh"))  // 拼写错误

问题searchResultHighligh 应该是 searchResultHighlight(缺少了最后的 't')。
建议:修正拼写错误,确保与 TextSearchOptionsAPI 中使用的键名一致。

1.2 cli_options.cpp 中的默认值修改

m_maxResultsOption(QStringList() << "max-results", "Maximum number of results (0 for unlimited)", "number", "0"),

问题:将默认值从100改为0(无限制)是一个重大行为变更。
建议

  1. 考虑是否真的需要这个变更,如果需要,应该在文档中明确说明
  2. 在帮助信息中更清楚地说明0表示无限制
  3. 考虑添加一个验证机制,确保用户理解0的含义

2. 代码质量

2.1 测试覆盖

优点:添加了全面的单元测试 tst_textsearch_api.cpp,覆盖了新API的所有功能。
建议

  1. 考虑添加边界条件测试,例如:
    • setMaxPreviewLength(-1) 应该如何处理?
    • 超大文本内容的高亮处理
  2. 添加性能测试,特别是对于OCR内容高亮处理

2.2 代码重复

问题:在 indexedstrategy.cpp 中,OCR内容高亮处理逻辑可能会与内容搜索中的类似代码重复。
建议

  1. 确保高亮处理逻辑在 ContentHighlighter 类中实现,并在所有搜索类型中复用
  2. 考虑将高亮处理逻辑提取到一个公共位置,避免重复

3. 代码性能

3.1 OCR内容高亮处理

const QString highlightedContent = ContentHighlighter::customHighlight(
    m_keywords, content, previewLen, enableHTML);

问题:对于大型OCR文本内容,高亮处理可能会消耗大量资源。
建议

  1. 考虑添加最大处理大小限制
  2. 对于非常大的内容,考虑异步处理或分块处理
  3. 添加性能监控,记录处理时间

3.2 结果处理

for (int32_t i = 0; i < docsSize; ++i) {
    // 处理每个文档
}

建议

  1. 考虑添加批处理机制,减少频繁的内存分配
  2. 对于大量结果,考虑添加进度回调,允许用户取消长时间运行的操作

4. 代码安全

4.1 异常处理

try {
    // 处理OCR内容
} catch (const Lucene::LuceneException &e) {
    qWarning() << "Exception retrieving OCR content field:" << QString::fromStdWString(e.getError());
} catch (const std::exception &e) {
    qWarning() << "Standard exception retrieving OCR content field:" << e.what();
}

优点:添加了适当的异常处理。
建议

  1. 考虑添加更详细的错误日志,包括文档路径和索引信息
  2. 对于关键错误,考虑添加错误计数器或错误报告机制

4.2 输入验证

问题:在 TextSearchOptionsAPI 中,对输入参数的验证不够充分。
建议

  1. 添加对 setMaxPreviewLength 的参数验证,确保非负
  2. 在设置高亮内容时,考虑添加HTML注入防护,特别是当 enableHTML 为true时

5. 其他建议

5.1 文档更新

问题:README.md 已更新,但可能需要更多细节。
建议

  1. 添加OCR搜索的性能说明和限制
  2. 提供OCR搜索的示例用例和预期结果
  3. 说明OCR搜索对系统资源的影响

5.2 API设计

问题TextSearchOptionsAPITextSearchResultAPI 的继承关系设计合理,但可以考虑进一步优化。
建议

  1. 考虑使用接口类(纯虚类)来定义契约,而不是具体实现
  2. 考虑添加工厂方法或构建器模式,简化复杂选项的创建

总结

这次提交引入了良好的代码重构,通过引入基类实现了代码复用和更清晰的类层次结构。主要改进点包括:

  1. 添加了全面的单元测试
  2. 实现了OCR文本搜索的高亮功能
  3. 改进了命令行工具的默认行为

需要改进的地方包括:

  1. 修正拼写错误
  2. 加强输入验证
  3. 优化性能,特别是OCR内容处理
  4. 完善文档和示例

总体而言,这是一个高质量的提交,通过一些小的改进可以使其更加健壮和高效。

@Johnson-zs
Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot
Copy link
Copy Markdown

deepin-bot Bot commented Apr 23, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot Bot merged commit 211ec3c into linuxdeepin:master Apr 23, 2026
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants