recollq: specify max snippets list length with option -p
This commit is contained in:
parent
5ea2f7cc64
commit
1795320873
@ -58,13 +58,14 @@ bool dump_contents(RclConfig *rclconfig, Rcl::Doc& idoc)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
string make_abstract(Rcl::Doc& doc, Rcl::Query& query, bool asSnippets)
|
string make_abstract(Rcl::Doc& doc, Rcl::Query& query, bool asSnippets,
|
||||||
|
int snipcount)
|
||||||
{
|
{
|
||||||
string abstract;
|
string abstract;
|
||||||
if (asSnippets) {
|
if (asSnippets) {
|
||||||
std::vector<Rcl::Snippet> snippets;
|
std::vector<Rcl::Snippet> snippets;
|
||||||
std::ostringstream str;
|
std::ostringstream str;
|
||||||
if (query.makeDocAbstract(doc, snippets, -1, -1, true)) {
|
if (query.makeDocAbstract(doc, snippets, snipcount, -1, true)) {
|
||||||
for (const auto snippet : snippets) {
|
for (const auto snippet : snippets) {
|
||||||
str << snippet.page << " : " << snippet.snippet << endl;
|
str << snippet.page << " : " << snippet.snippet << endl;
|
||||||
}
|
}
|
||||||
@ -78,7 +79,8 @@ string make_abstract(Rcl::Doc& doc, Rcl::Query& query, bool asSnippets)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void output_fields(vector<string> fields, Rcl::Doc& doc,
|
void output_fields(vector<string> fields, Rcl::Doc& doc,
|
||||||
Rcl::Query& query, Rcl::Db&, bool printnames, bool asSnippets)
|
Rcl::Query& query, Rcl::Db&, bool printnames,
|
||||||
|
bool asSnippets, int snipcnt)
|
||||||
{
|
{
|
||||||
if (fields.empty()) {
|
if (fields.empty()) {
|
||||||
map<string,string>::const_iterator it;
|
map<string,string>::const_iterator it;
|
||||||
@ -90,7 +92,7 @@ void output_fields(vector<string> fields, Rcl::Doc& doc,
|
|||||||
it != fields.end(); it++) {
|
it != fields.end(); it++) {
|
||||||
string out;
|
string out;
|
||||||
if (!it->compare("abstract")) {
|
if (!it->compare("abstract")) {
|
||||||
base64_encode(make_abstract(doc, query, asSnippets), out);
|
base64_encode(make_abstract(doc, query, asSnippets, snipcnt), out);
|
||||||
} else if (!it->compare("xdocid")) {
|
} else if (!it->compare("xdocid")) {
|
||||||
char cdocid[30];
|
char cdocid[30];
|
||||||
sprintf(cdocid, "%lu", (unsigned long)doc.xdocid);
|
sprintf(cdocid, "%lu", (unsigned long)doc.xdocid);
|
||||||
@ -212,6 +214,8 @@ int recollq(RclConfig **cfp, int argc, char **argv)
|
|||||||
|
|
||||||
int firstres = 0;
|
int firstres = 0;
|
||||||
int maxcount = 2000;
|
int maxcount = 2000;
|
||||||
|
int snipcnt = -1;
|
||||||
|
|
||||||
thisprog = argv[0];
|
thisprog = argv[0];
|
||||||
argc--; argv++;
|
argc--; argv++;
|
||||||
|
|
||||||
@ -265,7 +269,18 @@ int recollq(RclConfig **cfp, int argc, char **argv)
|
|||||||
argc--; goto b1;
|
argc--; goto b1;
|
||||||
case 'o': op_flags |= OPT_o; break;
|
case 'o': op_flags |= OPT_o; break;
|
||||||
case 'P': op_flags |= OPT_P; break;
|
case 'P': op_flags |= OPT_P; break;
|
||||||
case 'p': op_flags |= OPT_p; break;
|
case 'p':
|
||||||
|
{
|
||||||
|
op_flags |= OPT_p;
|
||||||
|
if (argc < 2)
|
||||||
|
Usage();
|
||||||
|
const char *cp = *(++argv);
|
||||||
|
char *cpe;
|
||||||
|
snipcnt = strtol(cp, &cpe, 10);
|
||||||
|
if (*cpe != 0)
|
||||||
|
Usage();
|
||||||
|
argc--; goto b1;
|
||||||
|
}
|
||||||
case 'q': op_flags |= OPT_q; break;
|
case 'q': op_flags |= OPT_q; break;
|
||||||
case 'Q': op_flags |= OPT_Q; break;
|
case 'Q': op_flags |= OPT_Q; break;
|
||||||
case 'S': op_flags |= OPT_S; if (argc < 2) Usage();
|
case 'S': op_flags |= OPT_S; if (argc < 2) Usage();
|
||||||
@ -424,7 +439,7 @@ endopts:
|
|||||||
|
|
||||||
if (op_flags & OPT_F) {
|
if (op_flags & OPT_F) {
|
||||||
output_fields(fields, doc, query, rcldb,
|
output_fields(fields, doc, query, rcldb,
|
||||||
op_flags & OPT_N, op_flags & OPT_p);
|
op_flags & OPT_N, op_flags & OPT_p, snipcnt);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,7 +473,7 @@ endopts:
|
|||||||
}
|
}
|
||||||
if (op_flags & OPT_A) {
|
if (op_flags & OPT_A) {
|
||||||
bool asSnippets = (op_flags & OPT_p) != 0;
|
bool asSnippets = (op_flags & OPT_p) != 0;
|
||||||
string abstract = make_abstract(doc, query, asSnippets);
|
string abstract = make_abstract(doc, query, asSnippets, snipcnt);
|
||||||
string marker = asSnippets ? "SNIPPETS" : "ABSTRACT";
|
string marker = asSnippets ? "SNIPPETS" : "ABSTRACT";
|
||||||
if (!abstract.empty()) {
|
if (!abstract.empty()) {
|
||||||
cout << marker << endl;
|
cout << marker << endl;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user