|
a/src/query/wasastringtoquery.h |
|
b/src/query/wasastringtoquery.h |
1 |
#ifndef _WASASTRINGTOQUERY_H_INCLUDED_
|
1 |
#ifndef _WASASTRINGTOQUERY_H_INCLUDED_
|
2 |
#define _WASASTRINGTOQUERY_H_INCLUDED_
|
2 |
#define _WASASTRINGTOQUERY_H_INCLUDED_
|
3 |
/* @(#$Id: wasastringtoquery.h,v 1.6 2008-01-17 11:14:13 dockes Exp $ (C) 2006 J.F.Dockes */
|
3 |
/* @(#$Id: wasastringtoquery.h,v 1.7 2008-08-26 13:47:21 dockes Exp $ (C) 2006 J.F.Dockes */
|
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
|
8 |
* (at your option) any later version.
|
8 |
* (at your option) any later version.
|
|
... |
|
... |
21 |
#include <string>
|
21 |
#include <string>
|
22 |
#include <vector>
|
22 |
#include <vector>
|
23 |
|
23 |
|
24 |
using std::string;
|
24 |
using std::string;
|
25 |
using std::vector;
|
25 |
using std::vector;
|
|
|
26 |
/* Note: Xesam used to be named wasabi. We changed the references to wasabi in
|
|
|
27 |
the comments, but not the code */
|
26 |
|
28 |
|
27 |
/**
|
29 |
/**
|
28 |
* A simple class to represent a parsed wasabiSimple query element.
|
30 |
* A simple class to represent a parsed Xesam user language element.
|
29 |
* Can hold a string value or an array of subqueries.
|
31 |
* Can hold one leaf element or an array of subqueries to be joined by AND/OR
|
30 |
*
|
32 |
*
|
31 |
* The complete query is represented by a top WasaQuery holding a
|
33 |
* The complete query is represented by a top WasaQuery holding a
|
32 |
* chain of ANDed subclauses. Some of the subclauses may be themselves
|
34 |
* chain of ANDed subclauses. Some of the subclauses may be themselves
|
33 |
* OR'ed lists (it doesn't go deeper). Entries in the AND list may be
|
35 |
* OR'ed lists (it doesn't go deeper). Entries in the AND list may be
|
34 |
* negated (AND NOT).
|
36 |
* negated (AND NOT).
|
35 |
*
|
37 |
*
|
36 |
* For LEAF elements, the value can hold one or several words. In the
|
38 |
* For LEAF elements, the value can hold one or several words. In the
|
37 |
* latter case, it should be interpreted as a phrase (comes from a
|
39 |
* latter case, it should be interpreted as a phrase (comes from a
|
38 |
* user-entered "quoted string").
|
40 |
* user-entered "quoted string"), except if the modifier flags say otherwise.
|
39 |
*
|
41 |
*
|
40 |
* Some fields only make sense either for compound or LEAF queries. This
|
42 |
* Some fields only make sense either for compound or LEAF queries. This
|
41 |
* is commented for each. We should subclass really.
|
43 |
* is commented for each. We should subclass really.
|
|
|
44 |
*
|
|
|
45 |
* Note that wasaStringToQuery supposedly parses the whole Xesam
|
|
|
46 |
* User Search Language v 0.95, but that some elements are dropped or
|
|
|
47 |
* ignored during the translation to a native Recoll query in wasaToRcl
|
42 |
*/
|
48 |
*/
|
43 |
class WasaQuery {
|
49 |
class WasaQuery {
|
44 |
public:
|
50 |
public:
|
|
|
51 |
/** Type of this element: leaf or AND/OR chain */
|
45 |
enum Op {OP_NULL, OP_LEAF, OP_EXCL, OP_OR, OP_AND};
|
52 |
enum Op {OP_NULL, OP_LEAF, OP_EXCL, OP_OR, OP_AND};
|
|
|
53 |
/** Relation to be searched between field and value. Recoll actually only
|
|
|
54 |
supports "contain" */
|
|
|
55 |
enum Rel {REL_NULL, REL_EQUALS, REL_CONTAINS, REL_LT, REL_LTE,
|
|
|
56 |
REL_GT, REL_GTE};
|
|
|
57 |
/** Modifiers for term handling: case/diacritics handling,
|
|
|
58 |
stemming control */
|
|
|
59 |
enum Modifier {WQM_CASESENS = 1, WQM_DIACSENS = 2, WQM_NOSTEM = 4,
|
|
|
60 |
WQM_BOOST = 8, WQM_PROX = 0x10, WQM_SLOPPY = 0x20,
|
|
|
61 |
WQM_WORDS = 0x40, WQM_PHRASESLACK = 0x80, WQM_REGEX = 0x100,
|
|
|
62 |
WQM_FUZZY = 0x200};
|
|
|
63 |
|
46 |
typedef vector<WasaQuery*> subqlist_t;
|
64 |
typedef vector<WasaQuery*> subqlist_t;
|
47 |
|
65 |
|
48 |
WasaQuery()
|
66 |
WasaQuery()
|
49 |
: m_op(OP_NULL), m_modifiers(0)
|
67 |
: m_op(OP_NULL), m_modifiers(0)
|
50 |
{}
|
68 |
{}
|
|
... |
|
... |
57 |
/** Op to be performed on either value (may be LEAF or EXCL, or subqs */
|
75 |
/** Op to be performed on either value (may be LEAF or EXCL, or subqs */
|
58 |
WasaQuery::Op m_op;
|
76 |
WasaQuery::Op m_op;
|
59 |
|
77 |
|
60 |
/** Field specification if any (ie: title, author ...) Only OPT_LEAF */
|
78 |
/** Field specification if any (ie: title, author ...) Only OPT_LEAF */
|
61 |
string m_fieldspec;
|
79 |
string m_fieldspec;
|
|
|
80 |
/** Relation between field and value: =, :, <,>,<=, >= */
|
|
|
81 |
WasaQuery::Rel m_rel;
|
62 |
|
82 |
|
63 |
/* String value. Valid for op == OP_LEAF or EXCL */
|
83 |
/* String value. Valid for op == OP_LEAF or EXCL */
|
64 |
string m_value;
|
84 |
string m_value;
|
65 |
|
85 |
|
66 |
/** Subqueries. Valid for conjunctions */
|
86 |
/** Subqueries. Valid for conjunctions */
|
67 |
vector<WasaQuery*> m_subs;
|
87 |
vector<WasaQuery*> m_subs;
|
68 |
|
88 |
|
69 |
/** Modifiers for term handling: case/diacritics handling,
|
|
|
70 |
stemming control */
|
|
|
71 |
enum Modifier {WQM_CASESENS = 1, WQM_DIACSENS = 2, WQM_NOSTEM = 4,
|
|
|
72 |
WQM_BOOST = 8, WQM_PROX = 0x10, WQM_SLOPPY = 0x20,
|
|
|
73 |
WQM_WORDS = 0x40, WQM_PHRASESLACK = 0x80, WQM_REGEX = 0x100,
|
|
|
74 |
WQM_FUZZY = 0x200};
|
|
|
75 |
unsigned int m_modifiers;
|
89 |
unsigned int m_modifiers;
|
76 |
};
|
90 |
};
|
77 |
|
91 |
|
78 |
/**
|
92 |
/**
|
79 |
* Wasabi query string parser class. Could be a simple function
|
93 |
* Wasabi query string parser class. Could be a simple function
|
80 |
* really, but there might be some parser initialization work done in
|
94 |
* really, but there might be some parser initialization work done in
|