Switch to unified view

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.4 2007-01-17 13:53:41 dockes Exp $  (C) 2006 J.F.Dockes */
3
/* @(#$Id: wasastringtoquery.h,v 1.5 2007-02-12 18:16:08 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.
...
...
23
23
24
using std::string;
24
using std::string;
25
using std::vector;
25
using std::vector;
26
26
27
/** 
27
/** 
28
 * A simple class to represent a parsed wasabiSimple query
28
 * A simple class to represent a parsed wasabiSimple query element. 
29
 * string. Can hold a string value or an array of subqueries.
29
 * Can hold a string value or an array of subqueries.
30
 * The value can hold one or several words. In the latter case, it should 
30
 *
31
 * be interpreted as a phrase (comes from a user-entered "quoted string").
31
 * The complete query is represented by a top WasaQuery holding a
32
 * 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
34
 * negated (AND NOT).
35
 *
36
 * 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
38
 * user-entered "quoted string").
32
 */
39
 */
33
class WasaQuery {
40
class WasaQuery {
34
public:
41
public:
35
    enum Op {OP_NULL, OP_LEAF, OP_EXCL, OP_OR, OP_AND};
42
    enum Op {OP_NULL, OP_LEAF, OP_EXCL, OP_OR, OP_AND};
36
    typedef vector<WasaQuery*> subqlist_t;
43
    typedef vector<WasaQuery*> subqlist_t;
37
44
38
    WasaQuery() 
45
    WasaQuery() 
39
  : m_op(OP_NULL), m_typeKind(WQTK_NONE)
46
  : m_op(OP_NULL), m_modifiers(0)
40
    {}
47
    {}
48
41
    ~WasaQuery();
49
    ~WasaQuery();
42
50
43
    /** Get string describing the query tree from this point */
51
    /** Get string describing the query tree from this point */
44
    void describe(string &desc) const;
52
    void describe(string &desc) const;
45
53
46
    /** Op to be performed on either value or subqueries */
54
    /** Op to be performed on either value (may be LEAF or EXCL, or subqs */
47
    WasaQuery::Op      m_op;
55
    WasaQuery::Op      m_op;
48
56
49
    /** Field specification if any (ie: title, author ...) */
57
    /** Field specification if any (ie: title, author ...) */
50
    string             m_fieldspec;
58
    string             m_fieldspec;
51
59
52
    /* String value. Valid for op == OP_LEAF */
60
    /* String value. Valid for op == OP_LEAF or EXCL */
53
    string             m_value;
61
    string             m_value;
54
62
55
    /** Subqueries. Valid for conjunctions */
63
    /** Subqueries. Valid for conjunctions */
56
    vector<WasaQuery*> m_subs;
64
    vector<WasaQuery*> m_subs;
57
    
65
    
58
    /** Restrict results to some file type, defined by either mime,
66
    /** Modifiers for term handling: case/diacritics handling,
59
     *  app group, or extension */
67
  stemming control */
60
    enum TypeKind {WQTK_NONE, WQTK_MIME, WQTK_GROUP, WQTK_EXT};
68
    enum Modifier {WQM_CASESENS = 1, WQM_DIACSENS = 2, WQM_NOSTEM = 4, 
61
    TypeKind           m_typeKind;
69
         WQM_BOOST = 8, WQM_PROX = 0x10, WQM_SLOPPY = 0x20, 
62
    vector<string>     m_types;
70
         WQM_WORDS = 0x40, WQM_PHRASESLACK = 0x80, WQM_REGEX = 0x100,
63
71
         WQM_FUZZY = 0x200};
64
    /** Sort on relevance, date, name or group */
72
    unsigned int       m_modifiers;
65
    enum SortKind {WQSK_REL, WQSK_DATE, WQSK_ALPHA, WQSK_GROUP};
66
    vector<SortKind>   m_sortSpec;
67
};
73
};
68
74
69
/**
75
/**
70
 * Wasabi query string parser class. Could be a simple function
76
 * Wasabi query string parser class. Could be a simple function
71
 * really, but there might be some parser initialization work done in
77
 * really, but there might be some parser initialization work done in