doc.pc now only place where relevancy is stored

This commit is contained in:
dockes 2008-09-29 08:59:20 +00:00
parent 0bab0ea553
commit 828dff3bb1
18 changed files with 55 additions and 81 deletions

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: kio_recoll.cpp,v 1.8 2008-06-13 18:22:46 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: kio_recoll.cpp,v 1.9 2008-09-29 08:59:20 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
#include <stdio.h>
@ -139,8 +139,7 @@ void RecollProtocol::get(const KURL & url)
string sh;
doc.erase();
int percent;
if (!m_docsource->getDoc(i, doc, &percent, &sh)) {
if (!m_docsource->getDoc(i, doc, &sh)) {
// This may very well happen for history if the doc has
// been removed since. So don't treat it as fatal.
doc.meta["abstract"] = string("Unavailable document");
@ -158,7 +157,7 @@ void RecollProtocol::get(const KURL & url)
result = "<p>";
char perbuf[10];
sprintf(perbuf, "%3d%%", percent);
sprintf(perbuf, "%3d%%", doc.pc);
if (doc.meta["title"].empty())
doc.meta["title"] = path_getsimple(doc.url);
char datebuf[100];

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: pyrecoll.cpp,v 1.14 2008-09-29 06:58:25 dockes Exp $ (C) 2007 J.F.Dockes";
static char rcsid[] = "@(#$Id: pyrecoll.cpp,v 1.15 2008-09-29 08:59:20 dockes Exp $ (C) 2007 J.F.Dockes";
#endif
@ -618,7 +618,7 @@ Query_execute(recoll_QueryObject* self, PyObject *args, PyObject *kwargs)
return 0;
}
RefCntr<Rcl::SearchData> rq(sd);
rq->setSortBy(self->sortfield, self->ascending);
self->query->setSortBy(self->sortfield, self->ascending);
self->query->setQuery(rq, dostem?Rcl::Query::QO_STEM:Rcl::Query::QO_NONE);
int cnt = self->query->getResCnt();
self->next = 0;
@ -647,7 +647,7 @@ Query_executesd(recoll_QueryObject* self, PyObject *args, PyObject *kwargs)
PyErr_SetString(PyExc_AttributeError, "query");
return 0;
}
pysd->sd->setSortBy(self->sortfield, self->ascending);
self->query->setSortBy(self->sortfield, self->ascending);
self->query->setQuery(pysd->sd, dostem ? Rcl::Query::QO_STEM :
Rcl::Query::QO_NONE);
int cnt = self->query->getResCnt();
@ -681,8 +681,7 @@ Query_fetchone(recoll_QueryObject* self, PyObject *, PyObject *)
LOGERR(("Query_fetchone: couldn't create doc object for result\n"));
return 0;
}
int percent;
if (!self->query->getDoc(self->next, *result->doc, &percent)) {
if (!self->query->getDoc(self->next, *result->doc)) {
PyErr_SetString(PyExc_EnvironmentError, "query: cant fetch result");
self->next = -1;
return 0;
@ -702,7 +701,7 @@ Query_fetchone(recoll_QueryObject* self, PyObject *, PyObject *)
doc->meta[Rcl::Doc::keyfs] = doc->fbytes;
doc->meta[Rcl::Doc::keyds] = doc->dbytes;
char pc[20];
sprintf(pc, "%02d %%", percent);
sprintf(pc, "%02d %%", doc->pc);
doc->meta[Rcl::Doc::keyrr] = pc;
return (PyObject *)result;

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: reslist.cpp,v 1.45 2008-09-28 14:20:50 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: reslist.cpp,v 1.46 2008-09-29 08:59:20 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
#include <time.h>
@ -474,15 +474,19 @@ void ResList::resultPageNext()
// setUpdatesEnabled(false);
for (int i = 0; i < pagelen; i++) {
int &percent(respage[i].percent);
Rcl::Doc &doc(respage[i].doc);
string& sh(respage[i].subHeader);
if (percent == -1) {
int percent;
if (doc.pc == -1) {
percent = 0;
// Document not available, maybe other further, will go on.
doc.meta[Rcl::Doc::keyabs] = string(tr("Unavailable document").utf8());
} else {
percent = doc.pc;
}
// Percentage of 'relevance'
char perbuf[10];
sprintf(perbuf, "%3d%% ", percent);
// Determine icon to display if any
string img_name;
@ -496,10 +500,6 @@ void ResList::resultPageNext()
setImage(img_name.c_str(), image);
}
// Percentage of 'relevance'
char perbuf[10];
sprintf(perbuf, "%3d%% ", percent);
// Printable url: either utf-8 if transcoding succeeds, or url-encoded
string url;
printableUrl(rclconfig->getDefCharset(), doc.url, url);

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: docseq.cpp,v 1.10 2007-01-19 10:32:39 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: docseq.cpp,v 1.11 2008-09-29 08:59:20 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -27,8 +27,7 @@ int DocSequence::getSeqSlice(int offs, int cnt, vector<ResListEntry>& result)
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)) {
if (!getDoc(num, result.back().doc, &result.back().subHeader)) {
result.pop_back();
return ret;
}

View File

@ -16,7 +16,7 @@
*/
#ifndef _DOCSEQ_H_INCLUDED_
#define _DOCSEQ_H_INCLUDED_
/* @(#$Id: docseq.h,v 1.15 2008-09-28 07:40:56 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: docseq.h,v 1.16 2008-09-29 08:59:20 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
#include <list>
#include <vector>
@ -31,9 +31,7 @@ using std::vector;
// 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.
@ -50,17 +48,11 @@ class DocSequence {
*
* @param num document rank in sequence
* @param doc return data
* @param percent this will be updated with the percentage of relevance, if
* available, depending on the type of sequence. Return -1 in there
* to indicate that the specified document data is
* unavailable but that there may be available data further
* in the sequence
* @param sh subheader to display before this result (ie: date change
* inside history)
* @return true if ok, false for error or end of data
*/
virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0)
= 0;
virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0) = 0;
/** Get next page of documents. This accumulates entries into the result
* list (doesn't reset it). */

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: docseqdb.cpp,v 1.6 2008-09-28 07:40:56 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: docseqdb.cpp,v 1.7 2008-09-29 08:59:20 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -45,10 +45,10 @@ string DocSequenceDb::getDescription()
return m_sdata->getDescription();
}
bool DocSequenceDb::getDoc(int num, Rcl::Doc &doc, int *percent, string *sh)
bool DocSequenceDb::getDoc(int num, Rcl::Doc &doc, string *sh)
{
if (sh) sh->erase();
return m_q->getDoc(num, doc, percent);
return m_q->getDoc(num, doc);
}
int DocSequenceDb::getResCnt()

