add option to rezero db before index
This commit is contained in:
parent
80ae403a15
commit
f773eff0b1
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: indexer.cpp,v 1.18 2005-11-25 09:13:39 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: indexer.cpp,v 1.19 2005-11-30 09:46:25 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
@ -63,7 +63,7 @@ class DbIndexer : public FsTreeWalkerCB {
|
||||
}
|
||||
|
||||
/// Start indexing.
|
||||
bool index();
|
||||
bool index(bool resetbefore);
|
||||
|
||||
/// Tree walker callback method
|
||||
FsTreeWalker::Status
|
||||
@ -77,7 +77,7 @@ class DbIndexer : public FsTreeWalkerCB {
|
||||
/// file system walk for each top-level directory.
|
||||
/// When walking is done, we create the stem databases and close the
|
||||
/// main db.
|
||||
bool DbIndexer::index()
|
||||
bool DbIndexer::index(bool resetbefore)
|
||||
{
|
||||
string tdir;
|
||||
|
||||
@ -85,7 +85,7 @@ bool DbIndexer::index()
|
||||
LOGERR(("DbIndexer: cant create temp directory\n"));
|
||||
return false;
|
||||
}
|
||||
if (!db.open(dbdir, Rcl::Db::DbUpd)) {
|
||||
if (!db.open(dbdir, resetbefore ? Rcl::Db::DbTrunc : Rcl::Db::DbUpd)) {
|
||||
LOGERR(("DbIndexer::index: error opening database in %s\n",
|
||||
dbdir.c_str()));
|
||||
return false;
|
||||
@ -215,7 +215,7 @@ ConfIndexer::~ConfIndexer()
|
||||
deleteZ(dbindexer);
|
||||
}
|
||||
|
||||
bool ConfIndexer::index()
|
||||
bool ConfIndexer::index(bool resetbefore)
|
||||
{
|
||||
// Retrieve the list of directories to be indexed.
|
||||
string topdirs;
|
||||
@ -237,22 +237,22 @@ bool ConfIndexer::index()
|
||||
map<string, list<string> > dbmap;
|
||||
map<string, list<string> >::iterator dbit;
|
||||
for (dirit = tdl.begin(); dirit != tdl.end(); dirit++) {
|
||||
string db;
|
||||
string dir = path_tildexpand(*dirit);
|
||||
config->setKeyDir(dir);
|
||||
if (!config->getConfParam("dbdir", db)) {
|
||||
string dbdir;
|
||||
string doctopdir = path_tildexpand(*dirit);
|
||||
config->setKeyDir(doctopdir);
|
||||
if (!config->getConfParam("dbdir", dbdir)) {
|
||||
LOGERR(("ConfIndexer::index: no database directory in "
|
||||
"configuration for %s\n", dir.c_str()));
|
||||
"configuration for %s\n", doctopdir.c_str()));
|
||||
return false;
|
||||
}
|
||||
db = path_tildexpand(db);
|
||||
dbit = dbmap.find(db);
|
||||
dbdir = path_tildexpand(dbdir);
|
||||
dbit = dbmap.find(dbdir);
|
||||
if (dbit == dbmap.end()) {
|
||||
list<string> l;
|
||||
l.push_back(dir);
|
||||
dbmap[db] = l;
|
||||
l.push_back(doctopdir);
|
||||
dbmap[dbdir] = l;
|
||||
} else {
|
||||
dbit->second.push_back(dir);
|
||||
dbit->second.push_back(doctopdir);
|
||||
}
|
||||
}
|
||||
config->setKeyDir("");
|
||||
@ -265,9 +265,8 @@ bool ConfIndexer::index()
|
||||
// cout << *dit << " ";
|
||||
//}
|
||||
//cout << endl;
|
||||
|
||||
dbindexer = new DbIndexer(config, dbit->first, &dbit->second);
|
||||
if (!dbindexer->index()) {
|
||||
if (!dbindexer->index(resetbefore)) {
|
||||
deleteZ(dbindexer);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#ifndef _INDEXER_H_INCLUDED_
|
||||
#define _INDEXER_H_INCLUDED_
|
||||
/* @(#$Id: indexer.h,v 1.6 2005-11-10 08:47:49 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: indexer.h,v 1.7 2005-11-30 09:46:25 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include "rclconfig.h"
|
||||
|
||||
@ -26,7 +26,7 @@ class ConfIndexer {
|
||||
ConfIndexer(RclConfig *cnf) : config(cnf), dbindexer(0) {}
|
||||
virtual ~ConfIndexer();
|
||||
/** Worker function: doe the actual indexing */
|
||||
bool index();
|
||||
bool index(bool resetbefore = false);
|
||||
};
|
||||
|
||||
#endif /* _INDEXER_H_INCLUDED_ */
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: recollindex.cpp,v 1.11 2005-11-05 14:40:50 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: recollindex.cpp,v 1.12 2005-11-30 09:46:25 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
@ -24,8 +24,46 @@ static void sigcleanup(int sig)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static const char *thisprog;
|
||||
static int op_flags;
|
||||
#define OPT_MOINS 0x1
|
||||
#define OPT_z 0x2
|
||||
#define OPT_h 0x4
|
||||
|
||||
static const char usage [] =
|
||||
" recollindex [-hz]\n"
|
||||
"Options:\n"
|
||||
" -h : print this message\n"
|
||||
" -z : reset database before starting indexation\n\n"
|
||||
;
|
||||
|
||||
static void
|
||||
Usage(void)
|
||||
{
|
||||
FILE *fp = (op_flags & OPT_h) ? stdout : stderr;
|
||||
fprintf(fp, "%s: usage: %s", thisprog, usage);
|
||||
exit((op_flags & OPT_h)==0);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
thisprog = argv[0];
|
||||
argc--; argv++;
|
||||
|
||||
while (argc > 0 && **argv == '-') {
|
||||
(*argv)++;
|
||||
if (!(**argv))
|
||||
Usage();
|
||||
while (**argv)
|
||||
switch (*(*argv)++) {
|
||||
case 'z': op_flags |= OPT_z; break;
|
||||
case 'h': op_flags |= OPT_h; break;
|
||||
default: Usage(); break;
|
||||
}
|
||||
}
|
||||
if (op_flags & OPT_h)
|
||||
Usage();
|
||||
string reason;
|
||||
RclConfig *config = recollinit(cleanup, sigcleanup, reason);
|
||||
|
||||
@ -35,7 +73,8 @@ int main(int argc, const char **argv)
|
||||
fprintf(stderr, "%s\n", str.c_str());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
indexer = new ConfIndexer(config);
|
||||
|
||||
exit(!indexer->index());
|
||||
exit(!indexer->index((op_flags & OPT_z) != 0));
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.41 2005-11-25 09:12:25 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.42 2005-11-30 09:46:25 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
@ -101,16 +101,18 @@ bool Rcl::Db::open(const string& dir, OpenMode mode)
|
||||
try {
|
||||
switch (mode) {
|
||||
case DbUpd:
|
||||
ndb->wdb =
|
||||
Xapian::WritableDatabase(dir, Xapian::DB_CREATE_OR_OPEN);
|
||||
LOGDEB(("Rcl::Db::open: lastdocid: %d\n",
|
||||
ndb->wdb.get_lastdocid()));
|
||||
ndb->updated.resize(ndb->wdb.get_lastdocid() + 1);
|
||||
for (unsigned int i = 0; i < ndb->updated.size(); i++)
|
||||
ndb->updated[i] = false;
|
||||
ndb->iswritable = true;
|
||||
break;
|
||||
case DbTrunc:
|
||||
case DbTrunc:
|
||||
{
|
||||
int action = (mode == DbUpd) ? Xapian::DB_CREATE_OR_OPEN :
|
||||
Xapian::DB_CREATE_OR_OVERWRITE;
|
||||
ndb->wdb = Xapian::WritableDatabase(dir, action);
|
||||
LOGDEB(("Rcl::Db::open: lastdocid: %d\n",
|
||||
ndb->wdb.get_lastdocid()));
|
||||
ndb->updated.resize(ndb->wdb.get_lastdocid() + 1);
|
||||
for (unsigned int i = 0; i < ndb->updated.size(); i++)
|
||||
ndb->updated[i] = false;
|
||||
ndb->iswritable = true;
|
||||
}
|
||||
break;
|
||||
case DbRO:
|
||||
default:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user