rearranged some reslist/rclmain functions + add but not use filtseq code
This commit is contained in:
+3
-2
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
#ifndef _DOCSEQ_H_INCLUDED_
|
||||
#define _DOCSEQ_H_INCLUDED_
|
||||
/* @(#$Id: docseq.h,v 1.14 2008-09-08 16:49:10 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: docseq.h,v 1.15 2008-09-28 07:40:56 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
@@ -86,7 +86,8 @@ class DocSequence {
|
||||
* may have no associated search terms. Implement this for them. */
|
||||
virtual bool getTerms(vector<string>& terms,
|
||||
vector<vector<string> >& groups,
|
||||
vector<int>& gslks) const {
|
||||
vector<int>& gslks)
|
||||
{
|
||||
terms.clear(); groups.clear(); gslks.clear(); return true;
|
||||
}
|
||||
virtual list<string> expand(Rcl::Doc &) {list<string> e; return e;}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: docseqdb.cpp,v 1.5 2008-09-08 16:49:10 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: docseqdb.cpp,v 1.6 2008-09-28 07:40:56 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -35,9 +35,9 @@ DocSequenceDb::~DocSequenceDb()
|
||||
|
||||
bool DocSequenceDb::getTerms(vector<string>& terms,
|
||||
vector<vector<string> >& groups,
|
||||
vector<int>& gslks) const
|
||||
vector<int>& gslks)
|
||||
{
|
||||
return m_sdata.getptr()->getTerms(terms, groups, gslks);
|
||||
return m_sdata->getTerms(terms, groups, gslks);
|
||||
}
|
||||
|
||||
string DocSequenceDb::getDescription()
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
#ifndef _DOCSEQDB_H_INCLUDED_
|
||||
#define _DOCSEQDB_H_INCLUDED_
|
||||
/* @(#$Id: docseqdb.h,v 1.3 2008-06-13 18:22:46 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: docseqdb.h,v 1.4 2008-09-28 07:40:56 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
#include "docseq.h"
|
||||
#include "refcntr.h"
|
||||
|
||||
@@ -34,7 +34,7 @@ class DocSequenceDb : public DocSequence {
|
||||
virtual int getResCnt();
|
||||
virtual bool getTerms(vector<string>& terms,
|
||||
vector<vector<string> >& groups,
|
||||
vector<int>& gslks) const;
|
||||
vector<int>& gslks);
|
||||
virtual string getAbstract(Rcl::Doc &doc);
|
||||
virtual string getDescription();
|
||||
virtual list<string> expand(Rcl::Doc &doc);
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: filtseq.cpp,v 1.1 2008-09-28 07:40:56 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 <algorithm>
|
||||
|
||||
#include "debuglog.h"
|
||||
#include "filtseq.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
static bool filter(const DocSeqFiltSpec& fs, const Rcl::Doc *x)
|
||||
{
|
||||
// Compare using each criterion in term. We're doing an or:
|
||||
// 1st ok ends
|
||||
for (unsigned int i = 0; i < fs.crits.size(); i++) {
|
||||
switch (fs.crits[i]) {
|
||||
case DocSeqFiltSpec::DSFS_MIMETYPE:
|
||||
LOGDEB1((" MIMETYPE\n"));
|
||||
if (x->mimetype == fs.values[i])
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
// Did all comparisons
|
||||
return 0;
|
||||
}
|
||||
|
||||
DocSeqFiltered::DocSeqFiltered(RefCntr<DocSequence> iseq,
|
||||
DocSeqFiltSpec &filtspec,
|
||||
const std::string &t)
|
||||
: DocSequence(t), m_seq(iseq), m_spec(filtspec)
|
||||
{
|
||||
}
|
||||
|
||||
bool DocSeqFiltered::getDoc(int idx, Rcl::Doc &doc, int *percent, string *)
|
||||
{
|
||||
LOGDEB1(("DocSeqFiltered: fetching %d\n", idx));
|
||||
|
||||
if (idx >= (int)m_dbindices.size()) {
|
||||
// Have to fetch xapian docs and filter until we get enough or
|
||||
// fail
|
||||
m_dbindices.reserve(idx+1);
|
||||
|
||||
// First backend seq doc we fetch is the one after last stored
|
||||
int backend_idx = m_dbindices.size() > 0 ? m_dbindices.back() + 1 : 0;
|
||||
|
||||
// Loop until we get enough docs
|
||||
Rcl::Doc tdoc;
|
||||
int pc;
|
||||
int i = 0;
|
||||
while (idx >= (int)m_dbindices.size()) {
|
||||
if (!m_seq->getDoc(backend_idx, tdoc, &pc))
|
||||
return false;
|
||||
if (filter(m_spec, &tdoc)) {
|
||||
m_dbindices.push_back(backend_idx);
|
||||
}
|
||||
backend_idx++;
|
||||
}
|
||||
|
||||
if (percent)
|
||||
*percent = pc;
|
||||
doc = tdoc;
|
||||
} else {
|
||||
// The corresponding backend indice is already known
|
||||
if (!m_seq->getDoc(m_dbindices[idx], doc, percent))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 _FILTSEQ_H_INCLUDED_
|
||||
#define _FILTSEQ_H_INCLUDED_
|
||||
/* @(#$Id: filtseq.h,v 1.1 2008-09-28 07:40:56 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "refcntr.h"
|
||||
#include "docseq.h"
|
||||
|
||||
class DocSeqFiltSpec {
|
||||
public:
|
||||
DocSeqFiltSpec() {}
|
||||
enum Crit {DSFS_MIMETYPE};
|
||||
void orCrit(Crit crit, const string& value) {
|
||||
crits.push_back(crit);
|
||||
values.push_back(value);
|
||||
}
|
||||
std::vector<Crit> crits;
|
||||
std::vector<string> values;
|
||||
};
|
||||
|
||||
/**
|
||||
* A filtered sequence is created from another one by selecting entries
|
||||
* according to the given criteria.
|
||||
*/
|
||||
class DocSeqFiltered : public DocSequence {
|
||||
public:
|
||||
DocSeqFiltered(RefCntr<DocSequence> iseq, DocSeqFiltSpec &filtspec,
|
||||
const std::string &t);
|
||||
virtual ~DocSeqFiltered() {}
|
||||
virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0);
|
||||
virtual int getResCnt() {return m_seq->getResCnt();}
|
||||
virtual string getAbstract(Rcl::Doc& doc) {
|
||||
return m_seq->getAbstract(doc);
|
||||
}
|
||||
virtual string getDescription() {return m_seq->getDescription();}
|
||||
|
||||
private:
|
||||
RefCntr<DocSequence> m_seq;
|
||||
DocSeqFiltSpec m_spec;
|
||||
vector<int> m_dbindices;
|
||||
};
|
||||
|
||||
#endif /* _FILTSEQ_H_INCLUDED_ */
|
||||
Reference in New Issue
Block a user