Switch to unified view

a/src/query/docseq.cpp b/src/query/docseq.cpp
1
#ifndef lint
1
#ifndef lint
2
static char rcsid[] = "@(#$Id: docseq.cpp,v 1.9 2006-09-13 14:57:56 dockes Exp $ (C) 2005 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: docseq.cpp,v 1.10 2007-01-19 10:32:39 dockes Exp $ (C) 2005 J.F.Dockes";
3
#endif
3
#endif
4
/*
4
/*
5
 *   This program is free software; you can redistribute it and/or modify
5
 *   This program is free software; you can redistribute it and/or modify
6
 *   it under the terms of the GNU General Public License as published by
6
 *   it under the terms of the GNU General Public License as published by
7
 *   the Free Software Foundation; either version 2 of the License, or
7
 *   the Free Software Foundation; either version 2 of the License, or
...
...
20
#include <math.h>
20
#include <math.h>
21
#include <time.h>
21
#include <time.h>
22
22
23
#include "docseq.h"
23
#include "docseq.h"
24
24
25
bool DocSequenceDb::getDoc(int num, Rcl::Doc &doc, int *percent, string *sh)
25
int DocSequence::getSeqSlice(int offs, int cnt, vector<ResListEntry>& result)
26
{
26
{
27
    if (sh) sh->erase();
27
    int ret = 0;
28
    return m_db ? m_db->getDoc(num, doc, percent) : false;
28
    for (int num = offs; num < offs + cnt; num++, ret++) {
29
  result.push_back(ResListEntry());
30
  if (!getDoc(num, result.back().doc, &result.back().percent, 
31
          &result.back().subHeader)) {
32
      result.pop_back();
33
      return ret;
34
  }
35
    }
36
    return ret;
29
}
37
}
30
38
31
int DocSequenceDb::getResCnt()
32
{
33
    if (!m_db)
34
  return -1;
35
    if (m_rescnt < 0) {
36
  m_rescnt= m_db->getResCnt();
37
    }
38
    return m_rescnt;
39
}
40
41
void DocSequenceDb::getTerms(list<string> &terms)
42
{
43
    if (!m_db)
44
  return;
45
    m_db->getQueryTerms(terms);
46
}
47
48
bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, int *percent, 
49
              string *sh) 
50
{
51
    // Retrieve history list
52
    if (!m_hist)
53
  return false;
54
    if (m_hlist.empty())
55
  m_hlist = m_hist->getDocHistory();
56
57
    if (num < 0 || num >= (int)m_hlist.size())
58
  return false;
59
    int skip;
60
    if (m_prevnum >= 0 && num >= m_prevnum) {
61
  skip = num - m_prevnum;
62
    } else {
63
  skip = num;
64
  m_it = m_hlist.begin();
65
  m_prevtime = -1;
66
    }
67
    m_prevnum = num;
68
    while (skip--) 
69
  m_it++;
70
    if (percent)
71
  *percent = 100;
72
    if (sh) {
73
  if (m_prevtime < 0 || abs(m_prevtime - m_it->unixtime) > 86400) {
74
      m_prevtime = m_it->unixtime;
75
      time_t t = (time_t)(m_it->unixtime);
76
      *sh = string(ctime(&t));
77
      // Get rid of the final \n in ctime
78
      sh->erase(sh->length()-1);
79
  } else
80
      sh->erase();
81
    }
82
    return m_db->getDoc(m_it->fn, m_it->ipath, doc, percent);
83
}
84
85
int DocSequenceHistory::getResCnt()
86
{ 
87
    if (m_hlist.empty())
88
  m_hlist = m_hist->getDocHistory();
89
    return m_hlist.size();
90
}
91