add option to rezero db before index
This commit is contained in:
parent
80ae403a15
commit
f773eff0b1
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#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
|
#endif
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -63,7 +63,7 @@ class DbIndexer : public FsTreeWalkerCB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Start indexing.
|
/// Start indexing.
|
||||||
bool index();
|
bool index(bool resetbefore);
|
||||||
|
|
||||||
/// Tree walker callback method
|
/// Tree walker callback method
|
||||||
FsTreeWalker::Status
|
FsTreeWalker::Status
|
||||||
@ -77,7 +77,7 @@ class DbIndexer : public FsTreeWalkerCB {
|
|||||||
/// file system walk for each top-level directory.
|
/// file system walk for each top-level directory.
|
||||||
/// When walking is done, we create the stem databases and close the
|
/// When walking is done, we create the stem databases and close the
|
||||||
/// main db.
|
/// main db.
|
||||||
bool DbIndexer::index()
|
bool DbIndexer::index(bool resetbefore)
|
||||||
{
|
{
|
||||||
string tdir;
|
string tdir;
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ bool DbIndexer::index()
|
|||||||
LOGERR(("DbIndexer: cant create temp directory\n"));
|
LOGERR(("DbIndexer: cant create temp directory\n"));
|
||||||
return false;
|
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",
|
LOGERR(("DbIndexer::index: error opening database in %s\n",
|
||||||
dbdir.c_str()));
|
dbdir.c_str()));
|
||||||
return false;
|
return false;
|
||||||
@ -215,7 +215,7 @@ ConfIndexer::~ConfIndexer()
|
|||||||
deleteZ(dbindexer);
|
deleteZ(dbindexer);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfIndexer::index()
|
bool ConfIndexer::index(bool resetbefore)
|
||||||
{
|
{
|
||||||
// Retrieve the list of directories to be indexed.
|
// Retrieve the list of directories to be indexed.
|
||||||
string topdirs;
|
string topdirs;
|
||||||
@ -237,22 +237,22 @@ bool ConfIndexer::index()
|
|||||||
map<string, list<string> > dbmap;
|
map<string, list<string> > dbmap;
|
||||||
map<string, list<string> >::iterator dbit;
|
map<string, list<string> >::iterator dbit;
|
||||||
for (dirit = tdl.begin(); dirit != tdl.end(); dirit++) {
|
for (dirit = tdl.begin(); dirit != tdl.end(); dirit++) {
|
||||||
string db;
|
string dbdir;
|
||||||
string dir = path_tildexpand(*dirit);
|
string doctopdir = path_tildexpand(*dirit);
|
||||||
config->setKeyDir(dir);
|
config->setKeyDir(doctopdir);
|
||||||
if (!config->getConfParam("dbdir", db)) {
|
if (!config->getConfParam("dbdir", dbdir)) {
|
||||||
LOGERR(("ConfIndexer::index: no database directory in "
|
LOGERR(("ConfIndexer::index: no database directory in "
|
||||||
"configuration for %s\n", dir.c_str()));
|
"configuration for %s\n", doctopdir.c_str()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
db = path_tildexpand(db);
|
dbdir = path_tildexpand(dbdir);
|
||||||
dbit = dbmap.find(db);
|
dbit = dbmap.find(dbdir);
|
||||||
if (dbit == dbmap.end()) {
|
if (dbit == dbmap.end()) {
|
||||||
list<string> l;
|
list<string> l;
|
||||||
l.push_back(dir);
|
l.push_back(doctopdir);
|
||||||
dbmap[db] = l;
|
dbmap[dbdir] = l;
|
||||||
} else {
|
} else {
|
||||||
dbit->second.push_back(dir);
|
dbit->second.push_back(doctopdir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config->setKeyDir("");
|
config->setKeyDir("");
|
||||||
@ -265,9 +265,8 @@ bool ConfIndexer::index()
|
|||||||
// cout << *dit << " ";
|
// cout << *dit << " ";
|
||||||
//}
|
//}
|
||||||
//cout << endl;
|
//cout << endl;
|
||||||
|
|
||||||
dbindexer = new DbIndexer(config, dbit->first, &dbit->second);
|
dbindexer = new DbIndexer(config, dbit->first, &dbit->second);
|
||||||
if (!dbindexer->index()) {
|
if (!dbindexer->index(resetbefore)) {
|
||||||
deleteZ(dbindexer);
|
deleteZ(dbindexer);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#ifndef _INDEXER_H_INCLUDED_
|
#ifndef _INDEXER_H_INCLUDED_
|
||||||
#define _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"
|
#include "rclconfig.h"
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ class ConfIndexer {
|
|||||||
ConfIndexer(RclConfig *cnf) : config(cnf), dbindexer(0) {}
|
ConfIndexer(RclConfig *cnf) : config(cnf), dbindexer(0) {}
|
||||||
virtual ~ConfIndexer();
|
virtual ~ConfIndexer();
|
||||||
/** Worker function: doe the actual indexing */
|
/** Worker function: doe the actual indexing */
|
||||||
bool index();
|
bool index(bool resetbefore = false);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _INDEXER_H_INCLUDED_ */
|
#endif /* _INDEXER_H_INCLUDED_ */
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#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
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -24,8 +24,46 @@ static void sigcleanup(int sig)
|
|||||||
exit(1);
|
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)
|
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;
|
string reason;
|
||||||
RclConfig *config = recollinit(cleanup, sigcleanup, 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());
|
fprintf(stderr, "%s\n", str.c_str());
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
indexer = new ConfIndexer(config);
|
indexer = new ConfIndexer(config);
|
||||||
|
|
||||||
exit(!indexer->index());
|
exit(!indexer->index((op_flags & OPT_z) != 0));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#ifndef lint
|
#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
|
#endif
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -101,16 +101,18 @@ bool Rcl::Db::open(const string& dir, OpenMode mode)
|
|||||||
try {
|
try {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case DbUpd:
|
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;
|
break;
|
||||||
case DbRO:
|
case DbRO:
|
||||||
default:
|
default:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user