1st beagle version with index/preview working

This commit is contained in:
dockes
2009-11-13 13:29:34 +00:00
parent efa501f06d
commit bbba826c06
12 changed files with 341 additions and 152 deletions
+38 -14
View File
@@ -175,7 +175,7 @@ BeagleQueueIndexer::BeagleQueueIndexer(RclConfig *cnf, Rcl::Db *db,
if (!m_config->getConfParam("beaglequeuedir", m_queuedir))
m_queuedir = path_tildexpand("~/.beagle/ToIndex");
if (m_tmpdir.empty() || access(m_tmpdir.c_str(), 0) < 0) {
if (m_db && m_tmpdir.empty() || access(m_tmpdir.c_str(), 0) < 0) {
string reason;
if (!maketmpdir(m_tmpdir, reason)) {
LOGERR(("DbIndexer: cannot create temporary directory: %s\n",
@@ -212,26 +212,23 @@ BeagleQueueIndexer::~BeagleQueueIndexer()
deleteZ(m_cache);
}
bool BeagleQueueIndexer::indexFromCache(const string& udi)
bool BeagleQueueIndexer::getFromCache(const string& udi, Rcl::Doc &dotdoc,
string& data, string *htt)
{
string dict, data;
string dict;
// This is horribly inefficient and needs fixing either by saving
// the offsets during the forward scan, or using an auxiliary isam
// map
// This is horribly inefficient, especially while reindexing from
// cache, and needs fixing either by saving the offsets during the
// forward scan, or using an auxiliary isam map
if (!m_cache->get(udi, dict, data))
return false;
ConfSimple cf(dict, 1);
string hittype;
if (!cf.get(keybght, hittype, "")) {
LOGERR(("BeagleIndexer::index: cc entry has no hit type\n"));
return false;
}
if (htt)
cf.get(keybght, *htt, "");
// Build a doc from saved metadata
Rcl::Doc dotdoc;
cf.get("url", dotdoc.url, "");
cf.get("mimetype", dotdoc.mimetype, "");
cf.get("fmtime", dotdoc.fmtime, "");
@@ -242,9 +239,29 @@ bool BeagleQueueIndexer::indexFromCache(const string& udi)
it != names.end(); it++) {
cf.get(*it, dotdoc.meta[*it], "");
}
return true;
}
bool BeagleQueueIndexer::indexFromCache(const string& udi)
{
if (!m_db)
return false;
Rcl::Doc dotdoc;
string data;
string hittype;
if (!getFromCache(udi, dotdoc, data, &hittype))
return false;
if (hittype.empty()) {
LOGERR(("BeagleIndexer::index: cc entry has no hit type\n"));
return false;
}
if (!stringlowercmp("bookmark", hittype)) {
// Just index the dotdoc
dotdoc.meta[Rcl::Doc::keybcknd] = "BGL";
return m_db->addOrUpdate(udi, "", dotdoc);
} else if (stringlowercmp("webhistory", dotdoc.meta[keybght]) ||
(dotdoc.mimetype.compare("text/html") &&
@@ -269,13 +286,15 @@ bool BeagleQueueIndexer::indexFromCache(const string& udi)
doc.url = dotdoc.url;
doc.fbytes = dotdoc.fbytes;
doc.sig = "";
doc.meta[Rcl::Doc::keybcknd] = "BGL";
return m_db->addOrUpdate(udi, "", doc);
}
}
bool BeagleQueueIndexer::index()
{
if (!m_db)
return false;
LOGDEB(("BeagleQueueIndexer::processqueue: dir: [%s]\n",
m_queuedir.c_str()));
m_config->setKeyDir(m_queuedir);
@@ -322,6 +341,9 @@ BeagleQueueIndexer::processone(const string &path,
const struct stat *stp,
FsTreeWalker::CbFlag flg)
{
if (!m_db) //??
return FsTreeWalker::FtwError;
bool dounlink = false;
if (flg != FsTreeWalker::FtwRegular)
@@ -365,6 +387,7 @@ BeagleQueueIndexer::processone(const string &path,
dotfile.m_fields.set("fmtime", dotdoc.fmtime, "");
dotfile.m_fields.set("fbytes", dotdoc.fbytes, "");
dotdoc.meta[Rcl::Doc::keybcknd] = "BGL";
if (!m_db->addOrUpdate(udi, "", dotdoc))
return FsTreeWalker::FtwError;
@@ -402,6 +425,7 @@ BeagleQueueIndexer::processone(const string &path,
dotfile.m_fields.set("fmtime", dotdoc.fmtime, "");
dotfile.m_fields.set("fbytes", dotdoc.fbytes, "");
doc.meta[Rcl::Doc::keybcknd] = "BGL";
if (!m_db->addOrUpdate(udi, "", doc))
return FsTreeWalker::FtwError;
+17 -7
View File
@@ -19,21 +19,30 @@
/* @(#$Id: $ (C) 2009 J.F.Dockes */
/**
* Code to process the Beagle indexing queue. Beagle MUST NOT be
* running, else mayhem will ensue. Interesting to reuse the beagle
* firefox visited page indexing plugin for example.
* Process the Beagle indexing queue.
*
* Beagle MUST NOT be running, else mayhem will ensue.
*
* This is mainly written to reuse the Beagle Firefox plug-in (which
* copies visited pages and bookmarks to the queue).
*/
#include "rclconfig.h"
#include "fstreewalk.h"
#include "rcldb.h"
#include "rcldoc.h"
class DbIxStatusUpdater;
class CirCache;
class RclConfig;
namespace Rcl {
class Db;
}
class BeagleQueueIndexer : public FsTreeWalkerCB {
public:
BeagleQueueIndexer(RclConfig *cnf, Rcl::Db *db,
/**
* @para db can be null when using readonly for calling getFromCache()
*/
BeagleQueueIndexer(RclConfig *cnf, Rcl::Db *db = 0,
DbIxStatusUpdater *updfunc = 0);
~BeagleQueueIndexer();
@@ -42,6 +51,8 @@ public:
FsTreeWalker::Status
processone(const string &, const struct stat *, FsTreeWalker::CbFlag);
bool getFromCache(const string& udi, Rcl::Doc &doc, string& data,
string *hittype = 0);
private:
RclConfig *m_config;
Rcl::Db *m_db;
@@ -51,7 +62,6 @@ private:
DbIxStatusUpdater *m_updater;
bool indexFromCache(const string& udi);
};
#endif /* _beaglequeue_h_included_ */