indents etc.

This commit is contained in:
Jean-Francois Dockes 2021-04-22 09:03:36 +02:00
parent eca2f47a2a
commit d207d4f1c5
3 changed files with 82 additions and 93 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2005 J.F.Dockes /* Copyright (C) 2005-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
@ -24,19 +24,17 @@ using std::string;
static bool filter(const DocSeqFiltSpec& fs, const Rcl::Doc *x) static bool filter(const DocSeqFiltSpec& fs, const Rcl::Doc *x)
{ {
LOGDEB2(" Filter: ncrits " << (fs.crits.size()) << "\n" ); LOGDEB2(" Filter: ncrits " << fs.crits.size() << "\n");
// Compare using each criterion in term. We're doing an or: // Compare using each criterion in term. We're doing an or: 1st ok ends
// 1st ok ends
for (unsigned int i = 0; i < fs.crits.size(); i++) { for (unsigned int i = 0; i < fs.crits.size(); i++) {
switch (fs.crits[i]) { switch (fs.crits[i]) {
case DocSeqFiltSpec::DSFS_MIMETYPE: case DocSeqFiltSpec::DSFS_MIMETYPE:
LOGDEB2(" filter: MIMETYPE: me [" << (fs.values[i]) << "] doc [" << (x->mimetype) << "]\n" ); LOGDEB2(" filter: MIMETYPE: me [" << fs.values[i] << "] doc [" << x->mimetype << "]\n");
if (x->mimetype == fs.values[i]) if (x->mimetype == fs.values[i])
return true; return true;
break; break;
case DocSeqFiltSpec::DSFS_QLANG: case DocSeqFiltSpec::DSFS_QLANG: {
{ LOGDEB(" filter: QLANG [" << fs.values[i] << "]!!\n");
LOGDEB(" filter: QLANG [" << (fs.values[i]) << "]!!\n" );
} }
break; break;
case DocSeqFiltSpec::DSFS_PASSALL: case DocSeqFiltSpec::DSFS_PASSALL:
@ -47,8 +45,8 @@ static bool filter(const DocSeqFiltSpec& fs, const Rcl::Doc *x)
return false; return false;
} }
DocSeqFiltered::DocSeqFiltered(RclConfig *conf, std::shared_ptr<DocSequence> iseq, DocSeqFiltered::DocSeqFiltered(
DocSeqFiltSpec &filtspec) RclConfig *conf, std::shared_ptr<DocSequence> iseq, DocSeqFiltSpec &filtspec)
: DocSeqModifier(iseq), m_config(conf) : DocSeqModifier(iseq), m_config(conf)
{ {
setFiltSpec(filtspec); setFiltSpec(filtspec);
@ -56,26 +54,23 @@ DocSeqFiltered::DocSeqFiltered(RclConfig *conf, std::shared_ptr<DocSequence> ise
bool DocSeqFiltered::setFiltSpec(const DocSeqFiltSpec &filtspec) bool DocSeqFiltered::setFiltSpec(const DocSeqFiltSpec &filtspec)
{ {
LOGDEB0("DocSeqFiltered::setFiltSpec\n" ); LOGDEB0("DocSeqFiltered::setFiltSpec\n");
for (unsigned int i = 0; i < filtspec.crits.size(); i++) { for (unsigned int i = 0; i < filtspec.crits.size(); i++) {
switch (filtspec.crits[i]) { switch (filtspec.crits[i]) {
case DocSeqFiltSpec::DSFS_MIMETYPE: case DocSeqFiltSpec::DSFS_MIMETYPE:
m_spec.orCrit(filtspec.crits[i], filtspec.values[i]); m_spec.orCrit(filtspec.crits[i], filtspec.values[i]);
break; break;
case DocSeqFiltSpec::DSFS_QLANG: case DocSeqFiltSpec::DSFS_QLANG: {
{ // There are very few lang constructs that we can interpret. The
// There are very few lang constructs that we can // default config uses rclcat:value only. That will be all for now...
// interpret. The default config uses rclcat:value
// only. That will be all for now...
string val = filtspec.values[i]; string val = filtspec.values[i];
if (val.find("rclcat:") == 0) { if (val.find("rclcat:") == 0) {
string catg = val.substr(7); string catg = val.substr(7);
vector<string> tps; vector<string> tps;
m_config->getMimeCatTypes(catg, tps); m_config->getMimeCatTypes(catg, tps);
for (vector<string>::const_iterator it = tps.begin(); for (const auto& mime : tps) {
it != tps.end(); it++) { LOGDEB2("Adding mime: [" << mime << "]\n");
LOGDEB2("Adding mime: [" << *it << "]\n"); m_spec.orCrit(DocSeqFiltSpec::DSFS_MIMETYPE, mime);
m_spec.orCrit(DocSeqFiltSpec::DSFS_MIMETYPE, *it);
} }
} }
} }
@ -94,7 +89,7 @@ bool DocSeqFiltered::setFiltSpec(const DocSeqFiltSpec &filtspec)
bool DocSeqFiltered::getDoc(int idx, Rcl::Doc &doc, string *) bool DocSeqFiltered::getDoc(int idx, Rcl::Doc &doc, string *)
{ {
LOGDEB2("DocSeqFiltered::getDoc() fetching " << (idx) << "\n" ); LOGDEB2("DocSeqFiltered::getDoc() fetching " << idx << "\n");
if (idx >= (int)m_dbindices.size()) { if (idx >= (int)m_dbindices.size()) {
// Have to fetch docs and filter until we get enough or // Have to fetch docs and filter until we get enough or

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2005 J.F.Dockes /* Copyright (C) 2005-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
@ -16,10 +16,9 @@
*/ */
#include "autoconfig.h" #include "autoconfig.h"
#include "sortseq.h"
#include <algorithm> #include <algorithm>
#include "sortseq.h"
#include "log.h" #include "log.h"
using std::string; using std::string;
@ -31,8 +30,7 @@ public:
// It's not too clear in the std::sort doc what this should do. This // It's not too clear in the std::sort doc what this should do. This
// behaves as operator< // behaves as operator<
int operator()(const Rcl::Doc *x, const Rcl::Doc *y) int operator()(const Rcl::Doc *x, const Rcl::Doc *y) {
{
LOGDEB1("Comparing .. \n" ); LOGDEB1("Comparing .. \n" );
const auto xit = x->meta.find(ss.field); const auto xit = x->meta.find(ss.field);
@ -53,7 +51,7 @@ bool DocSeqSorted::setSortSpec(const DocSeqSortSpec &sortspec)
int i; int i;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (!m_seq->getDoc(i, m_docs[i])) { if (!m_seq->getDoc(i, m_docs[i])) {
LOGERR("DocSeqSorted: getDoc failed for doc " << (i) << "\n" ); LOGERR("DocSeqSorted: getDoc failed for doc " << i << "\n");
count = i; count = i;
break; break;
} }
@ -70,10 +68,9 @@ bool DocSeqSorted::setSortSpec(const DocSeqSortSpec &sortspec)
bool DocSeqSorted::getDoc(int num, Rcl::Doc &doc, string *) bool DocSeqSorted::getDoc(int num, Rcl::Doc &doc, string *)
{ {
LOGDEB("DocSeqSorted::getDoc(" << (num) << ")\n" ); LOGDEB("DocSeqSorted::getDoc(" << num << ")\n");
if (num < 0 || num >= int(m_docsp.size())) if (num < 0 || num >= int(m_docsp.size()))
return false; return false;
doc = *m_docsp[num]; doc = *m_docsp[num];
return true; return true;
} }

View File

@ -1570,8 +1570,7 @@ bool Db::addOrUpdate(const string &udi, const string &parent_udi, Doc &doc)
// There is no way in hell we could have an idea of the // There is no way in hell we could have an idea of the
// charset here, so let's hope it's ascii or utf-8. We call // charset here, so let's hope it's ascii or utf-8. We call
// transcode to strip the bad chars and pray // transcode to strip the bad chars and pray
if (transcode(path_getsimple(doc.ipath), utf8ipathlast, if (transcode(path_getsimple(doc.ipath), utf8ipathlast, "UTF-8", "UTF-8")) {
"UTF-8", "UTF-8")) {
splitter.text_to_words(utf8ipathlast); splitter.text_to_words(utf8ipathlast);
} }
} }
@ -1596,14 +1595,12 @@ bool Db::addOrUpdate(const string &udi, const string &parent_udi, Doc &doc)
splitter.curpos = 0; splitter.curpos = 0;
newdocument.add_posting(wrap_prefix(pathelt_prefix), newdocument.add_posting(wrap_prefix(pathelt_prefix),
splitter.basepos + splitter.curpos++); splitter.basepos + splitter.curpos++);
for (vector<string>::iterator it = vpath.begin(); for (auto& elt : vpath) {
it != vpath.end(); it++){ if (elt.length() > 230) {
if (it->length() > 230) { // Just truncate it. May still be useful because of wildcards
// Just truncate it. May still be useful because elt = elt.substr(0, 230);
// of wildcards
*it = it->substr(0, 230);
} }
newdocument.add_posting(wrap_prefix(pathelt_prefix) + *it, newdocument.add_posting(wrap_prefix(pathelt_prefix) + elt,
splitter.basepos + splitter.curpos++); splitter.basepos + splitter.curpos++);
} }
splitter.basepos += splitter.curpos + 100; splitter.basepos += splitter.curpos + 100;