Keep only the main Snippet-producing makeabstract in rclquery, further formatting done in using modules

This commit is contained in:
Jean-Francois Dockes
2019-05-13 18:11:23 +02:00
parent ee5a260d54
commit 34d43d1188
4 changed files with 53 additions and 67 deletions
+16 -2
View File
@@ -20,6 +20,8 @@
#include <time.h>
#include <list>
#include <sstream>
#include <vector>
#include "docseqdb.h"
#include "rcldb.h"
@@ -27,6 +29,7 @@
#include "wasatorcl.h"
using std::list;
using std::vector;
DocSequenceDb::DocSequenceDb(std::shared_ptr<Rcl::Db> db,
std::shared_ptr<Rcl::Query> q, const string &t,
@@ -114,8 +117,19 @@ bool DocSequenceDb::getAbstract(Rcl::Doc &doc, vector<string>& vabs)
return false;
if (m_q->whatDb() &&
m_queryBuildAbstract && (doc.syntabs || m_queryReplaceAbstract)) {
m_q->makeDocAbstract(doc, vabs);
}
vector<Rcl::Snippet> vpabs;
m_q->makeDocAbstract(doc, vpabs);
for (const auto& snippet : vpabs) {
string chunk;
if (snippet.page > 0) {
std::ostringstream ss;
ss << snippet.page;
chunk += string(" [p ") + ss.str() + "] ";
}
chunk += snippet.snippet;
vabs.push_back(chunk);
}
}
if (vabs.empty())
vabs.push_back(doc.meta[Rcl::Doc::keyabs]);
return true;
+16 -2
View File
@@ -56,6 +56,19 @@ bool dump_contents(RclConfig *rclconfig, Rcl::Doc& idoc)
return true;
}
static const string cstr_ellipsis("...");
static void stringAbstract(Rcl::Query& query, Rcl::Doc doc, string& abstract)
{
abstract.clear();
vector<Rcl::Snippet> vpabs;
query.makeDocAbstract(doc, vpabs);
for (const auto& snippet : vpabs) {
abstract.append(snippet.snippet);
abstract.append(cstr_ellipsis);
}
}
void output_fields(vector<string> fields, Rcl::Doc& doc,
Rcl::Query& query, Rcl::Db& rcldb, bool printnames)
{
@@ -70,7 +83,7 @@ void output_fields(vector<string> fields, Rcl::Doc& doc,
string out;
if (!it->compare("abstract")) {
string abstract;
query.makeDocAbstract(doc, abstract);
stringAbstract(query, doc, abstract);
base64_encode(abstract, out);
} else if (!it->compare("xdocid")) {
char cdocid[30];
@@ -412,7 +425,8 @@ endopts:
}
if (op_flags & OPT_A) {
string abstract;
if (query.makeDocAbstract(doc, abstract)) {
stringAbstract(query, doc, abstract);
if (abstract.size()) {
cout << "ABSTRACT" << endl;
cout << abstract << endl;
cout << "/ABSTRACT" << endl;