*** empty log message ***
This commit is contained in:
+90
-10
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.5 2004-12-17 15:50:48 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.6 2005-01-24 13:17:58 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
@@ -14,18 +14,23 @@ using namespace std;
|
||||
#include "textsplit.h"
|
||||
#include "transcode.h"
|
||||
#include "unacpp.h"
|
||||
#include "conftree.h"
|
||||
|
||||
#include "xapian.h"
|
||||
|
||||
// Data for a xapian database
|
||||
// Data for a xapian database. There could actually be 2 different ones for
|
||||
// indexing or query as there is not much in common.
|
||||
class Native {
|
||||
public:
|
||||
bool isopen;
|
||||
bool iswritable;
|
||||
class Xapian::Database db;
|
||||
class Xapian::WritableDatabase wdb;
|
||||
// Indexing
|
||||
Xapian::WritableDatabase wdb;
|
||||
vector<bool> updated;
|
||||
|
||||
// Querying
|
||||
Xapian::Database db;
|
||||
Xapian::Query query;
|
||||
Native() : isopen(false), iswritable(false) {}
|
||||
|
||||
};
|
||||
@@ -37,6 +42,7 @@ Rcl::Db::Db()
|
||||
|
||||
Rcl::Db::~Db()
|
||||
{
|
||||
cerr << "Rcl::Db::~Db" << endl;
|
||||
if (pdata == 0)
|
||||
return;
|
||||
Native *ndb = (Native *)pdata;
|
||||
@@ -45,6 +51,7 @@ Rcl::Db::~Db()
|
||||
try {
|
||||
// There is nothing to do for an ro db.
|
||||
if (ndb->isopen == false || ndb->iswritable == false) {
|
||||
cerr << "Deleting native database" << endl;
|
||||
delete ndb;
|
||||
return;
|
||||
}
|
||||
@@ -82,8 +89,8 @@ bool Rcl::Db::open(const string& dir, OpenMode mode)
|
||||
case DbRO:
|
||||
default:
|
||||
ndb->iswritable = false;
|
||||
cerr << "Not ready to open RO yet" << endl;
|
||||
exit(1);
|
||||
ndb->db = Xapian::Auto::open(dir, Xapian::DB_OPEN);
|
||||
break;
|
||||
}
|
||||
ndb->isopen = true;
|
||||
return true;
|
||||
@@ -142,7 +149,8 @@ class wsData {
|
||||
{}
|
||||
};
|
||||
|
||||
bool splitCb(void *cdata, const std::string &term, int pos)
|
||||
// Callback for the document to word splitting class during indexation
|
||||
static bool splitCb(void *cdata, const std::string &term, int pos)
|
||||
{
|
||||
wsData *data = (wsData*)cdata;
|
||||
|
||||
@@ -172,7 +180,7 @@ bool dumb_string(const string &in, string &out)
|
||||
out.erase();
|
||||
if (!unac_cpp(in, inter))
|
||||
return false;
|
||||
out.resize(inter.length());
|
||||
out.reserve(inter.length());
|
||||
for (unsigned int i = 0; i < inter.length(); i++) {
|
||||
if (inter[i] >= 'A' && inter[i] <= 'Z')
|
||||
out += inter[i] + 'a' - 'A';
|
||||
@@ -239,8 +247,10 @@ bool Rcl::Db::add(const string &fn, const Rcl::Doc &doc)
|
||||
// If this document has already been indexed, update the existing
|
||||
// entry.
|
||||
try {
|
||||
Xapian::docid did = ndb->wdb.replace_document(pathterm,
|
||||
newdocument);
|
||||
#if 0
|
||||
Xapian::docid did =
|
||||
#endif
|
||||
ndb->wdb.replace_document(pathterm, newdocument);
|
||||
#if 0
|
||||
if (did < updated.size()) {
|
||||
updated[did] = true;
|
||||
@@ -297,3 +307,73 @@ bool Rcl::Db::needUpdate(const string &filename, const struct stat *stp)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#include <vector>
|
||||
|
||||
class wsQData {
|
||||
public:
|
||||
vector<string> terms;
|
||||
};
|
||||
|
||||
// Callback for the document to word splitting class during indexation
|
||||
static bool splitQCb(void *cdata, const std::string &term, int )
|
||||
{
|
||||
wsQData *data = (wsQData*)cdata;
|
||||
|
||||
cerr << "splitQCb: term '" << term << "'" << endl;
|
||||
cerr << "splitQCb: term length: " << term.length() << endl;
|
||||
//string printable;
|
||||
//transcode(term, printable, "UTF-8", "ISO8859-1");
|
||||
//cerr << "Adding " << printable << endl;
|
||||
|
||||
data->terms.push_back(term);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Rcl::Db::setQuery(const std::string &querystring)
|
||||
{
|
||||
wsQData splitData;
|
||||
TextSplit splitter(splitQCb, &splitData);
|
||||
|
||||
string noacc;
|
||||
if (!dumb_string(querystring, noacc)) {
|
||||
return false;
|
||||
}
|
||||
// noacc = querystring;
|
||||
splitter.text_to_words(noacc);
|
||||
|
||||
Native *ndb = (Native *)pdata;
|
||||
|
||||
// splitData.terms.resize(0);
|
||||
// splitData.terms.push_back(string("le"));
|
||||
ndb->query = Xapian::Query(Xapian::Query::OP_OR, splitData.terms.begin(),
|
||||
splitData.terms.end());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Rcl::Db::getDoc(int i, Doc &doc)
|
||||
{
|
||||
// cerr << "Rcl::Db::getDoc: " << i << endl;
|
||||
Native *ndb = (Native *)pdata;
|
||||
|
||||
Xapian::Enquire enquire(ndb->db);
|
||||
enquire.set_query(ndb->query);
|
||||
Xapian::MSet matches = enquire.get_mset(i, 1);
|
||||
|
||||
// cerr << "Query `" << ndb->query.get_description() << "'" <<
|
||||
// "Estimated results: " << matches.get_matches_lower_bound() << endl;
|
||||
|
||||
if (matches.empty())
|
||||
return false;
|
||||
|
||||
Xapian::Document xdoc = matches.begin().get_document();
|
||||
|
||||
// Parse xapian document's data and populate doc fields
|
||||
string data = xdoc.get_data();
|
||||
ConfSimple parms(&data);
|
||||
parms.get(string("mtype"), doc.mimetype);
|
||||
parms.get(string("mtime"), doc.mtime);
|
||||
parms.get(string("url"), doc.url);
|
||||
return true;
|
||||
}
|
||||
|
||||
+38
-1
@@ -1,9 +1,22 @@
|
||||
#ifndef _DB_H_INCLUDED_
|
||||
#define _DB_H_INCLUDED_
|
||||
/* @(#$Id: rcldb.h,v 1.3 2004-12-17 13:01:01 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: rcldb.h,v 1.4 2005-01-24 13:17:58 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <string>
|
||||
|
||||
// rcldb defines an interface for a 'real' text database. The current
|
||||
// implementation uses xapian only, and xapian-related code is in rcldb.cpp
|
||||
// If support was added for other backend, the xapian code would be moved in
|
||||
// rclxapian.cpp, another file would be created for the new backend, and the
|
||||
// configuration/compile/link code would be adjusted to allow choosing. There
|
||||
// is no plan for supporting multiple different backends.
|
||||
//
|
||||
// In no case does this try to implement a useful virtualized text-db interface
|
||||
// The main goal is simplicity and good matching to usage inside the recoll
|
||||
// user interface. In other words, this is not exhaustive or well-designed or
|
||||
// reusable.
|
||||
|
||||
|
||||
struct stat;
|
||||
|
||||
namespace Rcl {
|
||||
@@ -13,6 +26,7 @@ namespace Rcl {
|
||||
*/
|
||||
class Doc {
|
||||
public:
|
||||
string url;
|
||||
string mimetype;
|
||||
string mtime; // Modification time as decimal ascii
|
||||
string origcharset;
|
||||
@@ -20,6 +34,16 @@ class Doc {
|
||||
string text;
|
||||
string keywords;
|
||||
string abstract;
|
||||
void erase() {
|
||||
url.erase();
|
||||
mimetype.erase();
|
||||
mtime.erase();
|
||||
origcharset.erase();
|
||||
title.erase();
|
||||
text.erase();
|
||||
keywords.erase();
|
||||
abstract.erase();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -27,14 +51,27 @@ class Doc {
|
||||
*/
|
||||
class Db {
|
||||
void *pdata;
|
||||
Doc curdoc;
|
||||
public:
|
||||
Db();
|
||||
~Db();
|
||||
enum OpenMode {DbRO, DbUpd, DbTrunc};
|
||||
bool open(const std::string &dbdir, OpenMode mode);
|
||||
bool close();
|
||||
|
||||
// Update-related functions
|
||||
bool add(const string &filename, const Doc &doc);
|
||||
bool needUpdate(const string &filename, const struct stat *stp);
|
||||
|
||||
// Query-related functions
|
||||
|
||||
// Parse query string and initialize query
|
||||
bool setQuery(const std::string &q);
|
||||
|
||||
// Get document at rank i. This is probably vastly inferior to the type
|
||||
// of interface in Xapian, but we have to start with something simple
|
||||
// to experiment with the GUI
|
||||
bool getDoc(int i, Doc &doc);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user