allow independant creation / deletion of stem dbs
This commit is contained in:
+24
-4
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: indexer.cpp,v 1.20 2005-12-14 11:00:48 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: indexer.cpp,v 1.21 2006-01-09 16:53:31 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -10,6 +10,7 @@ static char rcsid[] = "@(#$Id: indexer.cpp,v 1.20 2005-12-14 11:00:48 dockes Exp
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
|
||||
#include "pathut.h"
|
||||
#include "conftree.h"
|
||||
@@ -87,13 +88,22 @@ bool DbIndexer::indexDb(bool resetbefore, list<string> *topdirs)
|
||||
// filesystem anymore.
|
||||
db.purge();
|
||||
|
||||
// Create stemming databases
|
||||
// Create stemming databases. We also remove those which are not
|
||||
// configured.
|
||||
string slangs;
|
||||
if (config->getConfParam("indexstemminglanguages", slangs)) {
|
||||
list<string> langs;
|
||||
stringToStrings(slangs, langs);
|
||||
for (list<string>::const_iterator it = langs.begin();
|
||||
it != langs.end(); it++) {
|
||||
|
||||
// Get the list of existing stem dbs from the database (some may have
|
||||
// been manually created, we just keep those from the config
|
||||
list<string> dblangs = db.getStemLangs();
|
||||
list<string>::const_iterator it;
|
||||
for (it = dblangs.begin(); it != dblangs.end(); it++) {
|
||||
if (find(langs.begin(), langs.end(), *it) == langs.end())
|
||||
db.deleteStemDb(*it);
|
||||
}
|
||||
for (it = langs.begin(); it != langs.end(); it++) {
|
||||
db.createStemDb(*it);
|
||||
}
|
||||
}
|
||||
@@ -120,6 +130,16 @@ bool DbIndexer::init(bool resetbefore)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DbIndexer::createStemDb(const string &lang)
|
||||
{
|
||||
if (!init())
|
||||
return false;
|
||||
return db.createStemDb(lang);
|
||||
}
|
||||
|
||||
/**
|
||||
Index individual files, out of a full tree run. No database purging
|
||||
*/
|
||||
bool DbIndexer::indexFiles(const list<string> &filenames)
|
||||
{
|
||||
if (!init())
|
||||
|
||||
+14
-9
@@ -1,6 +1,6 @@
|
||||
#ifndef _INDEXER_H_INCLUDED_
|
||||
#define _INDEXER_H_INCLUDED_
|
||||
/* @(#$Id: indexer.h,v 1.8 2005-12-14 11:00:48 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: indexer.h,v 1.9 2006-01-09 16:53:31 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
@@ -24,10 +24,12 @@ class DbIndexer;
|
||||
class ConfIndexer {
|
||||
public:
|
||||
enum runStatus {IndexerOk, IndexerError};
|
||||
ConfIndexer(RclConfig *cnf) : config(cnf), dbindexer(0) {}
|
||||
virtual ~ConfIndexer();
|
||||
/** Worker function: doe the actual indexing */
|
||||
bool index(bool resetbefore = false);
|
||||
ConfIndexer(RclConfig *cnf) : config(cnf), dbindexer(0)
|
||||
{
|
||||
}
|
||||
virtual ~ConfIndexer();
|
||||
/** Worker function: doe the actual indexing */
|
||||
bool index(bool resetbefore = false);
|
||||
private:
|
||||
RclConfig *config;
|
||||
DbIndexer *dbindexer; // Object to process directories for a given db
|
||||
@@ -36,10 +38,10 @@ class ConfIndexer {
|
||||
/** Index things into one database
|
||||
|
||||
Tree indexing: we inherits FsTreeWalkerCB so that, the processone()
|
||||
method is called by the file-system tree walk code for each file and
|
||||
directory. We keep all state needed while indexing, and finally call
|
||||
the methods to purge the db of stale entries and create the stemming
|
||||
databases.
|
||||
method is called by the file-system tree walk code for each file and
|
||||
directory. We keep all state needed while indexing, and finally call
|
||||
the methods to purge the db of stale entries and create the stemming
|
||||
databases.
|
||||
|
||||
Single file(s) indexing: no database purging or stem db updating.
|
||||
*/
|
||||
@@ -67,6 +69,9 @@ class DbIndexer : public FsTreeWalkerCB {
|
||||
/** Index a list of files. No db cleaning or stemdb updating */
|
||||
bool indexFiles(const std::list<std::string> &files);
|
||||
|
||||
/** Create stem database for given language */
|
||||
bool createStemDb(const string &lang);
|
||||
|
||||
/** Tree walker callback method */
|
||||
FsTreeWalker::Status
|
||||
processone(const std::string &, const struct stat *,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: recollindex.cpp,v 1.13 2005-12-14 11:00:48 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: recollindex.cpp,v 1.14 2006-01-09 16:53:31 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -19,10 +19,12 @@ using namespace std;
|
||||
#include "pathut.h"
|
||||
|
||||
|
||||
// Globals for exit cleanup
|
||||
ConfIndexer *confindexer;
|
||||
DbIndexer *dbindexer;
|
||||
|
||||
bool indexfiles(RclConfig *config, const list<string> &filenames)
|
||||
// Index a list of files
|
||||
static bool indexfiles(RclConfig *config, const list<string> &filenames)
|
||||
{
|
||||
if (filenames.empty())
|
||||
return true;
|
||||
@@ -42,6 +44,21 @@ bool indexfiles(RclConfig *config, const list<string> &filenames)
|
||||
return dbindexer->indexFiles(filenames);
|
||||
}
|
||||
|
||||
// Create additional stem database
|
||||
static bool createstemdb(RclConfig *config, const string &lang)
|
||||
{
|
||||
// Note that we do not bother to check for multiple databases,
|
||||
// which are currently a fiction anyway.
|
||||
string dbdir;
|
||||
if (!config->getConfParam("dbdir", dbdir)) {
|
||||
LOGERR(("createstemdb: no database directory in configuration\n"));
|
||||
return false;
|
||||
}
|
||||
dbdir = path_tildexpand(dbdir);
|
||||
dbindexer = new DbIndexer(config, dbdir);
|
||||
return dbindexer->createStemDb(lang);
|
||||
}
|
||||
|
||||
static void cleanup()
|
||||
{
|
||||
delete confindexer;
|
||||
@@ -63,15 +80,19 @@ static int op_flags;
|
||||
#define OPT_z 0x2
|
||||
#define OPT_h 0x4
|
||||
#define OPT_i 0x8
|
||||
#define OPT_s 0x10
|
||||
|
||||
static const char usage [] =
|
||||
" recollindex [-hz] \n"
|
||||
" recollindex -i <filename [filename ...]>\n"
|
||||
"\n"
|
||||
"recollindex [-hz] \n"
|
||||
" Normal index run\n"
|
||||
"recollindex -i <filename [filename ...]>\n"
|
||||
" Index individual files. No db purge or stem database updates\n"
|
||||
"recollindex -s <lang>\n"
|
||||
" Build stem database for language <lang>\n"
|
||||
"Options:\n"
|
||||
" -h : print this message\n"
|
||||
" -z : reset database before starting indexation\n\n"
|
||||
" -i <filename [filename ...]> : index individual files. No db purge or stem\n"
|
||||
" database updates in this case\n"
|
||||
;
|
||||
|
||||
static void
|
||||
@@ -97,6 +118,7 @@ int main(int argc, const char **argv)
|
||||
case 'z': op_flags |= OPT_z; break;
|
||||
case 'h': op_flags |= OPT_h; break;
|
||||
case 'i': op_flags |= OPT_i; break;
|
||||
case 's': op_flags |= OPT_s; break;
|
||||
default: Usage(); break;
|
||||
}
|
||||
b1: argc--; argv++;
|
||||
@@ -108,7 +130,6 @@ int main(int argc, const char **argv)
|
||||
|
||||
string reason;
|
||||
RclConfig *config = recollinit(cleanup, sigcleanup, reason);
|
||||
|
||||
if (config == 0 || !config->ok()) {
|
||||
cerr << "Configuration problem: " << reason << endl;
|
||||
exit(1);
|
||||
@@ -130,6 +151,11 @@ int main(int argc, const char **argv)
|
||||
}
|
||||
}
|
||||
exit(!indexfiles(config, filenames));
|
||||
} else if (op_flags & OPT_s) {
|
||||
if (argc != 1)
|
||||
Usage();
|
||||
string lang = *argv++; argc--;
|
||||
exit(!createstemdb(config, lang));
|
||||
} else {
|
||||
confindexer = new ConfIndexer(config);
|
||||
bool rezero(op_flags & OPT_z);
|
||||
|
||||
Reference in New Issue
Block a user