*** empty log message ***

This commit is contained in:
dockes 2005-11-24 18:21:55 +00:00
parent ae8ff5abb3
commit 596966da4e
5 changed files with 159 additions and 10 deletions

View File

@ -1,8 +1,8 @@
PROGS = qtry qxtry xadump
PROGS = trhist qtry qxtry xadump
all: $(PROGS)
XADUMP_OBJS= xadump.o $(BIGLIB)
XADUMP_OBJS= xadump.o $(BIGLIB)
xadump : $(XADUMP_OBJS)
$(CXX) $(CXXFLAGS) -o xadump $(XADUMP_OBJS) \
$(LIBICONV) $(LIBXAPIAN)
@ -12,11 +12,18 @@ qxtry : $(QXTRY_OBJS)
$(CXX) $(CXXFLAGS) -o qxtry $(QXTRY_OBJS) \
$(LIBICONV) $(LIBXAPIAN)
QTRY_OBJS= qtry.o $(BIGLIB)
QTRY_OBJS= qtry.o $(BIGLIB) $(MIMELIB)
qtry : $(QTRY_OBJS)
$(CXX) $(CXXFLAGS) -o qtry $(QTRY_OBJS) \
$(LIBICONV) $(LIBXAPIAN)
HISTORY_OBJS= trhist.o $(BIGLIB) $(MIMELIB)
trhist : $(HISTORY_OBJS)
$(CXX) $(CXXFLAGS) -o trhist $(HISTORY_OBJS) \
$(LIBICONV) $(LIBXAPIAN)
trhist.o : history.cpp history.h
$(CXX) $(CXXFLAGS) -DTEST_HISTORY -c -o trhist.o history.cpp
$(BIGLIB):
cd ../lib;make

112
src/query/history.cpp Normal file
View File

@ -0,0 +1,112 @@
#ifndef lint
static char rcsid[] = "@(#$Id: history.cpp,v 1.1 2005-11-24 18:21:55 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
#ifndef TEST_HISTORY
#include <time.h>
#include "history.h"
#include "base64.h"
#include "smallut.h"
#include "debuglog.h"
#ifndef NO_NAMESPACES
using namespace std;
#endif
RclQHistory::RclQHistory(const string &fn, unsigned int mxs)
: m_mlen(mxs), m_data(fn.c_str())
{
}
const char *docSubkey = "docs";
bool RclQHistory::enterDocument(const string fn, const string ipath)
{
LOGDEB(("RclQHistory::enterDocument: [%s] [%s] into %s\n",
fn.c_str(), ipath.c_str(), m_data.getFilename().c_str()));
// How many do we have
list<string> names = m_data.getNames(docSubkey);
list<string>::const_iterator it = names.begin();
if (names.size() >= m_mlen) {
// Need to erase entries until we're back to size. Note that
// we don't ever erase anything. Problems will arise when
// history is 2 billion entries old
for (unsigned int i = 0; i < names.size() - m_mlen + 1; i++, it++) {
m_data.erase(*it, docSubkey);
it++;
}
}
// Increment highest number
int hi = names.empty() ? 0 : atoi(names.back().c_str());
hi++;
char nname[20];
sprintf(nname, "%010d", hi);
string bfn, bipath;
base64_encode(fn, bfn);
base64_encode(ipath, bipath);
string value = bfn + " " + bipath;
if (!m_data.set(string(nname), value, docSubkey)) {
LOGERR(("RclQHistory::enterDocument: set failed\n"));
return false;
}
return true;
}
list< pair<string, string> > RclQHistory::getDocHistory()
{
list< pair<string, string> > mlist;
list<string> names = m_data.getNames(docSubkey);
for (list<string>::const_iterator it = names.begin(); it != names.end();
it++) {
string value;
if (m_data.get(*it, value, docSubkey)) {
list<string> vall;
stringToStrings(value, vall);
list<string>::const_iterator it1 = vall.begin();
if (vall.size() < 1)
continue;
string fn, ipath;
LOGDEB(("RclQHistory::getDocHistory:b64: %s\n", (*it1).c_str()));
base64_decode(*it1++, fn);
LOGDEB(("RclQHistory::getDocHistory:fn: %s\n", fn.c_str()));
if (vall.size() == 2)
base64_decode(*it1, ipath);
mlist.push_back(pair<string, string>(fn, ipath));
}
}
return mlist;
}
#else
#include <string>
#include "history.h"
#include "debuglog.h"
#ifndef NO_NAMESPACES
using namespace std;
#endif
int main(int argc, char **argv)
{
RclQHistory hist("toto", 5);
DebugLog::getdbl()->setloglevel(DEBDEB1);
DebugLog::setfilename("stderr");
for (int i = 0; i < 10; i++) {
char docname[100];
sprintf(docname, "A very long document document name is very long indeed and this is the end of it here and exactly here:\n%d", i);
hist.enterDocument(string(docname), "ipathx");
}
list< pair<string, string> > hlist = hist.getDocHistory();
for (list< pair<string, string> >::const_iterator it = hlist.begin();
it != hlist.end(); it++) {
printf("[%s] [%s]\n", it->first.c_str(), it->second.c_str());
}
}
#endif