View File

@ -16,7 +16,7 @@
*/
#ifndef _DOCSEQDB_H_INCLUDED_
#define _DOCSEQDB_H_INCLUDED_
/* @(#$Id: docseqdb.h,v 1.4 2008-09-28 07:40:56 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: docseqdb.h,v 1.5 2008-09-29 08:59:20 dockes Exp $ (C) 2004 J.F.Dockes */
#include "docseq.h"
#include "refcntr.h"
@ -30,7 +30,7 @@ class DocSequenceDb : public DocSequence {
DocSequenceDb(RefCntr<Rcl::Query> q, const string &t,
RefCntr<Rcl::SearchData> sdata);
virtual ~DocSequenceDb();
virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string * = 0);
virtual bool getDoc(int num, Rcl::Doc &doc, string * = 0);
virtual int getResCnt();
virtual bool getTerms(vector<string>& terms,
vector<vector<string> >& groups,

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: docseqhist.cpp,v 1.3 2008-07-28 12:24:15 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: docseqhist.cpp,v 1.4 2008-09-29 08:59:20 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -25,8 +25,7 @@ static char rcsid[] = "@(#$Id: docseqhist.cpp,v 1.3 2008-07-28 12:24:15 dockes E
#include "rcldb.h"
#include "fileudi.h"
bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, int *percent,
string *sh)
bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, string *sh)
{
// Retrieve history list
if (!m_hist)
@ -47,8 +46,6 @@ bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, int *percent,
m_prevnum = num;
while (skip--)
m_it++;
if (percent)
*percent = 100;
if (sh) {
if (m_prevtime < 0 || abs (float(m_prevtime) - float(m_it->unixtime)) > 86400) {
m_prevtime = m_it->unixtime;
@ -61,7 +58,7 @@ bool DocSequenceHistory::getDoc(int num, Rcl::Doc &doc, int *percent,
}
string udi;
make_udi(m_it->fn, m_it->ipath, udi);
bool ret = m_db->getDoc(udi, doc, percent);
bool ret = m_db->getDoc(udi, doc);
if (!ret) {
doc.url = string("file://") + m_it->fn;
doc.ipath = m_it->ipath;

View File

@ -16,7 +16,7 @@
*/
#ifndef _DOCSEQHIST_H_INCLUDED_
#define _DOCSEQHIST_H_INCLUDED_
/* @(#$Id: docseqhist.h,v 1.2 2007-01-19 15:22:50 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: docseqhist.h,v 1.3 2008-09-29 08:59:20 dockes Exp $ (C) 2004 J.F.Dockes */
#include "docseq.h"
#include "history.h"
@ -34,7 +34,7 @@ class DocSequenceHistory : public DocSequence {
: 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 bool getDoc(int num, Rcl::Doc &doc, string *sh = 0);
virtual int getResCnt();
virtual string getDescription() {return m_description;}
void setDescription(const string& desc) {m_description = desc;}

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: filtseq.cpp,v 1.1 2008-09-28 07:40:56 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: filtseq.cpp,v 1.2 2008-09-29 08:59:20 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -47,7 +47,7 @@ DocSeqFiltered::DocSeqFiltered(RefCntr<DocSequence> iseq,
{
}
bool DocSeqFiltered::getDoc(int idx, Rcl::Doc &doc, int *percent, string *)
bool DocSeqFiltered::getDoc(int idx, Rcl::Doc &doc, string *)
{
LOGDEB1(("DocSeqFiltered: fetching %d\n", idx));
@ -61,23 +61,19 @@ bool DocSeqFiltered::getDoc(int idx, Rcl::Doc &doc, int *percent, string *)
// 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))
if (!m_seq->getDoc(backend_idx, tdoc))
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))
if (!m_seq->getDoc(m_dbindices[idx], doc))
return false;
}
return true;

View File

@ -16,7 +16,7 @@
*/
#ifndef _FILTSEQ_H_INCLUDED_
#define _FILTSEQ_H_INCLUDED_
/* @(#$Id: filtseq.h,v 1.2 2008-09-28 14:20:50 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: filtseq.h,v 1.3 2008-09-29 08:59:20 dockes Exp $ (C) 2004 J.F.Dockes */
#include <vector>
#include <string>
@ -47,7 +47,7 @@ class DocSeqFiltered : public DocSequence {
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 bool getDoc(int num, Rcl::Doc &doc, string *sh = 0);
virtual int getResCnt() {return m_seq->getResCnt();}
virtual string getAbstract(Rcl::Doc& doc) {
return m_seq->getAbstract(doc);

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: recollq.cpp,v 1.17 2008-09-29 06:58:25 dockes Exp $ (C) 2006 J.F.Dockes";
static char rcsid[] = "@(#$Id: recollq.cpp,v 1.18 2008-09-29 08:59:20 dockes Exp $ (C) 2006 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -239,16 +239,15 @@ int recollq(RclConfig **cfp, int argc, char **argv)
string tmpdir;
for (int i = 0; i < limit; i++) {
int pc;
Rcl::Doc doc;
if (!query.getDoc(i, doc, &pc))
if (!query.getDoc(i, doc))
break;
if (op_flags & OPT_b) {
cout << doc.url.c_str() << endl;
} else {
char cpc[20];
sprintf(cpc, "%d", pc);
sprintf(cpc, "%d", doc.pc);
cout
<< doc.mimetype.c_str() << "\t"
<< "[" << doc.url.c_str() << "]" << "\t"

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: sortseq.cpp,v 1.12 2008-09-28 14:20:50 dockes Exp $ (C) 2005 J.F.Dockes";
static char rcsid[] = "@(#$Id: sortseq.cpp,v 1.13 2008-09-29 08:59:20 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -91,12 +91,10 @@ DocSeqSorted::DocSeqSorted(RefCntr<DocSequence> iseq, DocSeqSortSpec &sortspec,
m_docs.resize(m_spec.sortdepth);
int i;
for (i = 0; i < m_spec.sortdepth; i++) {
int percent;
if (!iseq->getDoc(i, m_docs[i], &percent)) {
if (!iseq->getDoc(i, m_docs[i])) {
LOGERR(("DocSeqSorted: getDoc failed for doc %d\n", i));
break;
}
m_docs[i].pc = percent;
}
m_spec.sortdepth = i;
LOGDEB(("DocSeqSorted:: m_count %d\n", m_spec.sortdepth));
@ -109,14 +107,12 @@ DocSeqSorted::DocSeqSorted(RefCntr<DocSequence> iseq, DocSeqSortSpec &sortspec,
sort(m_docsp.begin(), m_docsp.end(), cmp);
}
bool DocSeqSorted::getDoc(int num, Rcl::Doc &doc, int *percent, string *)
bool DocSeqSorted::getDoc(int num, Rcl::Doc &doc, string *)
{
LOGDEB1(("DocSeqSorted: fetching %d\n", num));
if (num >= m_spec.sortdepth)
return false;
if (percent)
*percent = (*m_docsp[num]).pc;
doc = *m_docsp[num];
return true;
}

View File

@ -16,7 +16,7 @@
*/
#ifndef _SORTSEQ_H_INCLUDED_
#define _SORTSEQ_H_INCLUDED_
/* @(#$Id: sortseq.h,v 1.11 2008-09-28 14:20:50 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: sortseq.h,v 1.12 2008-09-29 08:59:20 dockes Exp $ (C) 2004 J.F.Dockes */
#include <vector>
#include <string>
@ -48,7 +48,7 @@ class DocSeqSorted : public DocSequence {
DocSeqSorted(RefCntr<DocSequence> iseq, DocSeqSortSpec &sortspec,
const std::string &t);
virtual ~DocSeqSorted() {}
virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0);
virtual bool getDoc(int num, Rcl::Doc &doc, string *sh = 0);
virtual int getResCnt() {return m_spec.sortdepth;}
virtual string getAbstract(Rcl::Doc& doc) {
return m_seq->getAbstract(doc);

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.145 2008-09-16 08:18:30 dockes Exp $ (C) 2004 J.F.Dockes";
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.146 2008-09-29 08:59:20 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
/*
* This program is free software; you can redistribute it and/or modify
@ -159,6 +159,7 @@ bool Db::Native::dbDataToRclDoc(Xapian::docid docid, std::string &data,
}
char buf[20];
sprintf(buf,"%.2f", float(percent) / 100.0);
doc.pc = percent;
doc.meta[Doc::keyrr] = buf;
parms.get(Doc::keyipt, doc.ipath);
parms.get(Doc::keyfs, doc.fbytes);
@ -1554,7 +1555,7 @@ bool Db::makeDocAbstract(Doc &doc, Query *query, string& abstract)
}
// Retrieve document defined by file name and internal path.
bool Db::getDoc(const string &udi, Doc &doc, int *pc)
bool Db::getDoc(const string &udi, Doc &doc)
{
LOGDEB(("Db:getDoc: [%s]\n", udi.c_str()));
if (m_ndb == 0)
@ -1562,8 +1563,7 @@ bool Db::getDoc(const string &udi, Doc &doc, int *pc)
// Initialize what we can in any case. If this is history, caller
// will make partial display in case of error
if (*pc)
*pc = 100;
doc.pc = 100;
string uniterm = make_uniterm(udi);
string ermsg;
@ -1572,8 +1572,7 @@ bool Db::getDoc(const string &udi, Doc &doc, int *pc)
// Document found in history no longer in the database.
// We return true (because their might be other ok docs further)
// but indicate the error with pc = -1
if (*pc)
*pc = -1;
doc.pc = -1;
LOGINFO(("Db:getDoc: no such doc in index: [%s] (len %d)\n",
uniterm.c_str(), uniterm.length()));
return true;

View File

@ -16,7 +16,7 @@
*/
#ifndef _DB_H_INCLUDED_
#define _DB_H_INCLUDED_
/* @(#$Id: rcldb.h,v 1.62 2008-09-16 08:18:30 dockes Exp $ (C) 2004 J.F.Dockes */
/* @(#$Id: rcldb.h,v 1.63 2008-09-29 08:59:20 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
#include <list>
@ -174,7 +174,7 @@ class Db {
*
* Used by the 'history' feature (and nothing else?)
*/
bool getDoc(const string &udi, Doc &doc, int *percent);
bool getDoc(const string &udi, Doc &doc);
/* The following are mainly for the aspell module */
/** Whole term list walking. */

View File

@ -1,5 +1,5 @@
#ifndef lint
static char rcsid[] = "@(#$Id: rclquery.cpp,v 1.7 2008-09-29 06:58:25 dockes Exp $ (C) 2008 J.F.Dockes";
static char rcsid[] = "@(#$Id: rclquery.cpp,v 1.8 2008-09-29 08:59:20 dockes Exp $ (C) 2008 J.F.Dockes";
#endif
#include <stdlib.h>
@ -278,7 +278,7 @@ int Query::getResCnt()
// maintain a correspondance from the sequential external index
// sequence to the internal Xapian hole-y one (the holes being the documents
// that dont match the filter).
bool Query::getDoc(int exti, Doc &doc, int *percent)
bool Query::getDoc(int exti, Doc &doc)
{
LOGDEB1(("Query::getDoc: exti %d\n", exti));
if (ISNULL(m_nq) || !m_nq->enquire) {
@ -364,8 +364,6 @@ bool Query::getDoc(int exti, Doc &doc, int *percent)
Xapian::Document xdoc = m_nq->mset[xapi-first].get_document();
Xapian::docid docid = *(m_nq->mset[xapi-first]);
int pc = m_nq->mset.convert_to_percent(m_nq->mset[xapi-first]);
if (percent)
*percent = pc;
// Parse xapian document's data and populate doc fields
string data = xdoc.get_data();

View File

@ -1,6 +1,6 @@
#ifndef _rclquery_h_included_
#define _rclquery_h_included_
/* @(#$Id: rclquery.h,v 1.4 2008-09-29 06:58:25 dockes Exp $ (C) 2008 J.F.Dockes */
/* @(#$Id: rclquery.h,v 1.5 2008-09-29 08:59:20 dockes Exp $ (C) 2008 J.F.Dockes */
/*
* 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
@ -70,7 +70,7 @@ class Query {
int getResCnt();
/** Get document at rank i in current query results. */
bool getDoc(int i, Doc &doc, int *percent = 0);
bool getDoc(int i, Doc &doc);
/** Get possibly expanded list of query terms */
bool getQueryTerms(list<string>& terms);