Switch to unified view

a/src/query/wasastringtoquery.cpp b/src/query/wasastringtoquery.cpp
...
...
18
#include <stdio.h>
18
#include <stdio.h>
19
#include <stdlib.h>
19
#include <stdlib.h>
20
#include <string.h>
20
#include <string.h>
21
#include <regex.h>
21
#include <regex.h>
22
22
23
#include "smallut.h"
23
#include "wasastringtoquery.h"
24
#include "wasastringtoquery.h"
24
25
25
// #define DEB_WASASTRINGTOQ 1
26
#undef DEB_WASASTRINGTOQ
26
#ifdef DEB_WASASTRINGTOQ
27
#ifdef DEB_WASASTRINGTOQ
27
#define DPRINT(X) fprintf X
28
#define DPRINT(X) fprintf X
28
#define DUMPQ(Q) {string D;Q->describe(D);fprintf(stderr, "%s\n", D.c_str());}
29
#define DUMPQ(Q) {string D;Q->describe(D);fprintf(stderr, "%s\n", D.c_str());}
29
#else
30
#else
30
#define DPRINT(X)
31
#define DPRINT(X)
...
...
87
    if (m_modifiers & WQM_BOOST)     desc += "BOOST|";
88
    if (m_modifiers & WQM_BOOST)     desc += "BOOST|";
88
    if (m_modifiers & WQM_CASESENS)  desc += "CASESENS|";
89
    if (m_modifiers & WQM_CASESENS)  desc += "CASESENS|";
89
    if (m_modifiers & WQM_DIACSENS)  desc += "DIACSENS|";
90
    if (m_modifiers & WQM_DIACSENS)  desc += "DIACSENS|";
90
    if (m_modifiers & WQM_FUZZY)     desc += "FUZZY|";
91
    if (m_modifiers & WQM_FUZZY)     desc += "FUZZY|";
91
    if (m_modifiers & WQM_NOSTEM)    desc += "NOSTEM|";
92
    if (m_modifiers & WQM_NOSTEM)    desc += "NOSTEM|";
92
    if (m_modifiers & WQM_PHRASESLACK) desc += "PHRASESLACK|";
93
    if (m_modifiers & WQM_PHRASESLACK) {
94
      char buf[100];
95
      sprintf(buf, "%d", m_slack);
96
      desc += "PHRASESLACK(" + string(buf) + string(")|");
97
  }
93
    if (m_modifiers & WQM_PROX)      desc += "PROX|";
98
    if (m_modifiers & WQM_PROX)      desc += "PROX|";
94
    if (m_modifiers & WQM_REGEX)     desc += "REGEX|";
99
    if (m_modifiers & WQM_REGEX)     desc += "REGEX|";
95
    if (m_modifiers & WQM_SLOPPY)    desc += "SLOPPY|";
100
    if (m_modifiers & WQM_SLOPPY)    desc += "SLOPPY|";
96
    if (m_modifiers & WQM_WORDS)     desc += "WORDS|";
101
    if (m_modifiers & WQM_WORDS)     desc += "WORDS|";
102
97
    if (desc.length() > 0 && desc[desc.length()-1] == '|')
103
    if (desc.length() > 0 && desc[desc.length()-1] == '|')
98
        desc = desc.substr(0, desc.length()-1);
104
        desc.erase(desc.length()-1);
99
    }
105
    }
100
    desc += " ";
106
    desc += " ";
101
}
107
}
102
108
103
// The string query parser code:
109
// The string query parser code:
...
...
222
}
228
}
223
229
224
WasaQuery *
230
WasaQuery *
225
StringToWasaQuery::stringToQuery(const string& str, string& reason)
231
StringToWasaQuery::stringToQuery(const string& str, string& reason)
226
{
232
{
233
    if (internal == 0)
234
  return 0;
227
    return internal ? internal->stringToQuery(str, reason) : 0;
235
    WasaQuery *wq = internal->stringToQuery(str, reason);
236
    DUMPQ(wq);
237
    return wq;
228
}
238
}
229
239
230
WasaQuery *
240
WasaQuery *
231
StringToWasaQuery::Internal::stringToQuery(const string& str, string& reason)
241
StringToWasaQuery::Internal::stringToQuery(const string& str, string& reason)
232
{
242
{
...
...
314
        reason = "Out of memory";
324
        reason = "Out of memory";
315
        return 0;
325
        return 0;
316
        }
326
        }
