diff --git a/src/query/Makefile b/src/query/Makefile index 25cba72b..baaf7c93 100644 --- a/src/query/Makefile +++ b/src/query/Makefile @@ -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 diff --git a/src/query/history.cpp b/src/query/history.cpp new file mode 100644 index 00000000..2cd149fa --- /dev/null +++ b/src/query/history.cpp @@ -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 +#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 names = m_data.getNames(docSubkey); + list::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 > RclQHistory::getDocHistory() +{ + list< pair > mlist; + list names = m_data.getNames(docSubkey); + for (list::const_iterator it = names.begin(); it != names.end(); + it++) { + string value; + if (m_data.get(*it, value, docSubkey)) { + list vall; + stringToStrings(value, vall); + list::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(fn, ipath)); + } + } + return mlist; +} + + +#else +#include + +#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 > hlist = hist.getDocHistory(); + for (list< pair >::const_iterator it = hlist.begin(); + it != hlist.end(); it++) { + printf("[%s] [%s]\n", it->first.c_str(), it->second.c_str()); + } +} + +#endif diff --git a/src/query/history.h b/src/query/history.h new file mode 100644 index 00000000..4905f66d --- /dev/null +++ b/src/query/history.h @@ -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 +#include +#include + +#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 > getDocHistory(); + + private: + unsigned int m_mlen; + ConfSimple m_data; +}; + + +#endif /* _HISTORY_H_INCLUDED_ */ diff --git a/src/query/qtry.cpp b/src/query/qtry.cpp index 1d216f75..afd73457 100644 --- a/src/query/qtry.cpp +++ b/src/query/qtry.cpp @@ -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; } diff --git a/src/query/xadump.cpp b/src/query/xadump.cpp index 0fd48b85..eaa92e89 100644 --- a/src/query/xadump.cpp +++ b/src/query/xadump.cpp @@ -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 @@ -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; }