rclabstract: fixed log call formats and indentation

This commit is contained in:
Jean-Francois Dockes 2017-12-07 10:51:10 +01:00
parent 653b1fb5a5
commit 207e3d5af7

View File

@ -50,7 +50,7 @@ static void listList(const string& what, const vector<string>&l)
for (vector<string>::const_iterator it = l.begin(); it != l.end(); it++) { for (vector<string>::const_iterator it = l.begin(); it != l.end(); it++) {
a = a + *it + " "; a = a + *it + " ";
} }
LOGDEB("" << (what) << ": " << (a) << "\n" ); LOGDEB("" << what << ": " << a << "\n");
} }
#else #else
#define LOGABS LOGDEB2 #define LOGABS LOGDEB2
@ -82,7 +82,7 @@ static void noPrefixList(const vector<string>& in, vector<string>& out)
bool Query::Native::getMatchTerms(unsigned long xdocid, vector<string>& terms) bool Query::Native::getMatchTerms(unsigned long xdocid, vector<string>& terms)
{ {
if (!xenquire) { if (!xenquire) {
LOGERR("Query::getMatchTerms: no query opened\n" ); LOGERR("Query::getMatchTerms: no query opened\n");
return false; return false;
} }
@ -95,7 +95,7 @@ bool Query::Native::getMatchTerms(unsigned long xdocid, vector<string>& terms)
xenquire->get_matching_terms_end(id)), xenquire->get_matching_terms_end(id)),
m_q->m_db->m_ndb->xrdb, m_q->m_reason); m_q->m_db->m_ndb->xrdb, m_q->m_reason);
if (!m_q->m_reason.empty()) { if (!m_q->m_reason.empty()) {
LOGERR("getMatchTerms: xapian error: " << (m_q->m_reason) << "\n" ); LOGERR("getMatchTerms: xapian error: " << m_q->m_reason << "\n");
return false; return false;
} }
noPrefixList(iterms, terms); noPrefixList(iterms, terms);
@ -127,7 +127,8 @@ void Query::Native::setDbWideQTermsFreqs()
for (vector<string>::const_iterator qit = qterms.begin(); for (vector<string>::const_iterator qit = qterms.begin();
qit != qterms.end(); qit++) { qit != qterms.end(); qit++) {
termfreqs[*qit] = xrdb.get_termfreq(*qit) / doccnt; termfreqs[*qit] = xrdb.get_termfreq(*qit) / doccnt;
LOGABS("setDbWideQTermFreqs: [" << (qit) << "] db freq " << (termfreqs[*qit]) << "\n" ); LOGABS("setDbWideQTermFreqs: [" << *qit << "] db freq " <<
termfreqs[*qit] << "\n");
} }
} }
@ -146,7 +147,7 @@ double Query::Native::qualityTerms(Xapian::docid docid,
const vector<string>& terms, const vector<string>& terms,
multimap<double, vector<string> >& byQ) multimap<double, vector<string> >& byQ)
{ {
LOGABS("qualityTerms\n" ); LOGABS("qualityTerms\n");
setDbWideQTermsFreqs(); setDbWideQTermsFreqs();
map<string, double> termQcoefs; map<string, double> termQcoefs;
@ -165,7 +166,7 @@ double Query::Native::qualityTerms(Xapian::docid docid,
{ {
string deb; string deb;
hld.toString(deb); hld.toString(deb);
LOGABS("qualityTerms: hld: " << (deb) << "\n" ); LOGABS("qualityTerms: hld: " << deb << "\n");
} }
#endif #endif
@ -177,7 +178,7 @@ double Query::Native::qualityTerms(Xapian::docid docid,
if (eit != hld.terms.end()) { if (eit != hld.terms.end()) {
byRoot[eit->second].push_back(*qit); byRoot[eit->second].push_back(*qit);
} else { } else {
LOGDEB0("qualityTerms: [" << ((*qit)) << "] not found in hld\n" ); LOGDEB0("qualityTerms: [" << *qit << "] not found in hld\n");
byRoot[*qit].push_back(*qit); byRoot[*qit].push_back(*qit);
} }
} }
@ -194,7 +195,7 @@ double Query::Native::qualityTerms(Xapian::docid docid,
} }
byRootstr.append("\n"); byRootstr.append("\n");
} }
LOGABS("\nqualityTerms: uterms to terms: " << (byRootstr) << "\n" ); LOGABS("\nqualityTerms: uterms to terms: " << byRootstr << "\n");
} }
#endif #endif
@ -242,10 +243,10 @@ double Query::Native::qualityTerms(Xapian::docid docid,
#ifdef DEBUGABSTRACT #ifdef DEBUGABSTRACT
for (multimap<double, vector<string> >::reverse_iterator mit= byQ.rbegin(); for (multimap<double, vector<string> >::reverse_iterator mit= byQ.rbegin();
mit != byQ.rend(); mit++) { mit != byQ.rend(); mit++) {
LOGABS("qualityTerms: group\n" ); LOGABS("qualityTerms: group\n");
for (vector<string>::const_iterator qit = mit->second.begin(); for (vector<string>::const_iterator qit = mit->second.begin();
qit != mit->second.end(); qit++) { qit != mit->second.end(); qit++) {
LOGABS("" << (mit->first) << "->[" << (qit) << "]\n" ); LOGABS("" << mit->first << "->[" << *qit << "]\n");
} }
} }
#endif #endif
@ -257,7 +258,7 @@ int Query::Native::getFirstMatchPage(Xapian::docid docid, string& term)
{ {
LOGDEB("Query::Native::getFirstMatchPage\n"); LOGDEB("Query::Native::getFirstMatchPage\n");
if (!m_q|| !m_q->m_db || !m_q->m_db->m_ndb || !m_q->m_db->m_ndb->m_isopen) { if (!m_q|| !m_q->m_db || !m_q->m_db->m_ndb || !m_q->m_db->m_ndb->m_isopen) {
LOGERR("Query::getFirstMatchPage: no db\n" ); LOGERR("Query::getFirstMatchPage: no db\n");
return -1; return -1;
} }
Rcl::Db::Native *ndb(m_q->m_db->m_ndb); Rcl::Db::Native *ndb(m_q->m_db->m_ndb);
@ -267,7 +268,7 @@ int Query::Native::getFirstMatchPage(Xapian::docid docid, string& term)
getMatchTerms(docid, terms); getMatchTerms(docid, terms);
if (terms.empty()) { if (terms.empty()) {
LOGDEB("getFirstMatchPage: empty match term list (field match?)\n" ); LOGDEB("getFirstMatchPage: empty match term list (field match?)\n");
return -1; return -1;
} }
@ -316,13 +317,14 @@ int Query::Native::makeAbstract(Xapian::docid docid,
int imaxoccs, int ictxwords) int imaxoccs, int ictxwords)
{ {
Chrono chron; Chrono chron;
LOGABS("makeAbstract: docid " << (long(docid)) << " imaxoccs " << (imaxoccs) << " ictxwords " << (ictxwords) << "\n" ); LOGABS("makeAbstract: docid " << docid << " imaxoccs " <<
imaxoccs << " ictxwords " << ictxwords << "\n");
// The (unprefixed) terms matched by this document // The (unprefixed) terms matched by this document
vector<string> matchedTerms; vector<string> matchedTerms;
getMatchTerms(docid, matchedTerms); getMatchTerms(docid, matchedTerms);
if (matchedTerms.empty()) { if (matchedTerms.empty()) {
LOGDEB("makeAbstract::Empty term list\n" ); LOGDEB("makeAbstract:"<<chron.millis()<<"mS:Empty term list\n");
return ABSRES_ERROR; return ABSRES_ERROR;
} }
@ -339,10 +341,10 @@ int Query::Native::makeAbstract(Xapian::docid docid,
// aggregated by the qualityTerms() routine. // aggregated by the qualityTerms() routine.
multimap<double, vector<string> > byQ; multimap<double, vector<string> > byQ;
double totalweight = qualityTerms(docid, matchedTerms, byQ); double totalweight = qualityTerms(docid, matchedTerms, byQ);
LOGABS("makeAbstract:" << (chron.ms()) << ": computed Qcoefs.\n" ); LOGABS("makeAbstract:" << chron.millis() << "mS: computed Qcoefs.\n");
// This can't happen, but would crash us // This can't happen, but would crash us
if (totalweight == 0.0) { if (totalweight == 0.0) {
LOGERR("makeAbstract: totalweight == 0.0 !\n" ); LOGERR("makeAbstract:"<<chron.millis()<<"mS: totalweight == 0.0 !\n");
return ABSRES_ERROR; return ABSRES_ERROR;
} }
@ -376,7 +378,8 @@ int Query::Native::makeAbstract(Xapian::docid docid,
const unsigned int maxtotaloccs = imaxoccs > 0 ? imaxoccs : const unsigned int maxtotaloccs = imaxoccs > 0 ? imaxoccs :
m_q->m_db->getAbsLen() /(7 * (m_q->m_db->getAbsCtxLen() + 1)); m_q->m_db->getAbsLen() /(7 * (m_q->m_db->getAbsCtxLen() + 1));
int ctxwords = ictxwords == -1 ? m_q->m_db->getAbsCtxLen() : ictxwords; int ctxwords = ictxwords == -1 ? m_q->m_db->getAbsCtxLen() : ictxwords;
LOGABS("makeAbstract:" << (chron.ms()) << ": mxttloccs " << (maxtotaloccs) << " ctxwords " << (ctxwords) << "\n" ); LOGABS("makeAbstract:" << chron.millis() << "mS: mxttloccs " <<
maxtotaloccs << " ctxwords " << ctxwords << "\n");
int ret = ABSRES_OK; int ret = ABSRES_OK;
@ -404,7 +407,8 @@ int Query::Native::makeAbstract(Xapian::docid docid,
string qterm = *qit; string qterm = *qit;
LOGABS("makeAbstract: [" << (qterm) << "] " << (maxgrpoccs) << " max grp occs (coef " << (q) << ")\n" ); LOGABS("makeAbstract: [" << qterm << "] " << maxgrpoccs <<
" max grp occs (coef " << q << ")\n");
// The match term may span several words // The match term may span several words
int qtrmwrdcnt = int qtrmwrdcnt =
@ -423,7 +427,9 @@ int Query::Native::makeAbstract(Xapian::docid docid,
int ipos = *pos; int ipos = *pos;
if (ipos < int(baseTextPosition)) // Not in text body if (ipos < int(baseTextPosition)) // Not in text body
continue; continue;
LOGABS("makeAbstract: [" << (qterm) << "] at pos " << (ipos) << " grpoccs " << (grpoccs) << " maxgrpoccs " << (maxgrpoccs) << "\n" ); LOGABS("makeAbstract: [" << qterm << "] at pos " <<
ipos << " grpoccs " << grpoccs << " maxgrpoccs " <<
maxgrpoccs << "\n");
totaloccs++; totaloccs++;
grpoccs++; grpoccs++;
@ -463,13 +469,13 @@ int Query::Native::makeAbstract(Xapian::docid docid,
// Group done ? // Group done ?
if (grpoccs >= maxgrpoccs) { if (grpoccs >= maxgrpoccs) {
ret |= ABSRES_TRUNC; ret |= ABSRES_TRUNC;
LOGABS("Db::makeAbstract: max group occs cutoff\n" ); LOGABS("Db::makeAbstract: max group occs cutoff\n");
break; break;
} }
// Global done ? // Global done ?
if (totaloccs >= maxtotaloccs) { if (totaloccs >= maxtotaloccs) {
ret |= ABSRES_TRUNC; ret |= ABSRES_TRUNC;
LOGABS("Db::makeAbstract: max occurrences cutoff\n" ); LOGABS("Db::makeAbstract: max occurrences cutoff\n");
break; break;
} }
} }
@ -479,18 +485,19 @@ int Query::Native::makeAbstract(Xapian::docid docid,
if (totaloccs >= maxtotaloccs) { if (totaloccs >= maxtotaloccs) {
ret |= ABSRES_TRUNC; ret |= ABSRES_TRUNC;
LOGABS("Db::makeAbstract: max1 occurrences cutoff\n" ); LOGABS("Db::makeAbstract: max1 occurrences cutoff\n");
break; break;
} }
} }
} }
maxpos += ctxwords + 1; maxpos += ctxwords + 1;
LOGABS("makeAbstract:" << (chron.millis()) << ":chosen number of positions " << (totaloccs) << "\n" ); LOGABS("makeAbstract:" << chron.millis() <<
"mS:chosen number of positions " << totaloccs << "\n");
// This can happen if there are term occurences in the keywords // This can happen if there are term occurences in the keywords
// etc. but not elsewhere ? // etc. but not elsewhere ?
if (totaloccs == 0) { if (totaloccs == 0) {
LOGDEB("makeAbstract: no occurrences\n" ); LOGDEB("makeAbstract: no occurrences\n");
return ABSRES_OK; return ABSRES_OK;
} }
@ -509,7 +516,8 @@ int Query::Native::makeAbstract(Xapian::docid docid,
continue; continue;
if (m_q->m_snipMaxPosWalk > 0 && cutoff-- < 0) { if (m_q->m_snipMaxPosWalk > 0 && cutoff-- < 0) {
ret |= ABSRES_TERMMISS; ret |= ABSRES_TERMMISS;
LOGDEB0("makeAbstract: max term count cutoff " << (m_q->m_snipMaxPosWalk) << "\n" ); LOGDEB0("makeAbstract: max term count cutoff " <<
m_q->m_snipMaxPosWalk << "\n");
break; break;
} }
@ -519,7 +527,8 @@ int Query::Native::makeAbstract(Xapian::docid docid,
pos != xrdb.positionlist_end(docid, *term); pos++) { pos != xrdb.positionlist_end(docid, *term); pos++) {
if (m_q->m_snipMaxPosWalk > 0 && cutoff-- < 0) { if (m_q->m_snipMaxPosWalk > 0 && cutoff-- < 0) {
ret |= ABSRES_TERMMISS; ret |= ABSRES_TERMMISS;
LOGDEB0("makeAbstract: max term count cutoff " << (m_q->m_snipMaxPosWalk) << "\n" ); LOGDEB0("makeAbstract: max term count cutoff " <<
m_q->m_snipMaxPosWalk << "\n");
break; break;
} }
// If we are beyond the max possible position, stop // If we are beyond the max possible position, stop
@ -533,13 +542,15 @@ int Query::Native::makeAbstract(Xapian::docid docid,
// at the same position, we want to keep only the // at the same position, we want to keep only the
// first one (ie: dockes and dockes@wanadoo.fr) // first one (ie: dockes and dockes@wanadoo.fr)
if (vit->second.empty()) { if (vit->second.empty()) {
LOGDEB2("makeAbstract: populating: [" << ((*term)) << "] at " << (*pos) << "\n" ); LOGDEB2("makeAbstract: populating: [" << *term <<
"] at " << *pos << "\n");
sparseDoc[*pos] = *term; sparseDoc[*pos] = *term;
} }
} }
} }
} }
} }
LOGABS("makeAbstract:" << chron.millis() << "mS: all term poslist read\n");
#if 0 #if 0
// Debug only: output the full term[position] vector // Debug only: output the full term[position] vector
@ -550,11 +561,11 @@ int Query::Native::makeAbstract(Xapian::docid docid,
it++, ipos++) { it++, ipos++) {
if (it->empty()) { if (it->empty()) {
if (!epty) if (!epty)
LOGDEB("makeAbstract:vec[" << (ipos) << "]: [" << (it) << "]\n" ); LOGDEB("makeAbstract:vec[" << ipos << "]: [" << it << "]\n");
epty=true; epty=true;
} else { } else {
epty = false; epty = false;
LOGDEB("makeAbstract:vec[" << (ipos) << "]: [" << (it) << "]\n" ); LOGDEB("makeAbstract:vec[" << ipos << "]: [" << it << "]\n");
} }
} }
#endif #endif
@ -562,7 +573,8 @@ int Query::Native::makeAbstract(Xapian::docid docid,
vector<int> vpbreaks; vector<int> vpbreaks;
ndb->getPagePositions(docid, vpbreaks); ndb->getPagePositions(docid, vpbreaks);
LOGABS("makeAbstract:" << (chron.millis()) << ": extracting. Got " << (vpbreaks.size()) << " pages\n" ); LOGABS("makeAbstract:" << chron.millis() << "mS: extracting. Got " <<
vpbreaks.size() << " pages\n");
// Finally build the abstract by walking the map (in order of position) // Finally build the abstract by walking the map (in order of position)
vabs.clear(); vabs.clear();
string chunk; string chunk;
@ -571,9 +583,10 @@ int Query::Native::makeAbstract(Xapian::docid docid,
string term; string term;
for (map<unsigned int, string>::const_iterator it = sparseDoc.begin(); for (map<unsigned int, string>::const_iterator it = sparseDoc.begin();
it != sparseDoc.end(); it++) { it != sparseDoc.end(); it++) {
LOGDEB2("Abtract:output " << (it->first) << " -> [" << (it->second) << "]\n" ); LOGDEB2("Abtract:output " << it->first << " -> [" << it->second <<
"]\n");
if (!occupiedmarker.compare(it->second)) { if (!occupiedmarker.compare(it->second)) {
LOGDEB("Abstract: qtrm position not filled ??\n" ); LOGDEB("Abstract: qtrm position not filled ??\n");
continue; continue;
} }
if (chunk.empty() && !vpbreaks.empty()) { if (chunk.empty() && !vpbreaks.empty()) {
@ -603,12 +616,9 @@ int Query::Native::makeAbstract(Xapian::docid docid,
if (!chunk.empty()) if (!chunk.empty())
vabs.push_back(Snippet(page, chunk).setTerm(term)); vabs.push_back(Snippet(page, chunk).setTerm(term));
LOGDEB2("makeAbtract: done in " << (chron.millis()) << " mS\n" ); LOGABS("makeAbtract: done in " << chron.millis() << " mS\n");
return ret; return ret;
} }
} }