Parent: [57cdec] (diff)

Child: [7cc20a] (diff)

Download this file

searchdata.h    113 lines (90 with data), 3.2 kB

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