From fd5ef403dd4a008469d75660d6807f23f41ae998 Mon Sep 17 00:00:00 2001 From: Zhang Sheng Date: Wed, 17 Jun 2026 15:22:44 +0800 Subject: [PATCH 1/2] feat: add configurable keyword positioning in search results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Added positioningMaxLength parameter to HighlightOptions structure to allow configuration of keyword positioning window size 2. Modified customHighlight function to accept and use this parameter for better keyword positioning in search results 3. Enforced minimum window size of 30 characters for proper keyword visibility 4. Updated all function calls to pass the new parameter 5. Improved documentation for the customHighlight function parameters Log: Added configurable keyword positioning window for better search result snippets Influence: 1. Test search results with different positioningMaxLength values (below 30 and above 30) 2. Verify keyword visibility and snippet positioning in results 3. Check HTML highlighting still works when enabled 4. Test with both short and long content samples 5. Verify behavior with empty content or keyword lists feat: 添加可配置的关键词定位功能 1. 在HighlightOptions结构中添加positioningMaxLength参数,用于配置关键词 定位窗口大小 2. 修改customHighlight函数以接受并使用此参数,改进搜索结果中的关键词定位 3. 强制30个字符的最小窗口尺寸以确保关键词可见性 4. 更新所有函数调用以传递新参数 5. 改进了customHighlight函数的参数文档 Log: 新增可配置关键词定位窗口,改进搜索结果片段显示 Influence: 1. 使用不同的positioningMaxLength值测试搜索结果(小于30和大于30) 2. 验证结果中的关键词可见性和片段定位 3. 检查启用HTML高亮时是否仍正常工作 4. 测试短内容和长内容样本 5. 验证空内容或关键词列表时的行为 Fixes: #365083 --- include/dfm-search/dfm-search/contentretriever.h | 5 +++-- .../dfm-search-lib/utils/contenthighlighter.cpp | 10 +++++----- .../dfm-search-lib/utils/contenthighlighter.h | 7 ++++--- .../dfm-search-lib/utils/contentretriever.cpp | 6 ++++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/include/dfm-search/dfm-search/contentretriever.h b/include/dfm-search/dfm-search/contentretriever.h index 673f38e..17f6338 100644 --- a/include/dfm-search/dfm-search/contentretriever.h +++ b/include/dfm-search/dfm-search/contentretriever.h @@ -18,8 +18,9 @@ DFM_SEARCH_BEGIN_NS */ struct HighlightOptions { - int maxPreviewLength = 200; ///< Maximum snippet length in characters - bool enableHtml = false; ///< Wrap matched keywords with tags + int maxPreviewLength = 200; ///< Maximum snippet length in characters + int positioningMaxLength = 30; ///< Keyword positioning window size (min 30) + bool enableHtml = false; ///< Wrap matched keywords with tags }; /** diff --git a/src/dfm-search/dfm-search-lib/utils/contenthighlighter.cpp b/src/dfm-search/dfm-search-lib/utils/contenthighlighter.cpp index cc95dd1..e6f1c70 100644 --- a/src/dfm-search/dfm-search-lib/utils/contenthighlighter.cpp +++ b/src/dfm-search/dfm-search-lib/utils/contenthighlighter.cpp @@ -155,7 +155,7 @@ KeywordMatch findFirstKeywordMatch(const QString &content, const QStringList &ke } } // namespace -QString customHighlight(const QStringList &keywords, const QString &content, int maxLength, bool enableHtml) +QString customHighlight(const QStringList &keywords, const QString &content, int maxLength, bool enableHtml, int positioningMaxLength) { if (content.isEmpty() || keywords.isEmpty()) { return QString(); @@ -191,13 +191,13 @@ QString customHighlight(const QStringList &keywords, const QString &content, int return match.keyword; // Return the keyword as is (original behavior) } - // This is the "30 characters" from the requirement, used for positioning the keyword. - const int positioningMaxLength = 30; + // Enforce minimum of 30 for the positioning window + const int effectivePositioningLength = qMax(30, positioningMaxLength); // 1. Calculate the optimal start position. // This start position is determined based on making the keyword visible - // and well-positioned within a `positioningMaxLength` (e.g., 80 char) window. - int optimalStart = findOptimalStartPosition(content, match.position, positioningMaxLength); + // and well-positioned within the positioning window. + int optimalStart = findOptimalStartPosition(content, match.position, effectivePositioningLength); // 2. Calculate the optimal end position. // This uses the `optimalStart` calculated above and extends the snippet diff --git a/src/dfm-search/dfm-search-lib/utils/contenthighlighter.h b/src/dfm-search/dfm-search-lib/utils/contenthighlighter.h index e926fd6..fbaffdd 100644 --- a/src/dfm-search/dfm-search-lib/utils/contenthighlighter.h +++ b/src/dfm-search/dfm-search-lib/utils/contenthighlighter.h @@ -33,11 +33,12 @@ namespace ContentHighlighter { * * @param keywords A list of search keywords (supports wildcards *, ?). * @param content The original document content to be searched. - * @param maxLength The maximum length of the returned snippet (used when no line breaks are present). - * @param enableHtml Whether to wrap matched keywords with tags for highlighting. + * @param maxLength The maximum length of the returned snippet (used when no line breaks are present). + * @param enableHtml Whether to wrap matched keywords with tags for highlighting. + * @param positioningMaxLength Keyword positioning window size for finding the optimal snippet start/end (min 30). * @return A snippet of content with matched keywords highlighted, or an empty string if no match is found. */ -QString customHighlight(const QStringList &keywords, const QString &content, int maxLength, bool enableHtml); +QString customHighlight(const QStringList &keywords, const QString &content, int maxLength, bool enableHtml, int positioningMaxLength = 30); } // namespace ContentHighlighter diff --git a/src/dfm-search/dfm-search-lib/utils/contentretriever.cpp b/src/dfm-search/dfm-search-lib/utils/contentretriever.cpp index 8dbc7c4..c86225c 100644 --- a/src/dfm-search/dfm-search-lib/utils/contentretriever.cpp +++ b/src/dfm-search/dfm-search-lib/utils/contentretriever.cpp @@ -219,7 +219,8 @@ QString ContentRetriever::fetchHighlight(const QString &path, } return ContentHighlighter::customHighlight( - keywords, content, options.maxPreviewLength, options.enableHtml); + keywords, content, options.maxPreviewLength, options.enableHtml, + options.positioningMaxLength); } catch (const LuceneException &e) { qWarning() << "ContentRetriever: error fetching highlight for" << path << QString::fromStdWString(e.getError()); @@ -260,7 +261,8 @@ QMap ContentRetriever::fetchHighlights(const QStringList &path } results.insert(path, ContentHighlighter::customHighlight( - keywords, content, options.maxPreviewLength, options.enableHtml)); + keywords, content, options.maxPreviewLength, options.enableHtml, + options.positioningMaxLength)); } catch (const LuceneException &e) { qWarning() << "ContentRetriever: error for" << path << QString::fromStdWString(e.getError()); From 551403eaf893616db7c97efd3abf639a0ae94b41 Mon Sep 17 00:00:00 2001 From: Zhang Sheng Date: Wed, 17 Jun 2026 15:23:12 +0800 Subject: [PATCH 2/2] chore: bump version to 1.3.59 1.3.59 Log: --- debian/changelog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/debian/changelog b/debian/changelog index 370cca3..067b874 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +util-dfm (1.3.59) unstable; urgency=medium + + * fix: improve symlink handling in filename search + * feat: add configurable keyword positioning in search results + + -- Zhang Sheng Wed, 17 Jun 2026 15:22:52 +0800 + util-dfm (1.3.58) unstable; urgency=medium * fix: simplify file timestamp attribute handling