cleanup docseq, arrange things so that we can page reslist past the initial result count estimate if there are more
This commit is contained in:
+11
-64
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: docseq.cpp,v 1.9 2006-09-13 14:57:56 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: docseq.cpp,v 1.10 2007-01-19 10:32:39 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -22,70 +22,17 @@ static char rcsid[] = "@(#$Id: docseq.cpp,v 1.9 2006-09-13 14:57:56 dockes Exp $
|
||||
|
||||
#include "docseq.h"
|
||||
|
||||
bool DocSequenceDb::getDoc(int num, Rcl::Doc &doc, int *percent, string *sh)
|
||||
int DocSequence::getSeqSlice(int offs, int cnt, vector<ResListEntry>& result)
|
||||
{
|
||||
if (sh) sh->erase();
|
||||
return m_db ? m_db->getDoc(num, doc, percent) : false;
|
||||
}
|
||||
|
||||
int DocSequenceDb::getResCnt()
|
||||
{
|
||||
if (!m_db)
|
||||
return -1;
|
||||
if (m_rescnt < 0) {
|
||||
m_rescnt= m_db->getResCnt();
|
||||
int ret = 0;
|
||||
for (int num = offs; num < offs + cnt; num++, ret++) {
|
||||
result.push_back(ResListEntry());
|
||||
if (!getDoc(num, result.back().doc, &result.back().percent,
|
||||
&result.back().subHeader)) {
|
||||
result.pop_back();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return m_rescnt;
|
||||
}
|
||||
|
||||
void DocSequenceDb::getTerms(list<string> &terms)
|
||||
{
|
||||
if (!m_db)
|
||||
return;
|
||||
m_db->getQueryTerms(terms);
|
||||
}
|
||||
|
||||
bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, int *percent,
|
||||
string *sh)
|
||||
{
|
||||
// Retrieve history list
|
||||
if (!m_hist)
|
||||
return false;
|
||||
if (m_hlist.empty())
|
||||
m_hlist = m_hist->getDocHistory();
|
||||
|
||||
if (num < 0 || num >= (int)m_hlist.size())
|
||||
return false;
|
||||
int skip;
|
||||
if (m_prevnum >= 0 && num >= m_prevnum) {
|
||||
skip = num - m_prevnum;
|
||||
} else {
|
||||
skip = num;
|
||||
m_it = m_hlist.begin();
|
||||
m_prevtime = -1;
|
||||
}
|
||||
m_prevnum = num;
|
||||
while (skip--)
|
||||
m_it++;
|
||||
if (percent)
|
||||
*percent = 100;
|
||||
if (sh) {
|
||||
if (m_prevtime < 0 || abs(m_prevtime - m_it->unixtime) > 86400) {
|
||||
m_prevtime = m_it->unixtime;
|
||||
time_t t = (time_t)(m_it->unixtime);
|
||||
*sh = string(ctime(&t));
|
||||
// Get rid of the final \n in ctime
|
||||
sh->erase(sh->length()-1);
|
||||
} else
|
||||
sh->erase();
|
||||
}
|
||||
return m_db->getDoc(m_it->fn, m_it->ipath, doc, percent);
|
||||
}
|
||||
|
||||
int DocSequenceHistory::getResCnt()
|
||||
{
|
||||
if (m_hlist.empty())
|
||||
m_hlist = m_hist->getDocHistory();
|
||||
return m_hlist.size();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
+33
-43
@@ -16,28 +16,37 @@
|
||||
*/
|
||||
#ifndef _DOCSEQ_H_INCLUDED_
|
||||
#define _DOCSEQ_H_INCLUDED_
|
||||
/* @(#$Id: docseq.h,v 1.9 2006-09-13 14:57:56 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: docseq.h,v 1.10 2007-01-19 10:32:39 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
#include <vector>
|
||||
#ifndef NO_NAMESPACES
|
||||
using std::string;
|
||||
using std::list;
|
||||
using std::vector;
|
||||
#endif
|
||||
|
||||
#include "rcldb.h"
|
||||
#include "history.h"
|
||||
#include "rcldoc.h"
|
||||
|
||||
// A result list entry.
|
||||
struct ResListEntry {
|
||||
Rcl::Doc doc;
|
||||
int percent;
|
||||
string subHeader;
|
||||
ResListEntry() : percent(0) {}
|
||||
};
|
||||
|
||||
/** Interface for a list of documents coming from some source.
|
||||
|
||||
The result list display data may come from different sources (ie:
|
||||
history or Db query). We have an interface to make things cleaner.
|
||||
history or Db query), and be post-processed (DocSeqSorted).
|
||||
*/
|
||||
class DocSequence {
|
||||
public:
|
||||
DocSequence(const string &t) : m_title(t) {}
|
||||
virtual ~DocSequence() {}
|
||||
/** Get document at given rank
|
||||
|
||||
/** Get document at given rank.
|
||||
*
|
||||
* @param num document rank in sequence
|
||||
* @param doc return data
|
||||
@@ -52,49 +61,30 @@ class DocSequence {
|
||||
*/
|
||||
virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0)
|
||||
= 0;
|
||||
|
||||
/** Get next page of documents. This accumulates entries into the result
|
||||
* list (doesn't reset it). */
|
||||
virtual int getSeqSlice(int offs, int cnt, vector<ResListEntry>& result);
|
||||
|
||||
/** Get abstract for document. This is special because it may take time.
|
||||
* The default is to return the input doc's abstract fields, but some
|
||||
* sequences can compute a better value (ie: docseqdb) */
|
||||
virtual string getAbstract(Rcl::Doc& doc) {
|
||||
return doc.abstract;
|
||||
}
|
||||
|
||||
/** Get estimated total count in results */
|
||||
virtual int getResCnt() = 0;
|
||||
|
||||
/** Get title for result list */
|
||||
virtual string title() {return m_title;}
|
||||
|
||||
/** Get search terms (for highlighting abstracts). Some sequences
|
||||
* may have no associated search terms. Implement this for them. */
|
||||
virtual void getTerms(list<string>& t) {t.clear();}
|
||||
|
||||
private:
|
||||
string m_title;
|
||||
};
|
||||
|
||||
|
||||
/** A DocSequence from a Db query (there should be one active for this
|
||||
to make sense */
|
||||
class DocSequenceDb : public DocSequence {
|
||||
public:
|
||||
DocSequenceDb(Rcl::Db *d, const string &t) :
|
||||
DocSequence(t), m_db(d), m_rescnt(-1)
|
||||
{}
|
||||
virtual ~DocSequenceDb() {}
|
||||
virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string * = 0);
|
||||
virtual int getResCnt();
|
||||
virtual void getTerms(list<string>&);
|
||||
|
||||
private:
|
||||
Rcl::Db *m_db;
|
||||
int m_rescnt;
|
||||
};
|
||||
|
||||
/** A DocSequence coming from the history file */
|
||||
class DocSequenceHistory : public DocSequence {
|
||||
public:
|
||||
DocSequenceHistory(Rcl::Db *d, RclHistory *h, const string &t)
|
||||
: DocSequence(t), m_db(d), m_hist(h), m_prevnum(-1), m_prevtime(-1) {}
|
||||
virtual ~DocSequenceHistory() {}
|
||||
|
||||
virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0);
|
||||
virtual int getResCnt();
|
||||
private:
|
||||
Rcl::Db *m_db;
|
||||
RclHistory *m_hist;
|
||||
int m_prevnum;
|
||||
long m_prevtime;
|
||||
|
||||
list<RclDHistoryEntry> m_hlist;
|
||||
list<RclDHistoryEntry>::const_iterator m_it;
|
||||
};
|
||||
|
||||
#endif /* _DOCSEQ_H_INCLUDED_ */
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: docseqdb.cpp,v 1.1 2007-01-19 10:32:39 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "docseqdb.h"
|
||||
#include "rcldb.h"
|
||||
|
||||
bool DocSequenceDb::getDoc(int num, Rcl::Doc &doc, int *percent, string *sh)
|
||||
{
|
||||
if (sh) sh->erase();
|
||||
return m_db ? m_db->getDoc(num, doc, percent) : false;
|
||||
}
|
||||
|
||||
int DocSequenceDb::getResCnt()
|
||||
{
|
||||
if (!m_db)
|
||||
return -1;
|
||||
if (m_rescnt < 0) {
|
||||
m_rescnt= m_db->getResCnt();
|
||||
}
|
||||
return m_rescnt;
|
||||
}
|
||||
|
||||
void DocSequenceDb::getTerms(list<string> &terms)
|
||||
{
|
||||
if (!m_db)
|
||||
return;
|
||||
m_db->getQueryTerms(terms);
|
||||
}
|
||||
|
||||
string DocSequenceDb::getAbstract(Rcl::Doc &doc)
|
||||
{
|
||||
if (!m_db)
|
||||
return doc.abstract;
|
||||
string abstract;
|
||||
m_db->makeDocAbstract(doc, abstract);
|
||||
return abstract.empty() ? doc.abstract : abstract;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifndef _DOCSEQDB_H_INCLUDED_
|
||||
#define _DOCSEQDB_H_INCLUDED_
|
||||
/* @(#$Id: docseqdb.h,v 1.1 2007-01-19 10:32:39 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
#include <string>
|
||||
#include <list>
|
||||
#ifndef NO_NAMESPACES
|
||||
using std::string;
|
||||
using std::list;
|
||||
#endif
|
||||
|
||||
#include "docseq.h"
|
||||
namespace Rcl {
|
||||
class Db;
|
||||
}
|
||||
|
||||
/** A DocSequence from a Db query (there should be one active for this
|
||||
to make sense */
|
||||
class DocSequenceDb : public DocSequence {
|
||||
public:
|
||||
DocSequenceDb(Rcl::Db *d, const string &t) :
|
||||
DocSequence(t), m_db(d), m_rescnt(-1)
|
||||
{}
|
||||
virtual ~DocSequenceDb() {}
|
||||
virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string * = 0);
|
||||
virtual int getResCnt();
|
||||
virtual void getTerms(list<string>&);
|
||||
virtual string getAbstract(Rcl::Doc &doc);
|
||||
|
||||
private:
|
||||
Rcl::Db *m_db;
|
||||
int m_rescnt;
|
||||
};
|
||||
|
||||
#endif /* _DOCSEQDB_H_INCLUDED_ */
|
||||
@@ -0,0 +1,68 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: docseqhist.cpp,v 1.1 2007-01-19 10:32:39 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "docseqhist.h"
|
||||
#include "rcldb.h"
|
||||
|
||||
bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, int *percent,
|
||||
string *sh)
|
||||
{
|
||||
// Retrieve history list
|
||||
if (!m_hist)
|
||||
return false;
|
||||
if (m_hlist.empty())
|
||||
m_hlist = m_hist->getDocHistory();
|
||||
|
||||
if (num < 0 || num >= (int)m_hlist.size())
|
||||
return false;
|
||||
int skip;
|
||||
if (m_prevnum >= 0 && num >= m_prevnum) {
|
||||
skip = num - m_prevnum;
|
||||
} else {
|
||||
skip = num;
|
||||
m_it = m_hlist.begin();
|
||||
m_prevtime = -1;
|
||||
}
|
||||
m_prevnum = num;
|
||||
while (skip--)
|
||||
m_it++;
|
||||
if (percent)
|
||||
*percent = 100;
|
||||
if (sh) {
|
||||
if (m_prevtime < 0 || abs(m_prevtime - m_it->unixtime) > 86400) {
|
||||
m_prevtime = m_it->unixtime;
|
||||
time_t t = (time_t)(m_it->unixtime);
|
||||
*sh = string(ctime(&t));
|
||||
// Get rid of the final \n in ctime
|
||||
sh->erase(sh->length()-1);
|
||||
} else
|
||||
sh->erase();
|
||||
}
|
||||
return m_db->getDoc(m_it->fn, m_it->ipath, doc, percent);
|
||||
}
|
||||
|
||||
int DocSequenceHistory::getResCnt()
|
||||
{
|
||||
if (m_hlist.empty())
|
||||
m_hlist = m_hist->getDocHistory();
|
||||
return m_hlist.size();
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifndef _DOCSEQHIST_H_INCLUDED_
|
||||
#define _DOCSEQHIST_H_INCLUDED_
|
||||
/* @(#$Id: docseqhist.h,v 1.1 2007-01-19 10:32:39 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
#include <string>
|
||||
#include <list>
|
||||
#ifndef NO_NAMESPACES
|
||||
using std::string;
|
||||
using std::list;
|
||||
#endif
|
||||
|
||||
#include "docseq.h"
|
||||
#include "history.h"
|
||||
namespace Rcl {
|
||||
class Db;
|
||||
}
|
||||
class RclHistory;
|
||||
|
||||
/** A DocSequence coming from the history file.
|
||||
* History is kept as a list of urls. This queries the db to fetch
|
||||
* metadata for an url key */
|
||||
class DocSequenceHistory : public DocSequence {
|
||||
public:
|
||||
DocSequenceHistory(Rcl::Db *d, RclHistory *h, const string &t)
|
||||
: DocSequence(t), m_db(d), m_hist(h), m_prevnum(-1), m_prevtime(-1) {}
|
||||
virtual ~DocSequenceHistory() {}
|
||||
|
||||
virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0);
|
||||
virtual int getResCnt();
|
||||
private:
|
||||
Rcl::Db *m_db;
|
||||
RclHistory *m_hist;
|
||||
int m_prevnum;
|
||||
long m_prevtime;
|
||||
|
||||
list<RclDHistoryEntry> m_hlist;
|
||||
list<RclDHistoryEntry>::const_iterator m_it;
|
||||
};
|
||||
|
||||
#endif /* _DOCSEQ_H_INCLUDED_ */
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: sortseq.cpp,v 1.9 2006-12-05 15:18:48 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: sortseq.cpp,v 1.10 2007-01-19 10:32:39 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
|
||||
DocSeqSorted::DocSeqSorted(RefCntr<DocSequence> iseq, DocSeqSortSpec &sortspec,
|
||||
const std::string &t)
|
||||
: DocSequence(t)
|
||||
: DocSequence(t), m_seq(iseq)
|
||||
{
|
||||
m_spec = sortspec;
|
||||
LOGDEB(("DocSeqSorted:: count %d\n", m_spec.sortwidth));
|
||||
@@ -120,3 +120,8 @@ bool DocSeqSorted::getDoc(int num, Rcl::Doc &doc, int *percent, string *)
|
||||
doc = *m_docsp[num];
|
||||
return true;
|
||||
}
|
||||
|
||||
string DocSeqSorted::getAbstract(Rcl::Doc& doc)
|
||||
{
|
||||
return m_seq->getAbstract(doc);
|
||||
}
|
||||
|
||||
+5
-3
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
#ifndef _SORTSEQ_H_INCLUDED_
|
||||
#define _SORTSEQ_H_INCLUDED_
|
||||
/* @(#$Id: sortseq.h,v 1.8 2006-12-05 15:18:48 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: sortseq.h,v 1.9 2007-01-19 10:32:39 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@@ -48,10 +48,12 @@ class DocSeqSorted : public DocSequence {
|
||||
virtual ~DocSeqSorted() {}
|
||||
virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0);
|
||||
virtual int getResCnt() {return m_spec.sortwidth;}
|
||||
virtual string getAbstract(Rcl::Doc& doc);
|
||||
|
||||
private:
|
||||
DocSeqSortSpec m_spec;
|
||||
std::vector<Rcl::Doc> m_docs;
|
||||
RefCntr<DocSequence> m_seq;
|
||||
DocSeqSortSpec m_spec;
|
||||
std::vector<Rcl::Doc> m_docs;
|
||||
std::vector<Rcl::Doc *> m_docsp;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user