comments and justification

This commit is contained in:
Jean-Francois Dockes 2022-01-07 10:44:40 +01:00
parent 8c122d7de8
commit 25d6d78902
6 changed files with 34 additions and 56 deletions

View File

@ -140,8 +140,7 @@ public slots:
virtual void showActionsSearch(); virtual void showActionsSearch();
virtual void startPreview(int docnum, Rcl::Doc doc, int keymods); virtual void startPreview(int docnum, Rcl::Doc doc, int keymods);
virtual void startPreview(Rcl::Doc); virtual void startPreview(Rcl::Doc);
virtual void startNativeViewer(Rcl::Doc, int pagenum = -1, virtual void startNativeViewer(Rcl::Doc, int pagenum = -1, QString term = QString());
QString term = QString());
virtual void openWith(Rcl::Doc, string); virtual void openWith(Rcl::Doc, string);
virtual void saveDocToFile(Rcl::Doc); virtual void saveDocToFile(Rcl::Doc);
virtual void previewNextInTab(Preview *, int sid, int docnum); virtual void previewNextInTab(Preview *, int sid, int docnum);

View File

@ -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 * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
@ -67,8 +67,7 @@ using namespace std;
class PlainToRichQtSnippets : public PlainToRich { class PlainToRichQtSnippets : public PlainToRich {
public: public:
virtual string startMatch(unsigned int) { virtual string startMatch(unsigned int) {
return string("<span class='rclmatch' style='") return string("<span class='rclmatch' style='") + qs2utf8s(prefs.qtermstyle) + string("'>");
+ qs2utf8s(prefs.qtermstyle) + string("'>");
} }
virtual string endMatch() { virtual string endMatch() {
return string("</span>"); return string("</span>");
@ -82,12 +81,10 @@ void SnippetsW::init()
QPushButton *searchButton = new QPushButton(tr("Search")); QPushButton *searchButton = new QPushButton(tr("Search"));
searchButton->setAutoDefault(false); searchButton->setAutoDefault(false);
buttonBox->addButton(searchButton, QDialogButtonBox::ActionRole); buttonBox->addButton(searchButton, QDialogButtonBox::ActionRole);
// setWindowFlags(Qt::WindowStaysOnTopHint);
searchFM->hide(); searchFM->hide();
onNewShortcuts(); onNewShortcuts();
connect(&SCBase::scBase(), SIGNAL(shortcutsChanged()), connect(&SCBase::scBase(), SIGNAL(shortcutsChanged()), this, SLOT(onNewShortcuts()));
this, SLOT(onNewShortcuts()));
QPushButton *closeButton = buttonBox->button(QDialogButtonBox::Close); QPushButton *closeButton = buttonBox->button(QDialogButtonBox::Close);
if (closeButton) if (closeButton)
@ -105,11 +102,9 @@ void SnippetsW::init()
browserw = new QWebView(this); browserw = new QWebView(this);
verticalLayout->insertWidget(0, browserw); verticalLayout->insertWidget(0, browserw);
browser->setUrl(QUrl(QString::fromUtf8("about:blank"))); browser->setUrl(QUrl(QString::fromUtf8("about:blank")));
connect(browser, SIGNAL(linkClicked(const QUrl &)), connect(browser, SIGNAL(linkClicked(const QUrl &)), this, SLOT(onLinkClicked(const QUrl &)));
this, SLOT(onLinkClicked(const QUrl &)));
browser->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); browser->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
browser->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal, browser->page()->currentFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
Qt::ScrollBarAlwaysOff);
QWEBSETTINGS *ws = browser->page()->settings(); QWEBSETTINGS *ws = browser->page()->settings();
if (prefs.reslistfontfamily != "") { if (prefs.reslistfontfamily != "") {
ws->setFontFamily(QWEBSETTINGS::StandardFont, prefs.reslistfontfamily); ws->setFontFamily(QWEBSETTINGS::StandardFont, prefs.reslistfontfamily);
@ -136,8 +131,7 @@ void SnippetsW::init()
#else #else
browserw = new QTextBrowser(this); browserw = new QTextBrowser(this);
verticalLayout->insertWidget(0, browserw); verticalLayout->insertWidget(0, browserw);
connect(browser, SIGNAL(anchorClicked(const QUrl &)), connect(browser, SIGNAL(anchorClicked(const QUrl &)), this, SLOT(onLinkClicked(const QUrl &)));
this, SLOT(onLinkClicked(const QUrl &)));
browser->setReadOnly(true); browser->setReadOnly(true);
browser->setUndoRedoEnabled(false); browser->setUndoRedoEnabled(false);
browser->setOpenLinks(false); browser->setOpenLinks(false);
@ -183,8 +177,7 @@ void SnippetsW::createPopupMenu(const QPoint& pos)
{ {
QMenu *popup = new QMenu(this); QMenu *popup = new QMenu(this);
if (m_sortingByPage) { if (m_sortingByPage) {
popup->addAction(tr("Sort By Relevance"), this, popup->addAction(tr("Sort By Relevance"), this, SLOT(reloadByRelevance()));
SLOT(reloadByRelevance()));
} else { } else {
popup->addAction(tr("Sort By Page"), this, SLOT(reloadByPage())); popup->addAction(tr("Sort By Page"), this, SLOT(reloadByPage()));
} }
@ -230,29 +223,22 @@ void SnippetsW::onSetDoc(Rcl::Doc doc, std::shared_ptr<DocSequence> source)
source->getTerms(hdata); source->getTerms(hdata);
ostringstream oss; ostringstream oss;
oss << oss << "<html><head>"
"<html><head>" "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">";
"<meta http-equiv=\"content-type\" "
"content=\"text/html; charset=utf-8\">";
oss << "<style type=\"text/css\">\nbody,table,select,input {\n"; oss << "<style type=\"text/css\">\nbody,table,select,input {\n";
oss << "color: " + qs2utf8s(prefs.fontcolor) + ";\n"; oss << "color: " + qs2utf8s(prefs.fontcolor) + ";\n";
oss << "}\n</style>\n"; oss << "}\n</style>\n";
oss << qs2utf8s(prefs.darkreslistheadertext) << qs2utf8s(prefs.reslistheadertext); oss << qs2utf8s(prefs.darkreslistheadertext) << qs2utf8s(prefs.reslistheadertext);
oss << oss << "</head><body><table class=\"snippets\">";
"</head>"
"<body>"
"<table class=\"snippets\">"
;
g_hiliter.set_inputhtml(false); g_hiliter.set_inputhtml(false);
bool nomatch = true; bool nomatch = true;
for (const auto& snippet : vpabs) { for (const auto& snippet : vpabs) {
if (snippet.page == -1) { if (snippet.page == -1) {
oss << "<tr><td colspan=\"2\">" << oss << "<tr><td colspan=\"2\">" << snippet.snippet << "</td></tr>" << "\n";
snippet.snippet << "</td></tr>" << endl;
continue; continue;
} }
list<string> lr; list<string> lr;
@ -263,13 +249,12 @@ void SnippetsW::onSetDoc(Rcl::Doc doc, std::shared_ptr<DocSequence> source)
nomatch = false; nomatch = false;
oss << "<tr><td>"; oss << "<tr><td>";
if (snippet.page > 0) { if (snippet.page > 0) {
oss << "<a href=\"http://h/P" << snippet.page << "T" << oss << "<a href=\"http://h/P" << snippet.page << "T" << snippet.term << "\">" <<
snippet.term << "\">" "P.&nbsp;" << snippet.page << "</a>";
<< "P.&nbsp;" << snippet.page << "</a>";
} }
oss << "</td><td>" << lr.front().c_str() << "</td></tr>" << endl; oss << "</td><td>" << lr.front().c_str() << "</td></tr>" << "\n";
} }
oss << "</table>" << endl; oss << "</table>" << "\n";
if (nomatch) { if (nomatch) {
oss.str("<html><head></head><body>\n"); oss.str("<html><head></head><body>\n");
oss << qs2utf8s(tr("<p>Sorry, no exact match was found within limits. " oss << qs2utf8s(tr("<p>Sorry, no exact match was found within limits. "
@ -278,12 +263,12 @@ void SnippetsW::onSetDoc(Rcl::Doc doc, std::shared_ptr<DocSequence> source)
} }
oss << "\n</body></html>"; oss << "\n</body></html>";
#if defined(USING_WEBKIT) || defined(USING_WEBENGINE) #if defined(USING_WEBKIT) || defined(USING_WEBENGINE)
browser->setHtml(QString::fromUtf8(oss.str().c_str())); browser->setHtml(u8s2qs(oss.str()));
#else #else
browser->clear(); browser->clear();
browser->append("."); browser->append(".");
browser->clear(); browser->clear();
browser->insertHtml(QString::fromUtf8(oss.str().c_str())); browser->insertHtml(u8s2qs(oss.str()));
browser->moveCursor (QTextCursor::Start); browser->moveCursor (QTextCursor::Start);
browser->ensureCursorVisible(); browser->ensureCursorVisible();
#endif #endif
@ -354,8 +339,7 @@ void SnippetsW::onLinkClicked(const QUrl &url)
string term; string term;
if (termpos != string::npos) if (termpos != string::npos)
term = ascurl.substr(termpos+1); term = ascurl.substr(termpos+1);
emit startNativeViewer(m_doc, page, emit startNativeViewer(m_doc, page, u8s2qs(term));
QString::fromUtf8(term.c_str()));
return; return;
} }
} }

View File

@ -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 * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
@ -60,8 +60,7 @@ public:
* @param in raw text out of internfile. * @param in raw text out of internfile.
* @param out rich text output, divided in chunks (to help our caller * @param out rich text output, divided in chunks (to help our caller
* avoid inserting half tags into textedit which doesnt like it) * avoid inserting half tags into textedit which doesnt like it)
* @param in hdata terms and groups to be highlighted. These are * @param in hdata terms and groups to be highlighted. See utils/hldata.h
* lowercase and unaccented.
* @param chunksize max size of chunks in output list * @param chunksize max size of chunks in output list
*/ */
virtual bool plaintorich(const std::string &in, std::list<std::string> &out, virtual bool plaintorich(const std::string &in, std::list<std::string> &out,

View File

@ -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) int Query::Native::getFirstMatchPage(Xapian::docid docid, string& term)
{ {
LOGDEB("Query::Native::getFirstMatchPage\n"); LOGDEB("Query::Native::getFirstMatchPage\n");
@ -286,9 +286,7 @@ int Query::Native::getFirstMatchPage(Xapian::docid docid, string& term)
qualityTerms(docid, terms, byQ); qualityTerms(docid, terms, byQ);
for (auto mit = byQ.rbegin(); mit != byQ.rend(); mit++) { for (auto mit = byQ.rbegin(); mit != byQ.rend(); mit++) {
for (vector<string>::const_iterator qit = mit->second.begin(); for (const auto& qterm : mit->second) {
qit != mit->second.end(); qit++) {
string qterm = *qit;
Xapian::PositionIterator pos; Xapian::PositionIterator pos;
string emptys; string emptys;
try { try {
@ -619,9 +617,8 @@ int Query::Native::abstractFromIndex(
// possibly retried by our caller. // possibly retried by our caller.
// //
// @param[out] vabs the abstract is returned as a vector of snippets. // @param[out] vabs the abstract is returned as a vector of snippets.
int Query::Native::makeAbstract(Xapian::docid docid, int Query::Native::makeAbstract(
vector<Snippet>& vabs, Xapian::docid docid, vector<Snippet>& vabs, int imaxoccs, int ictxwords, bool sortbypage)
int imaxoccs, int ictxwords, bool sortbypage)
{ {
chron.restart(); chron.restart();
LOGDEB("makeAbstract: docid " << docid << " imaxoccs " << LOGDEB("makeAbstract: docid " << docid << " imaxoccs " <<

View File

@ -96,10 +96,13 @@ const string pathelt_prefix = "XP";
static const string udi_prefix("Q"); static const string udi_prefix("Q");
static const string parent_prefix("F"); static const string parent_prefix("F");
// Special terms to mark begin/end of field (for anchored searches), and // Special terms to mark begin/end of field (for anchored searches).
// page breaks
string start_of_field_term; string start_of_field_term;
string end_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/"; const string page_break_term = "XXPG/";
// Special term to mark documents with children. // 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 // If empty pages (multiple break at same pos) were recorded, save them (this is
// them (this is because we have no way to record them in the // because we have no way to record them in the Xapian list)
// Xapian list
if (!tpidx.m_pageincrvec.empty()) { if (!tpidx.m_pageincrvec.empty()) {
ostringstream multibreaks; ostringstream multibreaks;
for (unsigned int i = 0; i < tpidx.m_pageincrvec.size(); i++) { for (unsigned int i = 0; i < tpidx.m_pageincrvec.size(); i++) {
if (i != 0) if (i != 0)
multibreaks << ","; multibreaks << ",";
multibreaks << tpidx.m_pageincrvec[i].first << "," << multibreaks << tpidx.m_pageincrvec[i].first << "," << tpidx.m_pageincrvec[i].second;
tpidx.m_pageincrvec[i].second;
} }
RECORD_APPEND(record, string(cstr_mbreaks), multibreaks.str()); RECORD_APPEND(record, string(cstr_mbreaks), multibreaks.str());
} }

View File

@ -360,7 +360,6 @@ int Query::getFirstMatchPage(const Doc &doc, string& term)
return m_reason.empty() ? pagenum : -1; return m_reason.empty() ? pagenum : -1;
} }
// Mset size // Mset size
// Note: times for retrieving (multiple times)all docs from a sample // Note: times for retrieving (multiple times)all docs from a sample
// 25k docs db (q: mime:*) // 25k docs db (q: mime:*)
@ -511,8 +510,7 @@ vector<string> Query::expand(const Doc &doc)
Xapian::ESet eset = m_nq->xenquire->get_eset(20, rset, false); Xapian::ESet eset = m_nq->xenquire->get_eset(20, rset, false);
LOGDEB("ESet terms:\n"); LOGDEB("ESet terms:\n");
// We filter out the special terms // We filter out the special terms
for (Xapian::ESetIterator it = eset.begin(); for (Xapian::ESetIterator it = eset.begin(); it != eset.end(); it++) {
it != eset.end(); it++) {
LOGDEB(" [" << (*it) << "]\n"); LOGDEB(" [" << (*it) << "]\n");
if ((*it).empty() || has_prefix(*it)) if ((*it).empty() || has_prefix(*it))
continue; continue;