29
src/query/history.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef _HISTORY_H_INCLUDED_
#define _HISTORY_H_INCLUDED_
/* @(#$Id: history.h,v 1.1 2005-11-24 18:21:55 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
#include <list>
#include <utility>
#include "conftree.h"
/**
* The query and documents history class. This is based on a ConfTree for no
* imperative reason
*/
class RclQHistory {
public:
RclQHistory(const std::string &fn, unsigned int maxsize=1000);
bool ok() {return m_data.getStatus() == ConfSimple::STATUS_RW;}
bool enterDocument(const std::string fn, const std::string ipath);
std::list< std::pair<std::string, std::string> > getDocHistory();
private:
unsigned int m_mlen;
ConfSimple m_data;
};
#endif /* _HISTORY_H_INCLUDED_ */

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: qtry.cpp,v 1.5 2005-11-24 07:16:16 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: qtry.cpp,v 1.6 2005-11-24 18:21:55 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
// Tests with the query interface
@ -97,7 +97,8 @@ int main(int argc, char **argv)
cout << "Url: " << doc.url << endl;
cout << "Mimetype: " << doc.mimetype << endl;
cout << "Mtime: " << doc.mtime << endl;
cout << "fmtime: " << doc.fmtime << endl;
cout << "dmtime: " << doc.dmtime << endl;
cout << "Origcharset: " << doc.origcharset << endl;
cout << "Title: " << doc.title << endl;
cout << "Text: " << doc.text << endl;
@ -109,8 +110,7 @@ int main(int argc, char **argv)
// for preview:
// Look for appropriate handler
MimeHandlerFunc fun = getMimeHandler(doc.mimetype,
rclconfig->getMimeConf());
MimeHandler *fun = getMimeHandler(doc.mimetype, rclconfig);
if (!fun) {
cout << "No mime handler !" << endl;
continue;
@ -119,7 +119,8 @@ int main(int argc, char **argv)
cout << "Filename: " << fn << endl;
Rcl::Doc fdoc;
if (!fun(rclconfig, fn, doc.mimetype, fdoc)) {
if (fun->mkDoc(rclconfig, fn, doc.mimetype, fdoc, doc.ipath) ==
MimeHandler::MHError) {
cout << "Failed to convert/preview document!" << endl;
continue;
}

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: xadump.cpp,v 1.5 2005-11-24 07:16:16 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: xadump.cpp,v 1.6 2005-11-24 18:21:55 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
#include <strings.h>
@ -155,7 +155,7 @@ int main(int argc, char **argv)
cout << "FreqFor " << aterm << " : " <<
db->get_termfreq(aterm) << endl;
} else if (op_flags & OPT_E) {
cout << "Exists " << aterm << " : " <<
cout << "Exists [" << aterm << "] : " <<
db->term_exists(aterm) << endl;
}