Switch to unified view

a/src/query/filtseq.cpp b/src/query/filtseq.cpp
...
...
12
 *   You should have received a copy of the GNU General Public License
12
 *   You should have received a copy of the GNU General Public License
13
 *   along with this program; if not, write to the
13
 *   along with this program; if not, write to the
14
 *   Free Software Foundation, Inc.,
14
 *   Free Software Foundation, Inc.,
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
 */
16
 */
17
#include <algorithm>
18
17
19
#include "debuglog.h"
18
#include "debuglog.h"
20
#include "filtseq.h"
19
#include "filtseq.h"
20
#include "rclconfig.h"
21
21
22
using std::string;
22
using std::string;
23
23
24
static bool filter(const DocSeqFiltSpec& fs, const Rcl::Doc *x)
24
static bool filter(const DocSeqFiltSpec& fs, const Rcl::Doc *x)
25
{
25
{
26
    LOGDEB2(("  Filter: ncrits %d\n", fs.crits.size()));
26
    // Compare using each criterion in term. We're doing an or:
27
    // Compare using each criterion in term. We're doing an or:
27
    // 1st ok ends 
28
    // 1st ok ends 
28
    for (unsigned int i = 0; i < fs.crits.size(); i++) {
29
    for (unsigned int i = 0; i < fs.crits.size(); i++) {
29
    switch (fs.crits[i]) {
30
    switch (fs.crits[i]) {
30
    case DocSeqFiltSpec::DSFS_MIMETYPE:
31
    case DocSeqFiltSpec::DSFS_MIMETYPE:
31
      LOGDEB1((" MIMETYPE\n"));
32
      LOGDEB2((" filter: MIMETYPE: me [%s] doc [%s]\n",
33
          fs.values[i].c_str(), x->mimetype.c_str()));
32
        if (x->mimetype == fs.values[i])
34
        if (x->mimetype == fs.values[i])
33
        return 1;
35
        return true;
36
      break;
37
  case DocSeqFiltSpec::DSFS_QLANG:
38
  {
39
      LOGDEB((" filter: QLANG [%s]!!\n", fs.values[i].c_str()));
40
  }
41
  break;
42
  case DocSeqFiltSpec::DSFS_PASSALL:
43
      return true;
34
    }
44
    }
35
    }
45
    }
36
    // Did all comparisons
46
    // Did all comparisons
37
    return 0;
47
    return false;
38
} 
48
} 
49
50
DocSeqFiltered::DocSeqFiltered(RclConfig *conf, RefCntr<DocSequence> iseq, 
51
                 DocSeqFiltSpec &filtspec)
52
    :  DocSeqModifier(iseq), m_config(conf)
53
{
54
    setFiltSpec(filtspec);
55
}
39
56
40
bool DocSeqFiltered::setFiltSpec(DocSeqFiltSpec &filtspec)
57
bool DocSeqFiltered::setFiltSpec(DocSeqFiltSpec &filtspec)
41
{
58
{
42
    m_spec = filtspec;
59
    LOGDEB0(("DocSeqFiltered::setFiltSpec\n"));
60
    for (unsigned int i = 0; i < filtspec.crits.size(); i++) {
61
  switch (filtspec.crits[i]) {
62
  case DocSeqFiltSpec::DSFS_MIMETYPE:
63
      m_spec.orCrit(filtspec.crits[i], filtspec.values[i]);
64
      break;
65
  case DocSeqFiltSpec::DSFS_QLANG:
66
  {
67
      // There are very few lang constructs that we can
68
      // interpret. The default config uses rclcat:value
69
      // only. That will be all for now...
70
      string val = filtspec.values[i];
71
      if (val.find("rclcat:") == 0) {
72
      string catg = val.substr(7);
73
      list<string> tps;
74
      m_config->getMimeCatTypes(catg, tps);
75
      for (list<string>::const_iterator it = tps.begin();
76
           it != tps.end(); it++) {
77
          LOGDEB2(("Adding mime: [%s]\n", it->c_str()));
78
          m_spec.orCrit(DocSeqFiltSpec::DSFS_MIMETYPE, *it);
79
      }
80
      }
81
  }
82
  break;
83
  default:
84
      break;
85
  }
86
    }
87
    // If m_spec ends up empty, pass everything, better than filtering all.
88
    if (m_spec.crits.empty()) {
89
  m_spec.orCrit(DocSeqFiltSpec::DSFS_PASSALL, "");
90
    }
43
    m_dbindices.clear();
91
    m_dbindices.clear();
44
    return true;
92
    return true;
45
}
93
}
46
94
47
bool DocSeqFiltered::getDoc(int idx, Rcl::Doc &doc, string *)
95
bool DocSeqFiltered::getDoc(int idx, Rcl::Doc &doc, string *)
48
{
96
{
49
    LOGDEB1(("DocSeqFiltered: fetching %d\n", idx));
97
    LOGDEB2(("DocSeqFiltered::getDoc() fetching %d\n", idx));
50
98
51
    if (idx >= (int)m_dbindices.size()) {
99
    if (idx >= (int)m_dbindices.size()) {
52
    // Have to fetch docs and filter until we get enough or
100
    // Have to fetch docs and filter until we get enough or
53
    // fail
101
    // fail
54
    m_dbindices.reserve(idx+1);
102
    m_dbindices.reserve(idx+1);