Switch to unified view

a/src/query/wasastringtoquery.cpp b/src/query/wasastringtoquery.cpp
1
#ifndef lint
1
#ifndef lint
2
static char rcsid[] = "@(#$Id: wasastringtoquery.cpp,v 1.2 2006-12-08 10:54:38 dockes Exp $ (C) 2006 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: wasastringtoquery.cpp,v 1.3 2006-12-10 17:03:08 dockes Exp $ (C) 2006 J.F.Dockes";
3
#endif
3
#endif
4
/*
4
/*
5
 *   This program is free software; you can redistribute it and/or modify
5
 *   This program is free software; you can redistribute it and/or modify
6
 *   it under the terms of the GNU General Public License as published by
6
 *   it under the terms of the GNU General Public License as published by
7
 *   the Free Software Foundation; either version 2 of the License, or
7
 *   the Free Software Foundation; either version 2 of the License, or
...
...
34
    m_subs.clear();
34
    m_subs.clear();
35
}
35
}
36
36
37
void WasaQuery::describe(string &desc) const
37
void WasaQuery::describe(string &desc) const
38
{
38
{
39
    if (!m_types.empty()) {
40
  desc += "type_restrict(";
41
  for (vector<string>::const_iterator it = m_types.begin();
42
       it != m_types.end(); it++) {
43
      desc += *it + ", ";
44
  }
45
  desc.erase(desc.size() - 2);
46
  desc += ")";
47
    }
48
    if (m_sortSpec.size() > 1 || 
49
  (m_sortSpec.size() == 1 && m_sortSpec[0] != WQSK_REL)) {
50
  desc += "sort_by(";
51
  for (vector<SortKind>::const_iterator it = m_sortSpec.begin();
52
       it != m_sortSpec.end(); it++) {
53
      switch (*it) {
54
      case WQSK_DATE: desc += string("date") + ", ";break;
55
      case WQSK_ALPHA: desc += string("name") + ", ";break;
56
      case WQSK_GROUP: desc += string("group") + ", ";break;
57
      case WQSK_REL: default: desc += string("relevance") + ", ";break;
58
      }
59
  }
60
  desc.erase(desc.size() - 2);
61
  desc += ")";
62
    }
39
    desc += "(";
63
    desc += "(";
40
    switch (m_op) {
64
    switch (m_op) {
41
    case OP_NULL: 
65
    case OP_NULL: 
42
    desc += "NULL"; 
66
    desc += "NULL"; 
43
    break;
67
    break;
...
...
266
        }
290
        }
267
        if (nclause->m_value.empty()) {
291
        if (nclause->m_value.empty()) {
268
        // Isolated +- or fieldname: without a value. Ignore until
292
        // Isolated +- or fieldname: without a value. Ignore until
269
        // told otherwise.
293
        // told otherwise.
270
        delete nclause;
294
        delete nclause;
271
      return 0;
295
      goto nextfield;
296
      }
297
298
      // Field indicator ?
299
      if (checkSubMatch(SMI_FIELD, match, reason)) {
300
      // Check for special fields
301
      if (match == string("mime")) {
302
          if (query->m_typeKind == WasaQuery::WQTK_NONE)
303
          query->m_typeKind = WasaQuery::WQTK_MIME;
304
          if (query->m_typeKind == WasaQuery::WQTK_MIME)
305
          query->m_types.push_back(nclause->m_value);
306
          delete nclause;
307
          goto nextfield;
308
      } else if (match == string("group")) {
309
          if (query->m_typeKind == WasaQuery::WQTK_NONE)
310
          query->m_typeKind = WasaQuery::WQTK_GROUP;
311
          if (query->m_typeKind == WasaQuery::WQTK_GROUP)
312
          query->m_types.push_back(nclause->m_value);
313
          delete nclause;
314
          goto nextfield;
315
      } else if (match == string("filetype") || 
316
             match == string("ext")) {
317
          if (query->m_typeKind == WasaQuery::WQTK_NONE)
318
          query->m_typeKind = WasaQuery::WQTK_EXT;
319
          if (query->m_typeKind == WasaQuery::WQTK_EXT)
320
          query->m_types.push_back(nclause->m_value);
321
          delete nclause;
322
          goto nextfield;
323
      } else if (match == string("sort")) {
324
          if (nclause->m_value == "score") {
325
          query->m_sortSpec.push_back(WasaQuery::WQSK_REL);
326
          } else if (nclause->m_value == "date") {
327
          query->m_sortSpec.push_back(WasaQuery::WQSK_DATE);
328
          } else if (nclause->m_value == "alpha") {
329
          query->m_sortSpec.push_back(WasaQuery::WQSK_ALPHA);
330
          } else if (nclause->m_value == "group") {
331
          query->m_sortSpec.push_back(WasaQuery::WQSK_GROUP);
332
          }
333
          delete nclause;
334
          goto nextfield;
335
      } else {
336
          nclause->m_fieldspec = match;
337
      }
272
        }
338
        }
273
339
274
        // +- indicator ?
340
        // +- indicator ?
275
        if (checkSubMatch(SMI_PM, match, reason) && match[0] == '-') {
341
        if (checkSubMatch(SMI_PM, match, reason) && match[0] == '-') {
276
        nclause->m_op = WasaQuery::OP_EXCL;
342
        nclause->m_op = WasaQuery::OP_EXCL;
277
        } else {
343
        } else {
278
        nclause->m_op = WasaQuery::OP_LEAF;
344
        nclause->m_op = WasaQuery::OP_LEAF;
279
        }
345
        }
280
346
281
      // Field indicator ?
282
      if (checkSubMatch(SMI_FIELD, match, reason)) {
283
      nclause->m_fieldspec = match;
284
      }
285
347
286
        if (prev_or) {
348
        if (prev_or) {
287
        // We're in an OR subquery, add new subquery
349
        // We're in an OR subquery, add new subquery
288
        orClause->m_subs.push_back(nclause);
350
        orClause->m_subs.push_back(nclause);
289
        } else {
351
        } else {
...
...
296
        query->m_subs.push_back(nclause);
358
        query->m_subs.push_back(nclause);
297
        }
359
        }
298
        prev_or = false;
360
        prev_or = false;
299
    }
361
    }
300
362
363
    nextfield:
301
    // Advance current string position. We checked earlier that
364
    // Advance current string position. We checked earlier that
302
    // the increment is strictly positive, so we won't loop
365
    // the increment is strictly positive, so we won't loop
303
    // forever
366
    // forever
304
    m_cp += m_pmatch[0].rm_eo;
367
    m_cp += m_pmatch[0].rm_eo;
305
    if (m_cp >= cpe)
368
    if (m_cp >= cpe)