*** empty log message ***
This commit is contained in:
+105
-7
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.2 2004-12-15 15:00:36 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.3 2004-12-17 13:01:01 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
@@ -11,6 +11,8 @@ static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.2 2004-12-15 15:00:36 dockes Exp $
|
||||
using namespace std;
|
||||
|
||||
#include "rcldb.h"
|
||||
#include "textsplit.h"
|
||||
#include "transcode.h"
|
||||
|
||||
#include "xapian.h"
|
||||
|
||||
@@ -29,7 +31,7 @@ class Native {
|
||||
|
||||
Rcl::Db::Db()
|
||||
{
|
||||
// pdata = new Native;
|
||||
pdata = new Native;
|
||||
}
|
||||
|
||||
Rcl::Db::~Db()
|
||||
@@ -37,6 +39,8 @@ Rcl::Db::~Db()
|
||||
if (pdata == 0)
|
||||
return;
|
||||
Native *ndb = (Native *)pdata;
|
||||
cerr << "Db::~Db: isopen " << ndb->isopen << " iswritable " <<
|
||||
ndb->iswritable << endl;
|
||||
try {
|
||||
// There is nothing to do for an ro db.
|
||||
if (ndb->isopen == false || ndb->iswritable == false) {
|
||||
@@ -58,10 +62,11 @@ Rcl::Db::~Db()
|
||||
|
||||
bool Rcl::Db::open(const string& dir, OpenMode mode)
|
||||
{
|
||||
return true;
|
||||
if (pdata == 0)
|
||||
return false;
|
||||
Native *ndb = (Native *)pdata;
|
||||
cerr << "Db::open: isopen " << ndb->isopen << " iswritable " <<
|
||||
ndb->iswritable << endl;
|
||||
try {
|
||||
switch (mode) {
|
||||
case DbUpd:
|
||||
@@ -95,10 +100,11 @@ bool Rcl::Db::open(const string& dir, OpenMode mode)
|
||||
|
||||
bool Rcl::Db::close()
|
||||
{
|
||||
return true;
|
||||
if (pdata == 0)
|
||||
return false;
|
||||
Native *ndb = (Native *)pdata;
|
||||
cerr << "Db::open: isopen " << ndb->isopen << " iswritable " <<
|
||||
ndb->iswritable << endl;
|
||||
if (ndb->isopen == false)
|
||||
return true;
|
||||
try {
|
||||
@@ -125,9 +131,103 @@ bool Rcl::Db::close()
|
||||
return false;
|
||||
}
|
||||
|
||||
// A small class to hold state while splitting text
|
||||
class wsData {
|
||||
public:
|
||||
Xapian::Document &doc;
|
||||
Xapian::termpos basepos; // Base for document section
|
||||
Xapian::termpos curpos; // Last position sent to callback
|
||||
wsData(Xapian::Document &d) : doc(d), basepos(1), curpos(0)
|
||||
{}
|
||||
};
|
||||
|
||||
bool splitCb(void *cdata, const std::string &term, int pos)
|
||||
{
|
||||
wsData *data = (wsData*)cdata;
|
||||
cerr << "splitCb: term " << term << endl;
|
||||
try {
|
||||
// 1 is the value for wdfinc in index_text when called from omindex
|
||||
// TOBEDONE: check what this is used for
|
||||
data->curpos = pos;
|
||||
data->doc.add_posting(term, data->basepos + data->curpos, 1);
|
||||
string printable;
|
||||
transcode(term, printable, "UTF-8", "ISO8859-1");
|
||||
cerr << "Adding " << printable << endl;
|
||||
} catch (...) {
|
||||
cerr << "Error occurred during add_posting" << endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Rcl::Db::add(const string &fn, const Rcl::Doc &doc)
|
||||
{
|
||||
return true;
|
||||
if (pdata == 0)
|
||||
return false;
|
||||
Native *ndb = (Native *)pdata;
|
||||
|
||||
Xapian::Document newdocument;
|
||||
|
||||
// Document data record. omindex has the following nl separated fields:
|
||||
// - url
|
||||
// - sample
|
||||
// - caption (title limited to 100 chars)
|
||||
// - mime type
|
||||
string record = "url=file:/" + fn;
|
||||
record += "\nmtime=" + doc.mtime;
|
||||
record += "\nsample=";
|
||||
record += "\ncaption=" + doc.title;
|
||||
record += "\nmtype=" + doc.mimetype;
|
||||
record += "\n";
|
||||
newdocument.set_data(record);
|
||||
|
||||
// TOBEDONE:
|
||||
// Need to add stuff here to unaccent and lowercase the data: use unac
|
||||
// for accents, and do it by hand for upper / lower. Note lowercasing is
|
||||
// only for ascii letters anyway, so it's just A-Z -> a-z
|
||||
|
||||
wsData splitData(newdocument);
|
||||
|
||||
TextSplit splitter(splitCb, &splitData);
|
||||
|
||||
splitter.text_to_words(doc.title);
|
||||
|
||||
splitData.basepos += splitData.curpos + 100;
|
||||
splitter.text_to_words(doc.text);
|
||||
|
||||
splitData.basepos += splitData.curpos + 100;
|
||||
splitter.text_to_words(doc.keywords);
|
||||
|
||||
splitData.basepos += splitData.curpos + 100;
|
||||
splitter.text_to_words(doc.abstract);
|
||||
|
||||
newdocument.add_term("T" + doc.mimetype);
|
||||
newdocument.add_term("P" + fn);
|
||||
|
||||
#if 0
|
||||
if (dupes == DUPE_replace) {
|
||||
// If this document has already been indexed, update the existing
|
||||
// entry.
|
||||
try {
|
||||
Xapian::docid did = db.replace_document(urlterm, newdocument);
|
||||
if (did < updated.size()) {
|
||||
updated[did] = true;
|
||||
cout << "updated." << endl;
|
||||
} else {
|
||||
cout << "added." << endl;
|
||||
}
|
||||
} catch (...) {
|
||||
// FIXME: is this ever actually needed?
|
||||
db.add_document(newdocument);
|
||||
cout << "added (failed re-seek for duplicate)." << endl;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
ndb->wdb.add_document(newdocument);
|
||||
// cout << "added." << endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -140,5 +240,3 @@ bool Rcl::Db::needUpdate(const string &filename, const struct stat *stp)
|
||||
// - fetch doc (get_document(docid)
|
||||
// - check date field, maybe skip
|
||||
}
|
||||
|
||||
|
||||
|
||||
+5
-3
@@ -1,6 +1,6 @@
|
||||
#ifndef _DB_H_INCLUDED_
|
||||
#define _DB_H_INCLUDED_
|
||||
/* @(#$Id: rcldb.h,v 1.2 2004-12-15 15:00:36 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: rcldb.h,v 1.3 2004-12-17 13:01:01 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -13,11 +13,13 @@ namespace Rcl {
|
||||
*/
|
||||
class Doc {
|
||||
public:
|
||||
string mimetype;
|
||||
string mtime; // Modification time as decimal ascii
|
||||
string origcharset;
|
||||
string title;
|
||||
string abstract;
|
||||
string keywords;
|
||||
string text;
|
||||
string keywords;
|
||||
string abstract;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user