Switch to unified view

a/src/rcldb/searchdata.h b/src/rcldb/searchdata.h
1
#ifndef _SEARCHDATA_H_INCLUDED_
1
#ifndef _SEARCHDATA_H_INCLUDED_
2
#define _SEARCHDATA_H_INCLUDED_
2
#define _SEARCHDATA_H_INCLUDED_
3
/* @(#$Id: searchdata.h,v 1.2 2006-04-22 06:27:37 dockes Exp $  (C) 2004 J.F.Dockes */
3
/* @(#$Id: searchdata.h,v 1.3 2006-11-13 08:49:45 dockes Exp $  (C) 2004 J.F.Dockes */
4
5
#include <string>
6
#include <list>
7
8
#include "rcldb.h"
9
10
#ifndef NO_NAMESPACES
11
using std::list;
12
using std::string;
13
#endif
4
14
5
namespace Rcl {
15
namespace Rcl {
6
/**
16
7
 * Holder for query data 
17
/** Search clause types */
8
 */
18
enum SClType {
9
class AdvSearchData {
19
    SCLT_AND, 
10
    public:
20
    SCLT_OR, SCLT_EXCL, SCLT_FILENAME, SCLT_PHRASE, SCLT_NEAR,
11
    string allwords;
21
    SCLT_SUB
12
    string phrase;
13
    string orwords;
14
    string orwords1; // Have two instances of orwords for and'ing them
15
    string nowords;
16
    string filename; 
17
    list<string> filetypes; // restrict to types. Empty if inactive
18
    string topdir; // restrict to subtree. Empty if inactive
19
    string description; // Printable expanded version of the complete query
20
                        // returned after setQuery.
21
    void erase() {
22
  allwords.erase();
23
  phrase.erase();
24
  orwords.erase();
25
  orwords1.erase();
26
  nowords.erase();
27
  filetypes.clear(); 
28
  topdir.erase();
29
  filename.erase();
30
  description.erase();
31
    }
32
    bool fileNameOnly() {
33
  return allwords.empty() && phrase.empty() && orwords.empty() && 
34
      orwords1.empty() && nowords.empty();
35
    }
36
};
22
};
37
23
38
}
24
class SearchDataClause;
39
25
26
/** 
27
 * Holder for a list of search clauses. Some of the clauses can be comples
28
 * subqueries.
29
 */
30
class SearchData {
31
 public:
32
    SClType                  m_tp; // Only SCLT_AND or SCLT_OR here
33
    list<SearchDataClause *> m_query;
34
    list<string>             m_filetypes; // Restrict to filetypes if set.
35
    string                   m_topdir; // Restrict to subtree.
36
    // Printable expanded version of the complete query, obtained from Xapian
37
    // valid after setQuery() call
38
    string m_description; 
39
40
    SearchData(SClType tp) : m_tp(tp) {}
41
    ~SearchData() {erase();}
42
43
    /** Make pristine */
44
    void erase();
45
46
    /** Is there anything but a file name search in here ? */
47
    bool fileNameOnly();
48
49
    /** Translate to Xapian query. rcldb knows about the void*  */
50
    bool toNativeQuery(Rcl::Db &db, void *, const string& stemlang);
51
52
    /** We become the owner of cl and will delete it */
53
    bool addClause(SearchDataClause *cl);
54
55
 private:
56
    /* Copyconst and assignment private and forbidden */
57
    SearchData(const SearchData &) {}
58
    SearchData& operator=(const SearchData&) {return *this;};
59
};
60
61
class SearchDataClause {
62
 public:
63
    SClType m_tp;
64
65
    SearchDataClause(SClType tp) : m_tp(tp) {}
66
    virtual ~SearchDataClause() {}
67
    virtual bool toNativeQuery(Rcl::Db &db, void *, const string&) = 0;
68
    virtual bool isFileName() {return m_tp == SCLT_FILENAME ? true : false;}
69
};
70
71
class SearchDataClauseSimple : public SearchDataClause {
72
public:
73
    SearchDataClauseSimple(SClType tp, string txt)
74
  : SearchDataClause(tp), m_text(txt) {}
75
    virtual ~SearchDataClauseSimple() {}
76
    virtual bool toNativeQuery(Rcl::Db &db, void *, const string& stemlang);
77
protected:
78
    string  m_text;
79
};
80
81
class SearchDataClauseFilename : public SearchDataClauseSimple {
82
 public:
83
    SearchDataClauseFilename(string txt)
84
  : SearchDataClauseSimple(SCLT_FILENAME, m_text) {}
85
    virtual ~SearchDataClauseFilename() {}
86
    virtual bool toNativeQuery(Rcl::Db &db, void *, const string& stemlang);
87
};
88
89
class SearchDataClauseDist : public SearchDataClauseSimple {
90
public:
91
    SearchDataClauseDist(SClType tp, string txt, int dist) 
92
  : SearchDataClauseSimple(tp, txt), m_distance(dist) {}
93
    virtual ~SearchDataClauseDist() {}
94
    virtual bool toNativeQuery(Rcl::Db &db, void *, const string& stemlang);
95
96
protected:
97
    int     m_distance;
98
};
99
100
class SearchDataClauseSub : public SearchDataClause {
101
 public:
102
    SearchDataClauseSub(SClType tp, SClType stp) 
103
  : SearchDataClause(tp), m_sub(stp) {}
104
    virtual ~SearchDataClauseSub() {}
105
    virtual bool toNativeQuery(Rcl::Db &db, void *, const string& stemlang);
106
107
protected:
108
    SearchData m_sub;
109
};
110
111
} // Namespace Rcl
40
#endif /* _SEARCHDATA_H_INCLUDED_ */
112
#endif /* _SEARCHDATA_H_INCLUDED_ */