317
327
318
        // Check for quoted or unquoted value
328
        // Check for quoted or unquoted value
329
      unsigned int mods = 0;
319
        if (checkSubMatch(SMI_QUOTED, match, reason)) {
330
        if (checkSubMatch(SMI_QUOTED, match, reason)) {
320
        nclause->m_value = match;
331
        nclause->m_value = match;
321
        } else if (checkSubMatch(SMI_TERM, match, reason)) {
332
        } else if (checkSubMatch(SMI_TERM, match, reason)) {
322
        nclause->m_value = match;
333
        nclause->m_value = match;
323
        }
334
        }
...
...
330
        goto nextfield;
341
        goto nextfield;
331
        }
342
        }
332
        
343
        
333
        if (checkSubMatch(SMI_MODIF, match, reason)) {
344
        if (checkSubMatch(SMI_MODIF, match, reason)) {
334
        DPRINT((stderr, "Got modifiers: [%s]\n", match));
345
        DPRINT((stderr, "Got modifiers: [%s]\n", match));
335
      unsigned int mods = 0;
336
        for (unsigned int i = 0; i < strlen(match); i++) {
346
        for (unsigned int i = 0; i < strlen(match); i++) {
337
            switch (match[i]) {
347
            switch (match[i]) {
338
            case 'b': 
348
            case 'b': 
339
            mods |= WasaQuery::WQM_BOOST; 
349
            mods |= WasaQuery::WQM_BOOST; 
340
            nclause->m_weight = 10.0;
350
            nclause->m_weight = 10.0;
...
...
348
                WasaQuery::WQM_NOSTEM; 
358
                WasaQuery::WQM_NOSTEM; 
349
            break;
359
            break;
350
            case 'f': mods |= WasaQuery::WQM_FUZZY; break;
360
            case 'f': mods |= WasaQuery::WQM_FUZZY; break;
351
            case 'l': mods |= WasaQuery::WQM_NOSTEM; break;
361
            case 'l': mods |= WasaQuery::WQM_NOSTEM; break;
352
            case 'L': break;
362
            case 'L': break;
363
          case 'o': 
353
            case 'o': mods |= WasaQuery::WQM_PHRASESLACK; break;
364
          mods |= WasaQuery::WQM_PHRASESLACK; 
365
          // Default slack if specified only by 'o' is 10.
366
          nclause->m_slack = 10;
367
          if (i < strlen(match) - 1) {
368
              char *endptr;
369
              int slack = strtol(match+i+1, &endptr, 10);
370
              if (endptr != match+i+1) {
371
              i += endptr - (match+i+1);
372
              nclause->m_slack = slack;
373
              }
374
          }
375
          break;
354
            case 'p': mods |= WasaQuery::WQM_PROX; break;
376
            case 'p': mods |= WasaQuery::WQM_PROX; break;
355
            case 'r': mods |= WasaQuery::WQM_REGEX; break;
377
            case 'r': mods |= WasaQuery::WQM_REGEX; break;
356
            case 's': mods |= WasaQuery::WQM_SLOPPY; break;
378
            case 's': mods |= WasaQuery::WQM_SLOPPY; break;
357
            case 'w': mods |= WasaQuery::WQM_WORDS; break;
379
            case 'w': mods |= WasaQuery::WQM_WORDS; break;
358
            case '.':case '0':case '1':case '2':case '3':case '4':
380
            case '.':case '0':case '1':case '2':case '3':case '4':
...
...
368
            if (n)
390
            if (n)
369
                i += n-1;
391
                i += n-1;
370
            }
392
            }
371
            }
393
            }
372
        }
394
        }
395
      }
373
      nclause->m_modifiers = WasaQuery::Modifier(mods);
396
        nclause->m_modifiers = WasaQuery::Modifier(mods);
374
      }
375
397
376
        // Field indicator ?
398
        // Field indicator ?
377
        if (checkSubMatch(SMI_FIELD, match, reason)) {
399
        if (checkSubMatch(SMI_FIELD, match, reason)) {
378
        // We used Check for special fields indicating sorting
400
        // We used Check for special fields indicating sorting
379
        // etc. here but this went away from the spec. See 1.4
401
        // etc. here but this went away from the spec. See 1.4