Switch to unified view

a/src/rcldb/searchdata.cpp b/src/rcldb/searchdata.cpp
...
...
66
    m_autocasesens = true;
66
    m_autocasesens = true;
67
    m_maxexp = 10000;
67
    m_maxexp = 10000;
68
    m_maxcl = 100000;
68
    m_maxcl = 100000;
69
}
69
}
70
70
71
// Expand categories and mime type wild card exps
71
// Expand categories and mime type wild card exps Categories are
72
// Actually, using getAllMimeTypes() here is a bit problematic because
72
// expanded against the configuration, mimetypes against the index
73
// there maybe other types in the index, not indexed by content, but
73
// (for wildcards).
74
// which could be searched by file name. It would probably be
75
// preferable to do a termMatch() on field "mtype", which would
76
// retrieve all values from the index.
77
bool SearchData::expandFileTypes(const RclConfig *cfg, vector<string>& tps)
74
bool SearchData::expandFileTypes(Db &db, vector<string>& tps)
78
{
75
{
76
    const RclConfig *cfg = db.getConf();
79
    if (!cfg) {
77
    if (!cfg) {
80
    LOGFATAL(("Db::expandFileTypes: null configuration!!\n"));
78
    LOGFATAL(("Db::expandFileTypes: null configuration!!\n"));
81
    return false;
79
    return false;
82
    }
80
    }
83
    vector<string> exptps;
81
    vector<string> exptps;
84
    vector<string> alltypes = cfg->getAllMimeTypes();
85
82
86
    for (vector<string>::iterator it = tps.begin(); it != tps.end(); it++) {
83
    for (vector<string>::iterator it = tps.begin(); it != tps.end(); it++) {
87
    if (cfg->isMimeCategory(*it)) {
84
    if (cfg->isMimeCategory(*it)) {
88
        vector<string>tps;
85
        vector<string>tps;
89
        cfg->getMimeCatTypes(*it, tps);
86
        cfg->getMimeCatTypes(*it, tps);
90
        exptps.insert(exptps.end(), tps.begin(), tps.end());
87
        exptps.insert(exptps.end(), tps.begin(), tps.end());
91
    } else {
88
    } else {
92
      bool matched = false;
89
      TermMatchResult res;
93
      for (vector<string>::const_iterator ait = alltypes.begin();
90
      string mt = stringtolower((const string&)*it);
94
       ait != alltypes.end(); ait++) {
91
      db.termMatch(Db::ET_WILD, "", mt, res, -1, "mtype");
95
      if (fnmatch(it->c_str(), ait->c_str(), FNM_CASEFOLD) 
92
      if (res.entries.empty()) {
96
          != FNM_NOMATCH) {
97
            exptps.push_back(*ait);
93
        exptps.push_back(it->c_str());
98
          matched = true;
94
      } else {
95
      for (vector<TermMatchEntry>::const_iterator rit = 
96
           res.entries.begin(); rit != res.entries.end(); rit++) {
97
          exptps.push_back(strip_prefix(rit->term));
99
        }
98
        }
100
        }
99
        }
101
      if (!matched)
102
      exptps.push_back(it->c_str());
103
    }
100
    }
104
    }
101
    }
102
    sort(exptps.begin(), exptps.end());
103
    exptps.erase(unique(exptps.begin(), exptps.end()), exptps.end());
104
105
    tps = exptps;
105
    tps = exptps;
106
    return true;
106
    return true;
107
}
107
}
108
108
109
static const char *maxXapClauseMsg = 
109
static const char *maxXapClauseMsg = 
...
...
257
        }
257
        }
258
    }
258
    }
259
259
260
    // Add the file type filtering clause if any
260
    // Add the file type filtering clause if any
261
    if (!m_filetypes.empty()) {
261
    if (!m_filetypes.empty()) {
262
    expandFileTypes(db.getConf(), m_filetypes);
262
    expandFileTypes(db, m_filetypes);
263
        
263
        
264
    Xapian::Query tq;
264
    Xapian::Query tq;
265
    for (vector<string>::iterator it = m_filetypes.begin(); 
265
    for (vector<string>::iterator it = m_filetypes.begin(); 
266
         it != m_filetypes.end(); it++) {
266
         it != m_filetypes.end(); it++) {
267
        string term = wrap_prefix(mimetype_prefix) + *it;
267
        string term = wrap_prefix(mimetype_prefix) + *it;
...
...
272
    xq = xq.empty() ? tq : Xapian::Query(Xapian::Query::OP_FILTER, xq, tq);
272
    xq = xq.empty() ? tq : Xapian::Query(Xapian::Query::OP_FILTER, xq, tq);
273
    }
273
    }
274
274
275
    // Add the neg file type filtering clause if any
275
    // Add the neg file type filtering clause if any
276
    if (!m_nfiletypes.empty()) {
276
    if (!m_nfiletypes.empty()) {
277
    expandFileTypes(db.getConf(), m_nfiletypes);
277
    expandFileTypes(db, m_nfiletypes);
278
        
278
        
279
    Xapian::Query tq;
279
    Xapian::Query tq;
280
    for (vector<string>::iterator it = m_nfiletypes.begin(); 
280
    for (vector<string>::iterator it = m_nfiletypes.begin(); 
281
         it != m_nfiletypes.end(); it++) {
281
         it != m_nfiletypes.end(); it++) {
282
        string term = wrap_prefix(mimetype_prefix) + *it;
282
        string term = wrap_prefix(mimetype_prefix) + *it;