|
a |
|
b/src/index/fsindexer.h |
|
|
1 |
/*
|
|
|
2 |
* This program is free software; you can redistribute it and/or modify
|
|
|
3 |
* it under the terms of the GNU General Public License as published by
|
|
|
4 |
* the Free Software Foundation; either version 2 of the License, or
|
|
|
5 |
* (at your option) any later version.
|
|
|
6 |
*
|
|
|
7 |
* This program is distributed in the hope that it will be useful,
|
|
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
10 |
* GNU General Public License for more details.
|
|
|
11 |
*
|
|
|
12 |
* You should have received a copy of the GNU General Public License
|
|
|
13 |
* along with this program; if not, write to the
|
|
|
14 |
* Free Software Foundation, Inc.,
|
|
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
16 |
*/
|
|
|
17 |
#ifndef _fsindexer_h_included_
|
|
|
18 |
#define _fsindexer_h_included_
|
|
|
19 |
/* @(#$Id: $ (C) 2009 J.F.Dockes */
|
|
|
20 |
|
|
|
21 |
#include "fstreewalk.h"
|
|
|
22 |
#include "rcldb.h"
|
|
|
23 |
|
|
|
24 |
class DbIxStatusUpdater;
|
|
|
25 |
|
|
|
26 |
/** Index selected parts of the file system
|
|
|
27 |
|
|
|
28 |
Tree indexing: we inherits FsTreeWalkerCB so that, the processone()
|
|
|
29 |
method is called by the file-system tree walk code for each file and
|
|
|
30 |
directory. We keep all state needed while indexing, and finally call
|
|
|
31 |
the methods to purge the db of stale entries and create the stemming
|
|
|
32 |
databases.
|
|
|
33 |
|
|
|
34 |
Single file(s) indexing: there are also calls to index or purge lists of files.
|
|
|
35 |
No database purging or stem db updating in this case.
|
|
|
36 |
*/
|
|
|
37 |
class FsIndexer : public FsTreeWalkerCB {
|
|
|
38 |
public:
|
|
|
39 |
/** Constructor does nothing but store parameters
|
|
|
40 |
*
|
|
|
41 |
* @param cnf Configuration data
|
|
|
42 |
* @param updfunc Status updater callback
|
|
|
43 |
*/
|
|
|
44 |
FsIndexer(RclConfig *cnf, DbIxStatusUpdater *updfunc = 0)
|
|
|
45 |
: m_config(cnf), m_db(cnf), m_updater(updfunc)
|
|
|
46 |
{
|
|
|
47 |
m_havelocalfields = m_config->hasNameAnywhere("localfields");
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
virtual ~FsIndexer();
|
|
|
51 |
|
|
|
52 |
/** Top level file system tree index method for updating a
|
|
|
53 |
given database.
|
|
|
54 |
|
|
|
55 |
The list is supposed to have all the filename space for the
|
|
|
56 |
db, and we shall purge entries for non-existing files at the
|
|
|
57 |
end. We create the temporary directory, open the database,
|
|
|
58 |
then call a file system walk for each top-level directory.
|
|
|
59 |
When walking is done, we create the stem databases and close
|
|
|
60 |
the main db.
|
|
|
61 |
*/
|
|
|
62 |
bool indexTrees(bool resetbefore, std::list<string> *topdirs);
|
|
|
63 |
|
|
|
64 |
/** Index a list of files. No db cleaning or stemdb updating */
|
|
|
65 |
bool indexFiles(const std::list<string> &files);
|
|
|
66 |
|
|
|
67 |
/** Purge a list of files. */
|
|
|
68 |
bool purgeFiles(const std::list<string> &files);
|
|
|
69 |
|
|
|
70 |
/** Stemming reset to config: create needed, delete unconfigured */
|
|
|
71 |
bool createStemmingDatabases();
|
|
|
72 |
|
|
|
73 |
/** Create stem database for given language */
|
|
|
74 |
bool createStemDb(const string &lang);
|
|
|
75 |
|
|
|
76 |
/** Create misspelling expansion dictionary if aspell i/f is available */
|
|
|
77 |
bool createAspellDict();
|
|
|
78 |
|
|
|
79 |
/** Tree walker callback method */
|
|
|
80 |
FsTreeWalker::Status
|
|
|
81 |
processone(const string &, const struct stat *, FsTreeWalker::CbFlag);
|
|
|
82 |
|
|
|
83 |
/** Return my db dir */
|
|
|
84 |
string getDbDir() {return m_config->getDbDir();}
|
|
|
85 |
|
|
|
86 |
/** List possible stemmer names */
|
|
|
87 |
static list<string> getStemmerNames();
|
|
|
88 |
|
|
|
89 |
private:
|
|
|
90 |
FsTreeWalker m_walker;
|
|
|
91 |
RclConfig *m_config;
|
|
|
92 |
Rcl::Db m_db;
|
|
|
93 |
string m_tmpdir;
|
|
|
94 |
DbIxStatusUpdater *m_updater;
|
|
|
95 |
|
|
|
96 |
// The configuration can set attribute fields to be inherited by
|
|
|
97 |
// all files in a file system area. Ie: set "apptag = thunderbird"
|
|
|
98 |
// inside ~/.thunderbird. The boolean is set at init to avoid
|
|
|
99 |
// further wasteful processing if no local fields are set.
|
|
|
100 |
bool m_havelocalfields;
|
|
|
101 |
map<string, string> m_localfields;
|
|
|
102 |
|
|
|
103 |
bool init(bool rst = false, bool rdonly = false);
|
|
|
104 |
void localfieldsfromconf();
|
|
|
105 |
void setlocalfields(Rcl::Doc& doc);
|
|
|
106 |
};
|
|
|
107 |
|
|
|
108 |
#endif /* _fsindexer_h_included_ */
|