Switch to unified view

a/src/query/docseq.h b/src/query/docseq.h
...
...
14
 *   Free Software Foundation, Inc.,
14
 *   Free Software Foundation, Inc.,
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
 */
16
 */
17
#ifndef _DOCSEQ_H_INCLUDED_
17
#ifndef _DOCSEQ_H_INCLUDED_
18
#define _DOCSEQ_H_INCLUDED_
18
#define _DOCSEQ_H_INCLUDED_
19
/* @(#$Id: docseq.h,v 1.9 2006-09-13 14:57:56 dockes Exp $  (C) 2004 J.F.Dockes */
19
/* @(#$Id: docseq.h,v 1.10 2007-01-19 10:32:39 dockes Exp $  (C) 2004 J.F.Dockes */
20
#include <string>
20
#include <string>
21
#include <list>
21
#include <list>
22
22
#include <vector>
23
#ifndef NO_NAMESPACES
23
#ifndef NO_NAMESPACES
24
using std::string;
24
using std::string;
25
using std::list;
25
using std::list;
26
using std::vector;
26
#endif
27
#endif
27
28
28
#include "rcldb.h"
29
#include "rcldoc.h"
29
#include "history.h"
30
31
// A result list entry. 
32
struct ResListEntry {
33
    Rcl::Doc doc;
34
    int percent;
35
    string subHeader;
36
    ResListEntry() : percent(0) {}
37
};
30
38
31
/** Interface for a list of documents coming from some source.
39
/** Interface for a list of documents coming from some source.
32
40
33
    The result list display data may come from different sources (ie:
41
    The result list display data may come from different sources (ie:
34
    history or Db query). We have an interface to make things cleaner.
42
    history or Db query), and be post-processed (DocSeqSorted).
35
*/
43
*/
36
class DocSequence {
44
class DocSequence {
37
 public:
45
 public:
38
    DocSequence(const string &t) : m_title(t) {}
46
    DocSequence(const string &t) : m_title(t) {}
39
    virtual ~DocSequence() {}
47
    virtual ~DocSequence() {}
48
40
    /** Get document at given rank 
49
    /** Get document at given rank. 
41
     *
50
     *
42
     * @param num document rank in sequence
51
     * @param num document rank in sequence
43
     * @param doc return data
52
     * @param doc return data
44
     * @param percent this will be updated with the percentage of relevance, if
53
     * @param percent this will be updated with the percentage of relevance, if
45
     *        available, depending on the type of sequence. Return -1 in there 
54
     *        available, depending on the type of sequence. Return -1 in there 
...
...
50
     *           inside history)
59
     *           inside history)
51
     * @return true if ok, false for error or end of data
60
     * @return true if ok, false for error or end of data
52
     */
61
     */
53
    virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0) 
62
    virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0) 
54
    = 0;
63
    = 0;
64
65
    /** Get next page of documents. This accumulates entries into the result
66
     *  list (doesn't reset it). */
67
    virtual int getSeqSlice(int offs, int cnt, vector<ResListEntry>& result);
68
69
    /** Get abstract for document. This is special because it may take time.
70
     *  The default is to return the input doc's abstract fields, but some 
71
     *  sequences can compute a better value (ie: docseqdb) */
72
    virtual string getAbstract(Rcl::Doc& doc) {
73
  return doc.abstract;
74
    }
75
76
    /** Get estimated total count in results */
55
    virtual int getResCnt() = 0;
77
    virtual int getResCnt() = 0;
78
79
    /** Get title for result list */
56
    virtual string title() {return m_title;}
80
    virtual string title() {return m_title;}
81
82
    /** Get search terms (for highlighting abstracts). Some sequences
83
     * may have no associated search terms. Implement this for them. */
57
    virtual void getTerms(list<string>& t) {t.clear();}
84
    virtual void getTerms(list<string>& t) {t.clear();}
58
85
59
 private:
86
 private:
60
    string m_title;
87
    string m_title;
61
};
88
};
62
89
63
64
/** A DocSequence from a Db query (there should be one active for this
65
    to make sense */
66
class DocSequenceDb : public DocSequence {
67
 public:
68
    DocSequenceDb(Rcl::Db *d, const string &t) : 
69
  DocSequence(t), m_db(d), m_rescnt(-1) 
70
  {}
71
    virtual ~DocSequenceDb() {}
72
    virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string * = 0);
73
    virtual int getResCnt();
74
    virtual void getTerms(list<string>&);
75
76
 private:
77
    Rcl::Db *m_db;
78
    int m_rescnt;
79
};
80
81
/** A DocSequence coming from the history file */
82
class DocSequenceHistory : public DocSequence {
83
 public:
84
    DocSequenceHistory(Rcl::Db *d, RclHistory *h, const string &t) 
85
  : DocSequence(t), m_db(d), m_hist(h), m_prevnum(-1), m_prevtime(-1) {}
86
    virtual ~DocSequenceHistory() {}
87
88
    virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0);
89
    virtual int getResCnt();
90
 private:
91
    Rcl::Db *m_db;
92
    RclHistory *m_hist;
93
    int m_prevnum;
94
    long m_prevtime;
95
96
    list<RclDHistoryEntry> m_hlist;
97
    list<RclDHistoryEntry>::const_iterator m_it;
98
};
99
100
#endif /* _DOCSEQ_H_INCLUDED_ */
90
#endif /* _DOCSEQ_H_INCLUDED_ */