From cdaa86b9a0c1617d02723ba0a90dd332c84ed106 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sat, 13 Nov 2021 12:30:52 +0100 Subject: [PATCH] Result list snippets: incorrect page number detection could sometimes prevent highlighting --- src/query/reslistpager.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/query/reslistpager.cpp b/src/query/reslistpager.cpp index 1c63d625..5257b34a 100644 --- a/src/query/reslistpager.cpp +++ b/src/query/reslistpager.cpp @@ -148,6 +148,8 @@ void ResListPager::resultPageFor(int docnum) m_respage = npage; } +static const SimpleRegexp pagenumre("(^ *\\[[pP]\\.* [0-9]+\\])", 0); + void ResListPager::displayDoc(RclConfig *config, int i, Rcl::Doc& doc, const HighlightData& hdata, const string& sh) { @@ -220,23 +222,26 @@ void ResListPager::displayDoc(RclConfig *config, int i, Rcl::Doc& doc, string richabst; bool needabstract = parFormat().find("%A") != string::npos; if (needabstract && m_docSource) { - vector vabs; - m_docSource->getAbstract(doc, vabs); + vector snippets; + m_docSource->getAbstract(doc, snippets); m_hiliter->set_inputhtml(false); - for (vector::const_iterator it = vabs.begin(); - it != vabs.end(); it++) { - if (!it->empty()) { + for (const auto& snippet : snippets) { + if (!snippet.empty()) { // No need to call escapeHtml(), plaintorich handles it list lr; - // There may be data like page numbers before the snippet text. - // will be in brackets. - string::size_type bckt = it->find("]"); - if (bckt == string::npos) { - m_hiliter->plaintorich(*it, lr, hdata); + // There may be data like page numbers before the snippet text. will be in + // brackets. + if (pagenumre.simpleMatch(snippet)) { + string pagenum = pagenumre.getMatch(snippet, 0); + if (!pagenum.empty()) { + m_hiliter->plaintorich(snippet.substr(pagenum.size()), lr, hdata); + lr.front() = snippet.substr(0, pagenum.size()) + lr.front(); + } else { + m_hiliter->plaintorich(snippet, lr, hdata); + } } else { - m_hiliter->plaintorich(it->substr(bckt), lr, hdata); - lr.front() = it->substr(0, bckt) + lr.front(); + m_hiliter->plaintorich(snippet, lr, hdata); } richabst += lr.front(); richabst += absSep();