From 25d6d78902d65e9b3feda40bfad7a21bdcfcf324 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Fri, 7 Jan 2022 10:44:40 +0100 Subject: [PATCH] comments and justification --- src/qtgui/rclmain_w.h | 3 +-- src/qtgui/snippets_w.cpp | 52 ++++++++++++++------------------------- src/query/plaintorich.h | 5 ++-- src/rcldb/rclabstract.cpp | 11 +++------ src/rcldb/rcldb.cpp | 15 +++++------ src/rcldb/rclquery.cpp | 4 +-- 6 files changed, 34 insertions(+), 56 deletions(-) diff --git a/src/qtgui/rclmain_w.h b/src/qtgui/rclmain_w.h index 05899cb4..1c00932d 100644 --- a/src/qtgui/rclmain_w.h +++ b/src/qtgui/rclmain_w.h @@ -140,8 +140,7 @@ public slots: virtual void showActionsSearch(); virtual void startPreview(int docnum, Rcl::Doc doc, int keymods); virtual void startPreview(Rcl::Doc); - virtual void startNativeViewer(Rcl::Doc, int pagenum = -1, - QString term = QString()); + virtual void startNativeViewer(Rcl::Doc, int pagenum = -1, QString term = QString()); virtual void openWith(Rcl::Doc, string); virtual void saveDocToFile(Rcl::Doc); virtual void previewNextInTab(Preview *, int sid, int docnum); diff --git a/src/qtgui/snippets_w.cpp b/src/qtgui/snippets_w.cpp index 0e67a1bc..54c90e47 100644 --- a/src/qtgui/snippets_w.cpp +++ b/src/qtgui/snippets_w.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 J.F.Dockes +/* Copyright (C) 2012-2021 J.F.Dockes * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -67,8 +67,7 @@ using namespace std; class PlainToRichQtSnippets : public PlainToRich { public: virtual string startMatch(unsigned int) { - return string(""); + return string(""); } virtual string endMatch() { return string(""); @@ -82,12 +81,10 @@ void SnippetsW::init() QPushButton *searchButton = new QPushButton(tr("Search")); searchButton->setAutoDefault(false); buttonBox->addButton(searchButton, QDialogButtonBox::ActionRole); -// setWindowFlags(Qt::WindowStaysOnTopHint); searchFM->hide(); onNewShortcuts(); - connect(&SCBase::scBase(), SIGNAL(shortcutsChanged()), - this, SLOT(onNewShortcuts())); + connect(&SCBase::scBase(), SIGNAL(shortcutsChanged()), this, SLOT(onNewShortcuts())); QPushButton *closeButton = buttonBox->button(QDialogButtonBox::Close); if (closeButton) @@ -105,11 +102,9 @@ void SnippetsW::init() browserw = new QWebView(this); verticalLayout->insertWidget(0, browserw); browser->setUrl(QUrl(QString::fromUtf8("about:blank"))); - connect(browser, SIGNAL(linkClicked(const QUrl &)), - this, SLOT(onLinkClicked(const QUrl &))); + connect(browser, SIGNAL(linkClicked(const QUrl &)), this, SLOT(onLinkClicked(const QUrl &))); browser->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); - browser->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal, - Qt::ScrollBarAlwaysOff); + browser->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); QWEBSETTINGS *ws = browser->page()->settings(); if (prefs.reslistfontfamily != "") { ws->setFontFamily(QWEBSETTINGS::StandardFont, prefs.reslistfontfamily); @@ -136,8 +131,7 @@ void SnippetsW::init() #else browserw = new QTextBrowser(this); verticalLayout->insertWidget(0, browserw); - connect(browser, SIGNAL(anchorClicked(const QUrl &)), - this, SLOT(onLinkClicked(const QUrl &))); + connect(browser, SIGNAL(anchorClicked(const QUrl &)), this, SLOT(onLinkClicked(const QUrl &))); browser->setReadOnly(true); browser->setUndoRedoEnabled(false); browser->setOpenLinks(false); @@ -183,8 +177,7 @@ void SnippetsW::createPopupMenu(const QPoint& pos) { QMenu *popup = new QMenu(this); if (m_sortingByPage) { - popup->addAction(tr("Sort By Relevance"), this, - SLOT(reloadByRelevance())); + popup->addAction(tr("Sort By Relevance"), this, SLOT(reloadByRelevance())); } else { popup->addAction(tr("Sort By Page"), this, SLOT(reloadByPage())); } @@ -230,29 +223,22 @@ void SnippetsW::onSetDoc(Rcl::Doc doc, std::shared_ptr source) source->getTerms(hdata); ostringstream oss; - oss << - "" - ""; + oss << "" + ""; oss << "\n"; oss << qs2utf8s(prefs.darkreslistheadertext) << qs2utf8s(prefs.reslistheadertext); - oss << - "" - "" - "" - ; + oss << "
"; g_hiliter.set_inputhtml(false); bool nomatch = true; for (const auto& snippet : vpabs) { if (snippet.page == -1) { - oss << "" << endl; + oss << "" << "\n"; continue; } list lr; @@ -263,13 +249,12 @@ void SnippetsW::onSetDoc(Rcl::Doc doc, std::shared_ptr source) nomatch = false; oss << "" << endl; + oss << "" << "\n"; } - oss << "
" << - snippet.snippet << "
" << snippet.snippet << "
"; if (snippet.page > 0) { - oss << "" - << "P. " << snippet.page << ""; + oss << "" << + "P. " << snippet.page << ""; } - oss << "" << lr.front().c_str() << "
" << lr.front().c_str() << "
" << endl; + oss << "" << "\n"; if (nomatch) { oss.str("\n"); oss << qs2utf8s(tr("

Sorry, no exact match was found within limits. " @@ -278,12 +263,12 @@ void SnippetsW::onSetDoc(Rcl::Doc doc, std::shared_ptr source) } oss << "\n"; #if defined(USING_WEBKIT) || defined(USING_WEBENGINE) - browser->setHtml(QString::fromUtf8(oss.str().c_str())); + browser->setHtml(u8s2qs(oss.str())); #else browser->clear(); browser->append("."); browser->clear(); - browser->insertHtml(QString::fromUtf8(oss.str().c_str())); + browser->insertHtml(u8s2qs(oss.str())); browser->moveCursor (QTextCursor::Start); browser->ensureCursorVisible(); #endif @@ -354,8 +339,7 @@ void SnippetsW::onLinkClicked(const QUrl &url) string term; if (termpos != string::npos) term = ascurl.substr(termpos+1); - emit startNativeViewer(m_doc, page, - QString::fromUtf8(term.c_str())); + emit startNativeViewer(m_doc, page, u8s2qs(term)); return; } } diff --git a/src/query/plaintorich.h b/src/query/plaintorich.h index 9118ea5a..b86f649b 100644 --- a/src/query/plaintorich.h +++ b/src/query/plaintorich.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2004 J.F.Dockes +/* Copyright (C) 2004-2021 J.F.Dockes * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -60,8 +60,7 @@ public: * @param in raw text out of internfile. * @param out rich text output, divided in chunks (to help our caller * avoid inserting half tags into textedit which doesnt like it) - * @param in hdata terms and groups to be highlighted. These are - * lowercase and unaccented. + * @param in hdata terms and groups to be highlighted. See utils/hldata.h * @param chunksize max size of chunks in output list */ virtual bool plaintorich(const std::string &in, std::list &out, diff --git a/src/rcldb/rclabstract.cpp b/src/rcldb/rclabstract.cpp index 311ef760..04811a11 100644 --- a/src/rcldb/rclabstract.cpp +++ b/src/rcldb/rclabstract.cpp @@ -254,7 +254,7 @@ double Query::Native::qualityTerms(Xapian::docid docid, } -// Return page number for first match of "significant" term. +// Choose most interesting term and return the page number for its first match int Query::Native::getFirstMatchPage(Xapian::docid docid, string& term) { LOGDEB("Query::Native::getFirstMatchPage\n"); @@ -286,9 +286,7 @@ int Query::Native::getFirstMatchPage(Xapian::docid docid, string& term) qualityTerms(docid, terms, byQ); for (auto mit = byQ.rbegin(); mit != byQ.rend(); mit++) { - for (vector::const_iterator qit = mit->second.begin(); - qit != mit->second.end(); qit++) { - string qterm = *qit; + for (const auto& qterm : mit->second) { Xapian::PositionIterator pos; string emptys; try { @@ -619,9 +617,8 @@ int Query::Native::abstractFromIndex( // possibly retried by our caller. // // @param[out] vabs the abstract is returned as a vector of snippets. -int Query::Native::makeAbstract(Xapian::docid docid, - vector& vabs, - int imaxoccs, int ictxwords, bool sortbypage) +int Query::Native::makeAbstract( + Xapian::docid docid, vector& vabs, int imaxoccs, int ictxwords, bool sortbypage) { chron.restart(); LOGDEB("makeAbstract: docid " << docid << " imaxoccs " << diff --git a/src/rcldb/rcldb.cpp b/src/rcldb/rcldb.cpp index 557affcb..ceaec4e3 100644 --- a/src/rcldb/rcldb.cpp +++ b/src/rcldb/rcldb.cpp @@ -96,10 +96,13 @@ const string pathelt_prefix = "XP"; static const string udi_prefix("Q"); static const string parent_prefix("F"); -// Special terms to mark begin/end of field (for anchored searches), and -// page breaks +// Special terms to mark begin/end of field (for anchored searches). string start_of_field_term; string end_of_field_term; + +// Special term for page breaks. Note that we use a complicated mechanism for multiple page +// breaks at the same position, when it would have been probably simpler to use XXPG/n terms +// instead (did not try to implement though). A change would force users to reindex. const string page_break_term = "XXPG/"; // Special term to mark documents with children. @@ -1846,16 +1849,14 @@ bool Db::addOrUpdate(const string &udi, const string &parent_udi, Doc &doc) } } - // If empty pages (multiple break at same pos) were recorded, save - // them (this is because we have no way to record them in the - // Xapian list + // If empty pages (multiple break at same pos) were recorded, save them (this is + // because we have no way to record them in the Xapian list) if (!tpidx.m_pageincrvec.empty()) { ostringstream multibreaks; for (unsigned int i = 0; i < tpidx.m_pageincrvec.size(); i++) { if (i != 0) multibreaks << ","; - multibreaks << tpidx.m_pageincrvec[i].first << "," << - tpidx.m_pageincrvec[i].second; + multibreaks << tpidx.m_pageincrvec[i].first << "," << tpidx.m_pageincrvec[i].second; } RECORD_APPEND(record, string(cstr_mbreaks), multibreaks.str()); } diff --git a/src/rcldb/rclquery.cpp b/src/rcldb/rclquery.cpp index 19b88f79..19b50c87 100644 --- a/src/rcldb/rclquery.cpp +++ b/src/rcldb/rclquery.cpp @@ -360,7 +360,6 @@ int Query::getFirstMatchPage(const Doc &doc, string& term) return m_reason.empty() ? pagenum : -1; } - // Mset size // Note: times for retrieving (multiple times)all docs from a sample // 25k docs db (q: mime:*) @@ -511,8 +510,7 @@ vector Query::expand(const Doc &doc) Xapian::ESet eset = m_nq->xenquire->get_eset(20, rset, false); LOGDEB("ESet terms:\n"); // We filter out the special terms - for (Xapian::ESetIterator it = eset.begin(); - it != eset.end(); it++) { + for (Xapian::ESetIterator it = eset.begin(); it != eset.end(); it++) { LOGDEB(" [" << (*it) << "]\n"); if ((*it).empty() || has_prefix(*it)) continue;