colorize search terms in abstracts
This commit is contained in:
parent
b536c9c46c
commit
347fa3f962
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: plaintorich.cpp,v 1.10 2006-02-07 09:44:33 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: plaintorich.cpp,v 1.11 2006-09-13 14:57:56 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -83,7 +83,7 @@ class myTextSplitCB : public TextSplitCB {
|
||||
// we return the first term encountered, and the caller will use the
|
||||
// editor's find() function to position on it
|
||||
bool plaintorich(const string& in, string& out, const list<string>& terms,
|
||||
string *firstTerm)
|
||||
string *firstTerm, bool noHeader)
|
||||
{
|
||||
Chrono chron;
|
||||
LOGDEB(("plaintorich: terms: %s\n",
|
||||
@ -104,7 +104,10 @@ bool plaintorich(const string& in, string& out, const list<string>& terms,
|
||||
LOGDEB(("plaintorich: split done %d mS\n", chron.millis()));
|
||||
|
||||
// Rich text output
|
||||
out = "<qt><head><title></title></head><body><p>";
|
||||
if (noHeader)
|
||||
out = "";
|
||||
else
|
||||
out = "<qt><head><title></title></head><body><p>";
|
||||
|
||||
// Iterator for the list of input term positions. We use it to
|
||||
// output highlight tags and to compute term positions in the
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
#ifndef _PLAINTORICH_H_INCLUDED_
|
||||
#define _PLAINTORICH_H_INCLUDED_
|
||||
/* @(#$Id: plaintorich.h,v 1.6 2006-02-07 09:44:33 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: plaintorich.h,v 1.7 2006-09-13 14:57:56 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -27,11 +27,13 @@
|
||||
* colorize the query terms.
|
||||
*
|
||||
* @param in raw text out of internfile.
|
||||
* @param terms list of query terms
|
||||
* @param termoffsets output: character offsets where we find terms.
|
||||
* @param out rich text output
|
||||
* @param terms list of query terms. These are out of Rcl::Db and dumb
|
||||
* @param firstTerm out: value of the first search term in text.
|
||||
* @param noHeader if true don't output header (<qt><title>...)
|
||||
*/
|
||||
extern bool plaintorich(const string &in, string &out,
|
||||
const list<string>& terms,
|
||||
string* firstTerm);
|
||||
string* firstTerm, bool noHeader = false);
|
||||
|
||||
#endif /* _PLAINTORICH_H_INCLUDED_ */
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: rclreslist.cpp,v 1.18 2006-09-12 10:11:36 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: rclreslist.cpp,v 1.19 2006-09-13 14:57:56 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
@ -22,6 +22,7 @@ static char rcsid[] = "@(#$Id: rclreslist.cpp,v 1.18 2006-09-12 10:11:36 dockes
|
||||
#include "transcode.h"
|
||||
#include "pathut.h"
|
||||
#include "mimehandler.h"
|
||||
#include "plaintorich.h"
|
||||
|
||||
#include "rclreslist.h"
|
||||
#include "moc_rclreslist.cpp"
|
||||
@ -253,6 +254,14 @@ void RclResList::resultPageNext()
|
||||
|
||||
m_curDocs.clear();
|
||||
|
||||
// Query term colorization
|
||||
QStyleSheetItem *item =
|
||||
new QStyleSheetItem(styleSheet(), "termtag" );
|
||||
item->setColor("blue");
|
||||
// item->setFontWeight(QFont::Bold);
|
||||
list<string> qTerms;
|
||||
m_docsource->getTerms(qTerms);
|
||||
|
||||
// Insert results if any in result list window. We have to send
|
||||
// the text to the widgets, because we need the paragraph number
|
||||
// each time we add a result paragraph (its diffult and
|
||||
@ -357,7 +366,9 @@ void RclResList::resultPageNext()
|
||||
}
|
||||
|
||||
// Abstract
|
||||
string abst = escapeHtml(doc.abstract);
|
||||
string abst;
|
||||
plaintorich(doc.abstract, abst, qTerms, 0, true);
|
||||
//string abst = escapeHtml(doc.abstract);
|
||||
LOGDEB1(("Abstract: {%s}\n", abst.c_str()));
|
||||
|
||||
// Concatenate chunks to build the result list paragraph:
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: docseq.cpp,v 1.8 2006-02-07 10:26:49 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: docseq.cpp,v 1.9 2006-09-13 14:57:56 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@ -38,6 +38,13 @@ int DocSequenceDb::getResCnt()
|
||||
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)
|
||||
{
|
||||
|
||||
@ -16,7 +16,14 @@
|
||||
*/
|
||||
#ifndef _DOCSEQ_H_INCLUDED_
|
||||
#define _DOCSEQ_H_INCLUDED_
|
||||
/* @(#$Id: docseq.h,v 1.8 2006-09-11 09:08:44 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: docseq.h,v 1.9 2006-09-13 14:57:56 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
#ifndef NO_NAMESPACES
|
||||
using std::string;
|
||||
using std::list;
|
||||
#endif
|
||||
|
||||
#include "rcldb.h"
|
||||
#include "history.h"
|
||||
@ -28,7 +35,7 @@
|
||||
*/
|
||||
class DocSequence {
|
||||
public:
|
||||
DocSequence(const std::string &t) : m_title(t) {}
|
||||
DocSequence(const string &t) : m_title(t) {}
|
||||
virtual ~DocSequence() {}
|
||||
/** Get document at given rank
|
||||
*
|
||||
@ -46,10 +53,11 @@ class DocSequence {
|
||||
virtual bool getDoc(int num, Rcl::Doc &doc, int *percent, string *sh = 0)
|
||||
= 0;
|
||||
virtual int getResCnt() = 0;
|
||||
virtual std::string title() {return m_title;}
|
||||
virtual string title() {return m_title;}
|
||||
virtual void getTerms(list<string>& t) {t.clear();}
|
||||
|
||||
private:
|
||||
std::string m_title;
|
||||
string m_title;
|
||||
};
|
||||
|
||||
|
||||
@ -57,12 +65,14 @@ class DocSequence {
|
||||
to make sense */
|
||||
class DocSequenceDb : public DocSequence {
|
||||
public:
|
||||
DocSequenceDb(Rcl::Db *d, const std::string &t) :
|
||||
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;
|
||||
@ -71,7 +81,7 @@ class DocSequenceDb : public DocSequence {
|
||||
/** A DocSequence coming from the history file */
|
||||
class DocSequenceHistory : public DocSequence {
|
||||
public:
|
||||
DocSequenceHistory(Rcl::Db *d, RclHistory *h, const std::string &t)
|
||||
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() {}
|
||||
|
||||
@ -83,8 +93,8 @@ class DocSequenceHistory : public DocSequence {
|
||||
int m_prevnum;
|
||||
long m_prevtime;
|
||||
|
||||
std::list<RclDHistoryEntry> m_hlist;
|
||||
std::list<RclDHistoryEntry>::const_iterator m_it;
|
||||
list<RclDHistoryEntry> m_hlist;
|
||||
list<RclDHistoryEntry>::const_iterator m_it;
|
||||
};
|
||||
|
||||
#endif /* _DOCSEQ_H_INCLUDED_ */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user