|
a/src/index/indexer.h |
|
b/src/index/indexer.h |
|
... |
|
... |
27 |
using std::list;
|
27 |
using std::list;
|
28 |
using std::map;
|
28 |
using std::map;
|
29 |
#endif
|
29 |
#endif
|
30 |
|
30 |
|
31 |
#include "rclconfig.h"
|
31 |
#include "rclconfig.h"
|
32 |
#include "fstreewalk.h"
|
32 |
#include "fsindexer.h"
|
33 |
#include "rcldb.h"
|
|
|
34 |
|
33 |
|
35 |
/* Forward decl for lower level indexing object */
|
34 |
/* Forward decl for lower level indexing object */
|
36 |
class DbIndexer;
|
35 |
class DbIndexer;
|
37 |
|
36 |
|
38 |
class DbIxStatus {
|
37 |
class DbIxStatus {
|
|
... |
|
... |
69 |
*/
|
68 |
*/
|
70 |
class ConfIndexer {
|
69 |
class ConfIndexer {
|
71 |
public:
|
70 |
public:
|
72 |
enum runStatus {IndexerOk, IndexerError};
|
71 |
enum runStatus {IndexerOk, IndexerError};
|
73 |
ConfIndexer(RclConfig *cnf, DbIxStatusUpdater *updfunc = 0)
|
72 |
ConfIndexer(RclConfig *cnf, DbIxStatusUpdater *updfunc = 0)
|
74 |
: m_config(cnf), m_dbindexer(0), m_updater(updfunc)
|
73 |
: m_config(cnf), m_fsindexer(0), m_updater(updfunc)
|
75 |
{}
|
74 |
{}
|
76 |
virtual ~ConfIndexer();
|
75 |
virtual ~ConfIndexer();
|
77 |
/** Worker function: doe the actual indexing */
|
76 |
/** Worker function: doe the actual indexing */
|
78 |
bool index(bool resetbefore = false);
|
77 |
bool index(bool resetbefore = false);
|
79 |
const string &getReason() {return m_reason;}
|
78 |
const string &getReason() {return m_reason;}
|
80 |
private:
|
79 |
private:
|
81 |
RclConfig *m_config;
|
80 |
RclConfig *m_config;
|
82 |
DbIndexer *m_dbindexer; // Object to process directories for a given db
|
81 |
FsIndexer *m_fsindexer; // Object to process directories for a given db
|
83 |
DbIxStatusUpdater *m_updater;
|
82 |
DbIxStatusUpdater *m_updater;
|
84 |
string m_reason;
|
83 |
string m_reason;
|
85 |
};
|
84 |
};
|
86 |
|
85 |
|
87 |
/** Index things into one database
|
|
|
88 |
|
|
|
89 |
Tree indexing: we inherits FsTreeWalkerCB so that, the processone()
|
|
|
90 |
method is called by the file-system tree walk code for each file and
|
|
|
91 |
directory. We keep all state needed while indexing, and finally call
|
|
|
92 |
the methods to purge the db of stale entries and create the stemming
|
|
|
93 |
databases.
|
|
|
94 |
|
|
|
95 |
Single file(s) indexing: no database purging or stem db updating.
|
|
|
96 |
*/
|
|
|
97 |
class DbIndexer : public FsTreeWalkerCB {
|
|
|
98 |
public:
|
|
|
99 |
/** Constructor does nothing but store parameters
|
|
|
100 |
*
|
|
|
101 |
* @param cnf Configuration data
|
|
|
102 |
* @param updfunc Status updater callback
|
|
|
103 |
*/
|
|
|
104 |
DbIndexer(RclConfig *cnf, DbIxStatusUpdater *updfunc = 0)
|
|
|
105 |
: m_config(cnf), m_db(cnf), m_updater(updfunc)
|
|
|
106 |
{
|
|
|
107 |
m_havelocalfields = m_config->hasNameAnywhere("localfields");
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
virtual ~DbIndexer();
|
|
|
111 |
|
|
|
112 |
/** Top level file system tree index method for updating a
|
|
|
113 |
given database.
|
|
|
114 |
|
|
|
115 |
The list is supposed to have all the filename space for the
|
|
|
116 |
db, and we shall purge entries for non-existing files at the
|
|
|
117 |
end. We create the temporary directory, open the database,
|
|
|
118 |
then call a file system walk for each top-level directory.
|
|
|
119 |
When walking is done, we create the stem databases and close
|
|
|
120 |
the main db.
|
|
|
121 |
*/
|
|
|
122 |
bool indexDb(bool resetbefore, std::list<string> *topdirs);
|
|
|
123 |
|
|
|
124 |
/** Index a list of files. No db cleaning or stemdb updating */
|
|
|
125 |
bool indexFiles(const std::list<string> &files);
|
|
|
126 |
|
|
|
127 |
/** Purge a list of files. */
|
|
|
128 |
bool purgeFiles(const std::list<string> &files);
|
|
|
129 |
|
|
|
130 |
/** Stemming reset to config: create needed, delete unconfigured */
|
|
|
131 |
bool createStemmingDatabases();
|
|
|
132 |
|
|
|
133 |
/** Create stem database for given language */
|
|
|
134 |
bool createStemDb(const string &lang);
|
|
|
135 |
|
|
|
136 |
/** Create misspelling expansion dictionary if aspell i/f is available */
|
|
|
137 |
bool createAspellDict();
|
|
|
138 |
|
|
|
139 |
/** Tree walker callback method */
|
|
|
140 |
FsTreeWalker::Status
|
|
|
141 |
processone(const string &, const struct stat *, FsTreeWalker::CbFlag);
|
|
|
142 |
|
|
|
143 |
/** Return my db dir */
|
|
|
144 |
string getDbDir() {return m_config->getDbDir();}
|
|
|
145 |
|
|
|
146 |
/** List possible stemmer names */
|
|
|
147 |
static list<string> getStemmerNames();
|
|
|
148 |
|
|
|
149 |
private:
|
|
|
150 |
FsTreeWalker m_walker;
|
|
|
151 |
RclConfig *m_config;
|
|
|
152 |
Rcl::Db m_db;
|
|
|
153 |
string m_tmpdir;
|
|
|
154 |
DbIxStatusUpdater *m_updater;
|
|
|
155 |
|
|
|
156 |
// The configuration can set attribute fields to be inherited by
|
|
|
157 |
// all files in a file system area. Ie: set "apptag = thunderbird"
|
|
|
158 |
// inside ~/.thunderbird. The boolean is set at init to avoid
|
|
|
159 |
// further wasteful processing if no local fields are set.
|
|
|
160 |
bool m_havelocalfields;
|
|
|
161 |
map<string, string> m_localfields;
|
|
|
162 |
|
|
|
163 |
bool init(bool rst = false, bool rdonly = false);
|
|
|
164 |
void localfieldsfromconf();
|
|
|
165 |
void setlocalfields(Rcl::Doc& doc);
|
|
|
166 |
};
|
|
|
167 |
|
|
|
168 |
/** Helper methods in recollindex.cpp for initial checks/setup to index
|
|
|
169 |
* a list of files (either from the monitor or the command line) */
|
|
|
170 |
extern bool indexfiles(RclConfig *config, const list<string> &filenames);
|
|
|
171 |
extern bool purgefiles(RclConfig *config, const list<string> &filenames);
|
|
|
172 |
extern bool createAuxDbs(RclConfig *config);
|
|
|
173 |
|
|
|
174 |
#endif /* _INDEXER_H_INCLUDED_ */
|
86 |
#endif /* _INDEXER_H_INCLUDED_ */
|