Switch to unified view

a/src/rcldb/searchdata.cpp b/src/rcldb/searchdata.cpp
...
...
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
17
18
// Handle translation from rcl's SearchData structures to Xapian Queries
18
// Handle translation from rcl's SearchData structures to Xapian Queries
19
#include <stdio.h>
19
#include <stdio.h>
20
#include <fnmatch.h>
20
21
21
#include <string>
22
#include <string>
22
#include <vector>
23
#include <vector>
23
#include <algorithm>
24
#include <algorithm>
24
25
...
...
131
    buf[0] = 'M';
132
    buf[0] = 'M';
132
    v.push_back(Xapian::Query(buf));
133
    v.push_back(Xapian::Query(buf));
133
    }
134
    }
134
135
135
    return Xapian::Query(Xapian::Query::OP_OR, v.begin(), v.end());
136
    return Xapian::Query(Xapian::Query::OP_OR, v.begin(), v.end());
137
}
138
139
// Expand categories and mime type wild card exps
140
bool SearchData::expandFileTypes(RclConfig *cfg, vector<string>& tps)
141
{
142
    if (!cfg) {
143
  LOGFATAL(("Db::expandFileTypes: null configuration!!\n"));
144
  return false;
145
    }
146
    vector<string> exptps;
147
    list<string> alltypes = cfg->getAllMimeTypes();
148
149
    for (vector<string>::iterator it = tps.begin(); it != tps.end(); it++) {
150
  if (cfg->isMimeCategory(*it)) {
151
      list<string>tps;
152
      cfg->getMimeCatTypes(*it, tps);
153
      exptps.insert(exptps.end(), tps.begin(), tps.end());
154
  } else {
155
      for (list<string>::const_iterator ait = alltypes.begin();
156
       ait != alltypes.end(); ait++) {
157
      if (fnmatch(it->c_str(), ait->c_str(), FNM_CASEFOLD) 
158
          != FNM_NOMATCH) {
159
          exptps.push_back(*ait);
160
      }
161
      }
162
  }
163
    }
164
    tps = exptps;
165
    return true;
136
}
166
}
137
167
138
bool SearchData::toNativeQuery(Rcl::Db &db, void *d)
168
bool SearchData::toNativeQuery(Rcl::Db &db, void *d)
139
{
169
{
140
    Xapian::Query xq;
170
    Xapian::Query xq;
...
...
218
        }
248
        }
219
    }
249
    }
220
250
221
    // Add the file type filtering clause if any
251
    // Add the file type filtering clause if any
222
    if (!m_filetypes.empty()) {
252
    if (!m_filetypes.empty()) {
223
  vector<string> exptps;
253
  expandFileTypes(db.getConf(), m_filetypes);
224
  exptps.reserve(m_filetypes.size());
254
      
225
  // Expand categories
255
  Xapian::Query tq;
226
  RclConfig *cfg = db.getConf();
227
    for (vector<string>::iterator it = m_filetypes.begin(); 
256
    for (vector<string>::iterator it = m_filetypes.begin(); 
228
         it != m_filetypes.end(); it++) {
257
         it != m_filetypes.end(); it++) {
229
      if (cfg && cfg->isMimeCategory(*it)) {
230
      list<string>tps;
231
      cfg->getMimeCatTypes(*it, tps);
232
      exptps.insert(exptps.end(), tps.begin(), tps.end());
233
      } else {
234
      exptps.push_back(*it);
235
      }
236
  }
237
      
238
  Xapian::Query tq;
239
  for (vector<string>::iterator it = exptps.begin(); 
240
       it != exptps.end(); it++) {
241
        string term = "T" + *it;
258
        string term = "T" + *it;
242
        LOGDEB0(("Adding file type term: [%s]\n", term.c_str()));
259
        LOGDEB0(("Adding file type term: [%s]\n", term.c_str()));
243
        tq = tq.empty() ? Xapian::Query(term) : 
260
        tq = tq.empty() ? Xapian::Query(term) : 
244
        Xapian::Query(Xapian::Query::OP_OR, tq, Xapian::Query(term));
261
        Xapian::Query(Xapian::Query::OP_OR, tq, Xapian::Query(term));
245
    }
262
    }
246
    xq = xq.empty() ? tq : Xapian::Query(Xapian::Query::OP_FILTER, xq, tq);
263
    xq = xq.empty() ? tq : Xapian::Query(Xapian::Query::OP_FILTER, xq, tq);
264
    }
265
266
    // Add the neg file type filtering clause if any
267
    if (!m_nfiletypes.empty()) {
268
  expandFileTypes(db.getConf(), m_nfiletypes);
269
      
270
  Xapian::Query tq;
271
  for (vector<string>::iterator it = m_nfiletypes.begin(); 
272
       it != m_nfiletypes.end(); it++) {
273
      string term = "T" + *it;
274
      LOGDEB0(("Adding negative file type term: [%s]\n", term.c_str()));
275
      tq = tq.empty() ? Xapian::Query(term) : 
276
      Xapian::Query(Xapian::Query::OP_OR, tq, Xapian::Query(term));
277
  }
278
  xq = xq.empty() ? tq : Xapian::Query(Xapian::Query::OP_AND_NOT, xq, tq);
247
    }
279
    }
248
280
249
    // Add the directory filtering clause
281
    // Add the directory filtering clause
250
    if (!m_topdir.empty()) {
282
    if (!m_topdir.empty()) {
251
    vector<string> vpath;
283
    vector<string> vpath;